Skip to content

Commit

Permalink
Update the Groovy plugin to 4.0.1 (pt.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 5, 2022
1 parent 3585798 commit 44c31cb
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2021 the original author or authors.
* Copyright 2009-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2873,4 +2873,30 @@ public void testTraits10312() {

runConformTest(sources, "xx");
}

@Test
public void testTraits10521() {
//@formatter:off
String[] sources = {
"Script.groovy",
"abstract class A {\n" +
"}\n" +
"class C extends A implements T {\n" +
" void test() {\n" +
" p(90,'x')\n" +
" }\n" +
"}\n" +
"new C().test()\n",

"T.groovy",
"trait T {\n" +
" void p(one, Object... zeroOrMore) {\n" +
" print one; print zeroOrMore\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "90[x]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
private Set<String> resolutionFailed;
// GRECLIPSE end
private boolean checkingVariableTypeInDeclaration;
// GRECLIPSE private->protected
protected ImportNode currImportNode;
private ImportNode currImportNode;
private MethodNode currentMethod;
private ClassNodeResolver classNodeResolver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
private Set<String> resolutionFailed;
// GRECLIPSE end
private boolean checkingVariableTypeInDeclaration;
// GRECLIPSE private->protected
protected ImportNode currImportNode;
private ImportNode currImportNode;
private MethodNode currentMethod;
private ClassNodeResolver classNodeResolver;

Expand Down
Binary file modified base/org.codehaus.groovy40/lib/console/groovy-console-4.0.1.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/console/groovy-swing-4.0.1.jar
Binary file not shown.
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/console/groovy-xml-4.0.1.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/groovy-4.0.1-javadoc.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/groovy-4.0.1-sources.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/groovy-4.0.1.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/groovy-test-4.0.1-javadoc.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/groovy-test-4.0.1-sources.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/groovy-test-4.0.1.jar
Binary file not shown.
Binary file modified base/org.codehaus.groovy40/lib/shell/groovy-groovysh-4.0.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ private void addPhaseOperations() {
}, Phases.CONVERSION);

addPhaseOperation(source -> {
resolveVisitor.setClassNodeResolver(classNodeResolver);
for (ClassNode classNode : source.getAST().getClasses()) {
resolveVisitor.setClassNodeResolver(classNodeResolver);
resolveVisitor.startResolving(classNode, source);
}
}, Phases.SEMANTIC_ANALYSIS);
Expand Down Expand Up @@ -240,16 +240,15 @@ private void addPhaseOperations() {
CompileUnit cu = node.getCompileUnit();
for (Iterator<String> it = cu.getClassesToCompile().keySet().iterator(); it.hasNext(); ) {
String name = it.next();
StringBuilder message = new StringBuilder();
message
.append("Compilation incomplete: expected to find the class ")
StringBuilder message = new StringBuilder("Compilation incomplete: expected to find the class ")
.append(name)
.append(" in ")
.append(source.getName());
.append(source.getName())
.append(", but the file ");
if (classes.isEmpty()) {
message.append(", but the file seems not to contain any classes");
message.append("seems not to contain any classes");
} else {
message.append(", but the file contains the classes: ");
message.append("contains the classes: ");
boolean first = true;
for (ClassNode cn : classes) {
if (first) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public void addCollectorContents(final ErrorCollector that) {
}
}

public void addErrorAndContinue(final SyntaxException error, final SourceUnit source) throws CompilationFailedException {
public void addErrorAndContinue(final String error, final ASTNode node, final SourceUnit source) {
addErrorAndContinue(Message.create(new SyntaxException(error, node), source));
}

public void addErrorAndContinue(final SyntaxException error, final SourceUnit source) {
addErrorAndContinue(Message.create(error, source));
}

Expand All @@ -99,13 +103,6 @@ public void addErrorAndContinue(final Message message) {
errors.add(message);
}

public void addErrorAndContinue(final String error, final ASTNode node, final SourceUnit source) {
addErrorAndContinue(new SyntaxErrorMessage(
new SyntaxException(error, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
source)
);
}

/**
* Adds a non-fatal error to the message set, which may cause a failure if the error threshold is exceeded.
* The message is not required to have a source line and column specified, but it is best practice to try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,41 +84,38 @@
import static org.codehaus.groovy.ast.tools.ClosureUtils.getParametersSafe;

/**
* Visitor to resolve Types and convert VariableExpression to
* Visitor to resolve types and convert VariableExpression to
* ClassExpressions if needed. The ResolveVisitor will try to
* find the Class for a ClassExpression and prints an error if
* it fails to do so. Constructions like C[], foo as C, (C) foo
* will force creation of a ClassExpression for C
* <p>
* Note: the method to start the resolving is startResolving(ClassNode, SourceUnit).
* Note: the method to start the resolving is {@link #startResolving(ClassNode,SourceUnit)}.
*/
public class ResolveVisitor extends ClassCodeExpressionTransformer {

public static final String[] DEFAULT_IMPORTS = {"java.lang.", "java.util.", "java.io.", "java.net.", "groovy.lang.", "groovy.util."};
public static final String[] EMPTY_STRING_ARRAY = new String[0];
public static final String QUESTION_MARK = "?";

// GRECLIPSE private->protected
protected ClassNode currentClass;
// GRECLIPSE private->public
public final CompilationUnit compilationUnit;
private ClassNodeResolver classNodeResolver;
private SourceUnit source;
// GRECLIPSE private->protected
protected ClassNode currentClass;
private ImportNode currentImport;
private MethodNode currentMethod;
private VariableScope currentScope;

private boolean isTopLevelProperty = true;
private boolean inPropertyExpression;
private boolean inClosure;

private Map<GenericsTypeName, GenericsType> genericParameterNames = Collections.EMPTY_MAP;
private Set<FieldNode> fieldTypesChecked;
// GRECLIPSE add
private Set<String> resolutionFailed;
// GRECLIPSE end
private boolean checkingVariableTypeInDeclaration;
// GRECLIPSE private->protected
protected ImportNode currImportNode;
private MethodNode currentMethod;
private ClassNodeResolver classNodeResolver;
private boolean inClosure, inPropertyExpression;
private boolean isTopLevelProperty = true;

/**
* A ConstructedNestedClass consists of an outer class and a name part, denoting a
Expand Down Expand Up @@ -254,8 +251,6 @@ private Interrupt(final ProcessingUnit unit) {

public ResolveVisitor(final CompilationUnit compilationUnit) {
this.compilationUnit = compilationUnit;
// TODO: CompilationUnit.ClassNodeResolver?
setClassNodeResolver(new ClassNodeResolver());
}

public void setClassNodeResolver(final ClassNodeResolver classNodeResolver) {
Expand Down Expand Up @@ -538,12 +533,11 @@ private boolean setRedirect(final ClassNode type, final ClassNode classToCheck)
return true;
}
}
// GRECLIPSE add
if (classToCheck.getInterfaces().length > 0)
// GRECLIPSE end
for (ClassNode face : classToCheck.getAllInterfaces()) {
if (resolver.test(face)) {
return true;
if (classToCheck.getInterfaces().length > 0) {
for (ClassNode face : classToCheck.getAllInterfaces()) {
if (resolver.test(face)) {
return true;
}
}
}
return false;
Expand Down Expand Up @@ -697,12 +691,12 @@ private boolean resolveAliasFromModule(final ClassNode type) {
pname = name.substring(0, index);
ClassNode aliasedNode = null;
ImportNode importNode = module.getImport(pname);
if (importNode != null && importNode != currImportNode) {
if (importNode != null && importNode != currentImport) {
aliasedNode = importNode.getType();
}
if (aliasedNode == null) {
importNode = module.getStaticImports().get(pname);
if (importNode != null && importNode != currImportNode) {
if (importNode != null && importNode != currentImport) {
// static alias only for inner classes and must be at end of chain
ClassNode tmp = new ConstructedNestedClass(importNode.getType(), importNode.getFieldName());
if (resolve(tmp, false, false, true) && Modifier.isStatic(tmp.getModifiers())) {
Expand Down Expand Up @@ -868,6 +862,8 @@ protected boolean resolveFromModule(final ClassNode type, final boolean testModu

protected boolean resolveToOuter(final ClassNode type) {
String name = type.getName();
if (classNodeResolver == null)
classNodeResolver = new ClassNodeResolver();
// We do not need to check instances of LowerCaseClass
// to be a Class, because unless there was an import for
// for this we do not lookup these cases. This was a decision
Expand Down Expand Up @@ -1399,18 +1395,18 @@ public void visitClass(final ClassNode node) {
ModuleNode module = node.getModule();
if (!module.hasImportsResolved()) {
for (ImportNode importNode : module.getImports()) {
currImportNode = importNode;
currentImport = importNode;
ClassNode type = importNode.getType();
if (resolve(type, false, false, true)) {
currImportNode = null;
currentImport = null;
continue;
}
currImportNode = null;
currentImport = null;
addError("unable to resolve class " + type.getName(), type);
}
for (ImportNode importNode : module.getStarImports()) {
if (importNode.getLineNumber() > 0) {
currImportNode = importNode;
currentImport = importNode;
String importName = importNode.getPackageName();
importName = importName.substring(0, importName.length()-1);
ClassNode type = ClassHelper.makeWithoutCaching(importName);
Expand All @@ -1421,7 +1417,7 @@ public void visitClass(final ClassNode node) {
type.setEnd(type.getStart() + importName.length());
// GRECLIPSE end
}
currImportNode = null;
currentImport = null;
}
}
for (ImportNode importNode : module.getStaticImports().values()) {
Expand Down Expand Up @@ -1451,14 +1447,9 @@ public void visitClass(final ClassNode node) {

//

if (node instanceof InnerClassNode) {
if (Modifier.isStatic(node.getModifiers())) {
genericParameterNames = new HashMap<>();
}
} else {
if (!(node instanceof InnerClassNode) || Modifier.isStatic(node.getModifiers())) {
genericParameterNames = new HashMap<>();
}

resolveGenericsHeader(node.getGenericsTypes());

ClassNode sn = node.getUnresolvedSuperClass();
Expand Down Expand Up @@ -1553,9 +1544,8 @@ private void checkCyclicInheritance(final ClassNode node, final ClassNode type)
ClassNode cn = type; while (cn.getOuterClass() != null) cn = cn.getOuterClass();
addFatalError("Cycle detected: a cycle exists in the type hierarchy between " + node.getName() + " and " + cn.getName(), type);
// GRECLIPSE add
node.setHasInconsistentHierarchy(true);
node.setHasInconsistentHierarchy(true); break;
// GRECLIPSE end
return;
}
Collections.addAll(todo, next.getInterfaces());
todo.add(next.getUnresolvedSuperClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void addFatalError(String msg, ASTNode node) throws CompilationFailedExce
);
}

public void addErrorAndContinue(SyntaxException se) throws CompilationFailedException {
public void addErrorAndContinue(SyntaxException se) {
getErrorCollector().addErrorAndContinue(se, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
Expand Down Expand Up @@ -259,7 +258,7 @@ public synchronized void cleanUp() {
currentClass = null;
resetVariableScope();
setClassNodeResolver(null);
// TODO: Reset things like currentMethod, currImportNode, etc.?
// TODO: Reset things like currentMethod, currentImport, etc.?
}

@Override
Expand Down Expand Up @@ -421,11 +420,11 @@ protected boolean resolveToOuter(ClassNode type) {
ProblemReferenceBinding prBinding = (ProblemReferenceBinding) jdtBinding;
if (prBinding.problemId() == ProblemReasons.InternalNameProvided) {
jdtBinding = prBinding.closestMatch();
} else if (prBinding.problemId() == ProblemReasons.NotFound &&
prBinding.closestMatch() instanceof MissingTypeBinding && currImportNode != null && currImportNode.isStar()) {
}/*else if (prBinding.problemId() == ProblemReasons.NotFound &&
prBinding.closestMatch() instanceof MissingTypeBinding) {
MissingTypeBinding mtBinding = (MissingTypeBinding) prBinding.closestMatch();
mtBinding.fPackage.knownTypes.put(compoundName[compoundName.length - 1], null);
}
}*/
}

if ((jdtBinding instanceof BinaryTypeBinding || jdtBinding instanceof SourceTypeBinding) &&
Expand Down

0 comments on commit 44c31cb

Please sign in to comment.