Skip to content

Commit f3616f0

Browse files
committed
AIC: bypass checkTypeArgumentRedundancy instead of setting IsDiamond
for #1358 #1419
1 parent d53cebd commit f3616f0

File tree

2 files changed

+42
-55
lines changed

2 files changed

+42
-55
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GenericsTests.java

+21-33
Original file line numberDiff line numberDiff line change
@@ -2170,17 +2170,13 @@ public void testAbstractCovariance5() {
21702170
};
21712171
//@formatter:on
21722172

2173-
if (isAtLeastJava(JDK9)) {
2174-
runWarningFreeTest(sources);
2175-
} else {
2176-
runNegativeTest(sources,
2177-
"----------\n" +
2178-
"1. WARNING in Impl.groovy (at line 3)\n" +
2179-
"\tCharSequence process(CharSequence chars) { chars }\n" +
2180-
"\t^^^^^^^^^^^^\n" +
2181-
"Type safety: The return type CharSequence for process(CharSequence) from the type new Face<CharSequence>(){} needs unchecked conversion to conform to IO from the type Face<T>\n" +
2182-
"----------\n");
2183-
}
2173+
runNegativeTest(sources,
2174+
"----------\n" +
2175+
"1. WARNING in Impl.groovy (at line 3)\n" +
2176+
"\tCharSequence process(CharSequence chars) { chars }\n" +
2177+
"\t^^^^^^^^^^^^\n" +
2178+
"Type safety: The return type CharSequence for process(CharSequence) from the type new Face<CharSequence>(){} needs unchecked conversion to conform to IO from the type Face<T>\n" +
2179+
"----------\n");
21842180
}
21852181

21862182
@Test // https://issues.apache.org/jira/projects/GROOVY/issues/GROOVY-9059
@@ -2200,17 +2196,13 @@ public void testAbstractCovariance6() {
22002196
};
22012197
//@formatter:on
22022198

2203-
if (isAtLeastJava(JDK9)) {
2204-
runWarningFreeTest(sources);
2205-
} else {
2206-
runNegativeTest(sources,
2207-
"----------\n" +
2208-
"1. WARNING in Impl.groovy (at line 3)\n" +
2209-
"\tString process(String string) { string }\n" +
2210-
"\t^^^^^^\n" +
2211-
"Type safety: The return type String for process(String) from the type new Face<String>(){} needs unchecked conversion to conform to IO from the type Face<T>\n" +
2212-
"----------\n");
2213-
}
2199+
runNegativeTest(sources,
2200+
"----------\n" +
2201+
"1. WARNING in Impl.groovy (at line 3)\n" +
2202+
"\tString process(String string) { string }\n" +
2203+
"\t^^^^^^\n" +
2204+
"Type safety: The return type String for process(String) from the type new Face<String>(){} needs unchecked conversion to conform to IO from the type Face<T>\n" +
2205+
"----------\n");
22142206
}
22152207

22162208
@Test // https://issues.apache.org/jira/projects/GROOVY/issues/GROOVY-9059
@@ -2230,17 +2222,13 @@ public void testAbstractCovariance7() {
22302222
};
22312223
//@formatter:on
22322224

2233-
if (isAtLeastJava(JDK9)) {
2234-
runWarningFreeTest(sources);
2235-
} else {
2236-
runNegativeTest(sources,
2237-
"----------\n" +
2238-
"1. WARNING in Impl.groovy (at line 3)\n" +
2239-
"\tString process(String string) { string }\n" +
2240-
"\t^^^^^^\n" +
2241-
"Type safety: The return type String for process(String) from the type new Face<String>(){} needs unchecked conversion to conform to O from the type Face<T>\n" +
2242-
"----------\n");
2243-
}
2225+
runNegativeTest(sources,
2226+
"----------\n" +
2227+
"1. WARNING in Impl.groovy (at line 3)\n" +
2228+
"\tString process(String string) { string }\n" +
2229+
"\t^^^^^^\n" +
2230+
"Type safety: The return type String for process(String) from the type new Face<String>(){} needs unchecked conversion to conform to O from the type Face<T>\n" +
2231+
"----------\n");
22442232
}
22452233

22462234
@Test // https://issues.apache.org/jira/projects/GROOVY/issues/GROOVY-10675

base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java

+21-22
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,11 @@
162162
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
163163
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
164164
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
165+
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
165166
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
166167
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
167168
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
169+
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
168170
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
169171
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
170172
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
@@ -1205,16 +1207,18 @@ private void createTypeDeclarations(ModuleNode moduleNode) {
12051207
typeDeclaration.name = CharOperation.NO_CHAR;
12061208
typeDeclaration.bits |= (ASTNode.IsAnonymousType | ASTNode.IsLocalType);
12071209
//typeDeclaration.bits |= (typeDeclaration.superclass.bits & ASTNode.HasTypeAnnotations);
1208-
QualifiedAllocationExpression allocation = new QualifiedAllocationExpression(typeDeclaration);
1210+
QualifiedAllocationExpression allocation = new QualifiedAllocationExpression(typeDeclaration) {
1211+
@Override
1212+
public void checkTypeArgumentRedundancy(ParameterizedTypeBinding atype, BlockScope scope) {
1213+
// https://github.com/groovy/groovy-eclipse/issues/1358
1214+
}
1215+
};
12091216
allocation.sourceStart = isEnum ? typeDeclaration.sourceStart : typeDeclaration.sourceStart - 4; // approx. offset of "new"
12101217
allocation.sourceEnd = typeDeclaration.bodyEnd;
12111218
if (!isEnum) {
12121219
allocation.type = typeDeclaration.superclass;
1213-
if (allocation.type.isParameterizedTypeReference() && unitDeclaration.compilerOptions.targetJDK >= ClassFileConstants.JDK9) {
1214-
allocation.type.bits |= ASTNode.IsDiamond; // https://github.com/groovy/groovy-eclipse/issues/1358
1215-
}
12161220
}
1217-
// TODO: allocation.typeArguments = something
1221+
// TODO (GROOVY-10501): allocation.typeArguments = something
12181222
} else {
12191223
typeDeclaration.name = innerClassNode.getNameWithoutPackage().substring(outerClassNode.getNameWithoutPackage().length() + 1).toCharArray();
12201224
}
@@ -1707,7 +1711,7 @@ private void configurePermittedSubtypes(TypeDeclaration typeDeclaration, ClassNo
17071711
if (e instanceof VariableExpression) {
17081712
char[] simpleName = e.getText().toCharArray(); // assume it's a type name
17091713
TypeReference t = verify(new SingleTypeReference(simpleName, toPos(e.getStart(), e.getEnd() - 1)));
1710-
t.bits |= ASTNode.IgnoreRawTypeCheck;
1714+
if (!checkGenerics) t.bits |= ASTNode.IgnoreRawTypeCheck;
17111715
return t;
17121716
}
17131717
if (e instanceof PropertyExpression) {
@@ -1717,7 +1721,7 @@ private void configurePermittedSubtypes(TypeDeclaration typeDeclaration, ClassNo
17171721
}
17181722
char[][] compoundName = CharOperation.splitOn('.', e.getText().toCharArray()); // assume it's a type name
17191723
TypeReference t = new QualifiedTypeReference(compoundName, positionsFor(compoundName, e.getStart(), e.getEnd()));
1720-
t.bits |= ASTNode.IgnoreRawTypeCheck;
1724+
if (!checkGenerics) t.bits |= ASTNode.IgnoreRawTypeCheck;
17211725
return t;
17221726
}
17231727
Util.log(IStatus.WARNING, "Unhandled reference type: " + e.getClass().getName());
@@ -2307,27 +2311,23 @@ private TypeReference createTypeReferenceForClassNode(ClassNode classNode, int s
23072311

23082312
if (compoundName.length == 1) {
23092313
if (typeArguments == null) {
2310-
TypeReference tr = verify(new SingleTypeReference(typeName, toPos(sourceStart, sourceEnd - 1)));
2311-
if (!checkGenerics) {
2312-
tr.bits |= ASTNode.IgnoreRawTypeCheck;
2313-
}
2314-
return tr;
2314+
TypeReference t = verify(new SingleTypeReference(typeName, toPos(sourceStart, sourceEnd - 1)));
2315+
if (!checkGenerics) t.bits |= ASTNode.IgnoreRawTypeCheck;
2316+
return t;
23152317
} else {
23162318
TypeReference[] typeRefs = typeArguments.toArray(new TypeReference[typeArguments.size()]);
23172319
return new ParameterizedSingleTypeReference(typeName, typeRefs, 0, toPos(sourceStart, sourceEnd - 1));
23182320
}
23192321
} else {
23202322
if (typeArguments == null) {
2321-
TypeReference tr = new QualifiedTypeReference(compoundName, positionsFor(compoundName, sourceStart, sourceEnd));
2322-
if (!checkGenerics) {
2323-
tr.bits |= ASTNode.IgnoreRawTypeCheck;
2324-
}
2325-
return tr;
2323+
TypeReference t = new QualifiedTypeReference(compoundName, positionsFor(compoundName, sourceStart, sourceEnd));
2324+
if (!checkGenerics) t.bits |= ASTNode.IgnoreRawTypeCheck;
2325+
return t;
23262326
} else {
23272327
// TODO: Support individual component parameterization: A<X>.B<Y>
2328-
TypeReference[][] typeRefs = new TypeReference[compoundName.length][];
2329-
typeRefs[compoundName.length - 1] = typeArguments.toArray(new TypeReference[typeArguments.size()]);
2330-
return new ParameterizedQualifiedTypeReference(compoundName, typeRefs, 0, positionsFor(compoundName, sourceStart, sourceEnd));
2328+
TypeReference[][] types = new TypeReference[compoundName.length][];
2329+
types[compoundName.length - 1] = typeArguments.toArray(new TypeReference[typeArguments.size()]);
2330+
return new ParameterizedQualifiedTypeReference(compoundName, types, 0, positionsFor(compoundName, sourceStart, sourceEnd));
23312331
}
23322332
}
23332333
}
@@ -2360,8 +2360,7 @@ private TypeReference createTypeReferenceForGenerics(GenericsType genericsType)
23602360
}
23612361
// FIXASC what does the check on this next really line mean?
23622362
} else if (!genericsType.getType().isGenericsPlaceHolder()) {
2363-
TypeReference typeReference = createTypeReferenceForClassNode(genericsType.getType());
2364-
return typeReference;
2363+
return createTypeReferenceForClassNode(genericsType.getType());
23652364
} else {
23662365
// this means it is a placeholder. As an example, if the reference is to 'List'
23672366
// then the genericsType info may include a placeholder for the type variable (as the user

0 commit comments

Comments
 (0)