Skip to content

Commit

Permalink
Eclipse 4.23 (M2) JDT Patch for Groovy-Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jan 28, 2022
1 parent 89da3f1 commit 308008a
Show file tree
Hide file tree
Showing 34 changed files with 785 additions and 285 deletions.
2 changes: 1 addition & 1 deletion groovy-eclipse.setup
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
<repository
url="https://download.eclipse.org/eclipse/updates/4.23"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.23-I-builds/I20220105-1800"/>
url="https://download.eclipse.org/eclipse/updates/4.23-I-builds/I20220127-1800"/>
</repositoryList>
<repositoryList
name="2021-12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.tests.compiler;singleton:=true
Bundle-Version: 3.12.1750.qualifier
Bundle-Version: 3.12.1800.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests.compiler,
Expand Down
2 changes: 1 addition & 1 deletion jdt-patch/e423/org.eclipse.jdt.core.tests.compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.compiler</artifactId>
<version>3.12.1750-SNAPSHOT</version>
<version>3.12.1800-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@

import java.util.ArrayList;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.jdt.core.tests.compiler.util.HashtableOfObjectTest;
import org.eclipse.jdt.core.tests.dom.StandAloneASTParserTest;
import org.eclipse.jdt.core.tests.junit.extension.TestCase;
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo;

import junit.framework.Test;
import junit.framework.TestSuite;

/**
* Run all compiler regression tests
*/
Expand Down Expand Up @@ -223,6 +224,7 @@ public static Test suite() {
// Build final test suite
TestSuite all = new TestSuite(TestAll.class.getName());
all.addTest(new TestSuite(StandAloneASTParserTest.class));
all.addTest(new TestSuite(HashtableOfObjectTest.class));
int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
if ((possibleComplianceLevels & AbstractCompilerTest.F_1_3) != 0) {
ArrayList tests_1_3 = (ArrayList)standardTests.clone();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/*******************************************************************************
* Copyright (c) 2022 Andrey Loskujtov, and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrey Loskutov (loskutov@gmx.de) - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.util;

import static org.eclipse.jdt.internal.compiler.util.HashtableOfObject.MAX_ARRAY_SIZE;
import static org.eclipse.jdt.internal.compiler.util.HashtableOfObject.calculateNewSize;

import org.eclipse.jdt.core.tests.junit.extension.TestCase;
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;

public class HashtableOfObjectTest extends TestCase {

public HashtableOfObjectTest(String name) {
super(name);
}

public void testCalculateNewSize() {
int input;
int expected;

// Overflow
input = Integer.MAX_VALUE * 2;
try {
calculateNewSize(input);
fail("Should not accept " + input);
} catch (NegativeArraySizeException e) {
// expected
}
input = Integer.MAX_VALUE + 1;
try {
calculateNewSize(input);
fail("Should not accept " + input);
} catch (NegativeArraySizeException e) {
// expected
}
input = -1;
try {
calculateNewSize(input);
fail("Should not accept " + input);
} catch (NegativeArraySizeException e) {
// expected
}

// Regular size
assertEquals(1, calculateNewSize(0));
assertEquals(2, calculateNewSize(1));

input = (MAX_ARRAY_SIZE / 2) - 10000;
expected = input * 2;
assertEquals(expected, calculateNewSize(input));

input = (MAX_ARRAY_SIZE / 2) - 1;
expected = input * 2;
assertEquals(expected, calculateNewSize(input));

input = (MAX_ARRAY_SIZE / 2);
expected = input + (MAX_ARRAY_SIZE - input) / 2;
assertEquals(expected, calculateNewSize(input));

// Can't simply double the size
input = (MAX_ARRAY_SIZE / 2) + 1;
expected = input + (MAX_ARRAY_SIZE - input) / 2;
assertEquals(expected, calculateNewSize(input));

input = (MAX_ARRAY_SIZE / 2) + 10000;
expected = input + (MAX_ARRAY_SIZE - input) / 2;
assertEquals(expected, calculateNewSize(input));

// Last few possible sizes
input = MAX_ARRAY_SIZE - 4;
expected = input + (MAX_ARRAY_SIZE - input) / 2;
assertEquals(expected, calculateNewSize(input));

input = MAX_ARRAY_SIZE - 3;
expected = input + 1;
assertEquals(expected, calculateNewSize(input));

// No way to increase
try {
input = MAX_ARRAY_SIZE - 2;
calculateNewSize(input);
fail("Should not support table size " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = MAX_ARRAY_SIZE - 1;
calculateNewSize(input);
fail("Should not support table size " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = MAX_ARRAY_SIZE;
calculateNewSize(input);
fail("Should not support table size " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = Integer.MAX_VALUE - 1;
calculateNewSize(input);
fail("Should not support table size " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = Integer.MAX_VALUE;
calculateNewSize(input);
fail("Should not support table size " + input);
} catch (OutOfMemoryError e) {
// expected
}
}

public void testCreateNewTable() {
int input;
int expected;
// Overflow
input = Integer.MAX_VALUE + 1;
try {
new HashtableOfObject(input);
fail("Should not accept " + input);
} catch (NegativeArraySizeException e) {
// expected
}
input = Integer.MAX_VALUE * 2;
try {
new HashtableOfObject(input);
fail("Should not accept " + input);
} catch (NegativeArraySizeException e) {
// expected
}
input = Integer.MAX_VALUE * 2 + 1;
try {
new HashtableOfObject(input);
fail("Should not accept " + input);
} catch (NegativeArraySizeException e) {
// expected
}
input = -1;
try {
new HashtableOfObject(input);
fail("Should not accept " + input);
} catch (NegativeArraySizeException e) {
// expected
}

// Regular sizes
assertEquals(1, new HashtableOfObject(0).storageSize());
assertEquals(2, new HashtableOfObject(1).storageSize());
assertEquals(3, new HashtableOfObject(2).storageSize());

// No way to increase
try {
input = MAX_ARRAY_SIZE - 2;
new HashtableOfObject(input);
fail("Should support table size " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = MAX_ARRAY_SIZE - 1;
new HashtableOfObject(input);
fail("Should support table size " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = MAX_ARRAY_SIZE;
new HashtableOfObject(input);
fail("Should not accept " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = Integer.MAX_VALUE - 1;
new HashtableOfObject(input);
fail("Should not accept " + input);
} catch (OutOfMemoryError e) {
// expected
}
try {
input = Integer.MAX_VALUE;
new HashtableOfObject(input);
fail("Should not accept " + input);
} catch (OutOfMemoryError e) {
// expected
}

if(Runtime.getRuntime().maxMemory() / (1024 * 1024) < 31000) {
// requires lot of heap
return;
}

// Can't simply double the size
input = (int)(MAX_ARRAY_SIZE / 1.75);
expected = input + (MAX_ARRAY_SIZE - input) / 2;
assertEquals(expected, new HashtableOfObject(input).storageSize());

input = MAX_ARRAY_SIZE - 4;
expected = input + (MAX_ARRAY_SIZE - input) / 2;
assertEquals(expected, new HashtableOfObject(input).storageSize());

// Last possible size
input = MAX_ARRAY_SIZE - 3;
expected = input + 1;
assertEquals(expected, new HashtableOfObject(input).storageSize());

System.gc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4612,7 +4612,8 @@ else if (scope instanceof ClassScope)
}
}

if(this.expectedTypesPtr + 1 != this.expectedTypes.length) {
// Guard it, otherwise we end up with a empty array which cause issues down the line
if((this.expectedTypesPtr > -1) && ((this.expectedTypesPtr + 1) != this.expectedTypes.length)) {
System.arraycopy(this.expectedTypes, 0, this.expectedTypes = new TypeBinding[this.expectedTypesPtr + 1], 0, this.expectedTypesPtr + 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2775,8 +2775,10 @@ protected void consumeDimWithOrWithOutExpr() {
}
@Override
protected void consumeEmptyStatement() {
ASTNode nodeToAttach = (this.assistNodeParent instanceof MessageSend) || (this.assistNodeParent instanceof ParameterizedSingleTypeReference)
? this.assistNodeParent : this.assistNode;
boolean shouldAttachParent = (this.assistNodeParent instanceof MessageSend) ||
(this.assistNodeParent instanceof ParameterizedSingleTypeReference) ||
(this.assistNodeParent instanceof LocalDeclaration);
ASTNode nodeToAttach = shouldAttachParent ? this.assistNodeParent : this.assistNode;
if (this.shouldStackAssistNode && nodeToAttach != null) {
for (int ptr = this.astPtr; ptr >= 0; ptr--) {
if (new CompletionNodeDetector(nodeToAttach, this.astStack[ptr]).containsCompletionNode()) {
Expand Down Expand Up @@ -5799,9 +5801,10 @@ public void parseBlockStatements(AbstractMethodDeclaration md, CompilationUnitDe
}
}
super.parseBlockStatements(md, unit);
// if the assist node is parsed at the cursor location, then ignore syntax errors found due to chars such as . and (
// if the assist node is parsed at the cursor location or the cursor is within the assist node,
// then ignore syntax errors found due to chars such as . and (
if((md.bits & ASTNode.HasSyntaxErrors) != 0 && this.lastAct == ERROR_ACTION
&& this.assistNode != null && this.assistNode.sourceEnd == this.cursorLocation) {
&& this.assistNode != null && this.assistNode.sourceEnd >= this.cursorLocation) {
md.bits &= ~ASTNode.HasSyntaxErrors;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public class TypeDeclaration extends Statement implements ProblemSeverities, Ref
public FieldBinding enumValuesSyntheticfield; // for enum
public int enumConstantsCounter;

// 1.5 support
// Generics support
public TypeParameter[] typeParameters;

// Records support
// Record Type support
public int nRecordComponents;
public RecordComponent[] recordComponents;
public static Set<String> disallowedComponentNames;
Expand Down
Loading

0 comments on commit 308008a

Please sign in to comment.