"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/org/codehaus/groovy/control/ResolveVisitor.java" between
apache-groovy-src-3.0.8.zip and apache-groovy-src-3.0.9.zip

About: Groovy is an agile dynamic (scripting) language for the Java Platform. It has features similar to those of Python, Ruby, Perl, and Smalltalk. Source release.

ResolveVisitor.java  (apache-groovy-src-3.0.8):ResolveVisitor.java  (apache-groovy-src-3.0.9)
skipping to change at line 76 skipping to change at line 76
import org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache; import org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache;
import org.codehaus.groovy.syntax.Types; import org.codehaus.groovy.syntax.Types;
import org.codehaus.groovy.transform.trait.Traits; import org.codehaus.groovy.transform.trait.Traits;
import org.codehaus.groovy.vmplugin.VMPluginFactory; import org.codehaus.groovy.vmplugin.VMPluginFactory;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
skipping to change at line 946 skipping to change at line 947
return null; return null;
} }
String property = ((PropertyExpression) expr).getPropertyAsString(); String property = ((PropertyExpression) expr).getPropertyAsString();
// the class property stops resolving, dynamic property names too // the class property stops resolving, dynamic property names too
if (property == null || property.equals("class")) { if (property == null || property.equals("class")) {
return null; return null;
} }
Tuple2<StringBuilder, Boolean> classNameInfo = makeClassName(doIniti alClassTest, name, property); Tuple2<StringBuilder, Boolean> classNameInfo = makeClassName(doIniti alClassTest, name, property);
name = classNameInfo.getV1(); name = classNameInfo.getV1();
if (name == null) return null;
doInitialClassTest = classNameInfo.getV2(); doInitialClassTest = classNameInfo.getV2();
} }
if (null == name || name.length() == 0) return null; if (null == name || name.length() == 0) return null;
return name.toString(); return name.toString();
} }
private static Tuple2<StringBuilder, Boolean> makeClassName(final boolean do InitialClassTest, final StringBuilder name, final String varName) { private static Tuple2<StringBuilder, Boolean> makeClassName(final boolean do InitialClassTest, final StringBuilder name, final String varName) {
if (doInitialClassTest) { if (doInitialClassTest) {
skipping to change at line 1463 skipping to change at line 1465
} }
for (ImportNode importNode : module.getStaticStarImports().values()) { for (ImportNode importNode : module.getStaticStarImports().values()) {
ClassNode type = importNode.getType(); ClassNode type = importNode.getType();
if (resolve(type, true, true, true)) continue; if (resolve(type, true, true, true)) continue;
addError("unable to resolve class " + type.getName(), type); addError("unable to resolve class " + type.getName(), type);
} }
module.setImportsResolved(true); module.setImportsResolved(true);
} }
ClassNode sn = node.getUnresolvedSuperClass(); ClassNode sn = node.getUnresolvedSuperClass();
if (sn != null) resolveOrFail(sn, "", node, true); if (sn != null) {
resolveOrFail(sn, "", node, true);
for (ClassNode anInterface : node.getInterfaces()) { }
resolveOrFail(anInterface, "", node, true); for (ClassNode in : node.getInterfaces()) {
resolveOrFail(in, "", node, true);
} }
checkCyclicInheritance(node, node.getUnresolvedSuperClass(), node.getInt if (sn != null) checkCyclicInheritance(node, sn);
erfaces()); for (ClassNode in : node.getInterfaces()) {
checkCyclicInheritance(node, in);
}
if (node.getGenericsTypes() != null) {
for (GenericsType gt : node.getGenericsTypes()) {
if (gt != null && gt.getUpperBounds() != null) {
for (ClassNode variant : gt.getUpperBounds()) {
if (variant.isGenericsPlaceHolder()) checkCyclicInherita
nce(gt.getType().redirect(), variant);
}
}
}
}
super.visitClass(node); super.visitClass(node);
resolveOuterNestedClassFurther(node); resolveOuterNestedClassFurther(node);
currentClass = oldNode; currentClass = oldNode;
} }
private void checkCyclicInheritance(final ClassNode node, final ClassNode ty
pe) {
if (type.redirect() == node || type.getOuterClasses().contains(node)) {
addError("Cycle detected: the type " + node.getName() + " cannot ext
end/implement itself or one of its own member types", type);
} else if (type != ClassHelper.OBJECT_TYPE) {
Set<ClassNode> done = new HashSet<>();
done.add(ClassHelper.OBJECT_TYPE);
done.add(null);
LinkedList<ClassNode> todo = new LinkedList<>();
Collections.addAll(todo, type.getInterfaces());
todo.add(type.getUnresolvedSuperClass());
todo.add(type.getOuterClass());
do {
ClassNode next = todo.poll();
if (!done.add(next)) continue;
if (next.redirect() == node) {
ClassNode cn = type; while (cn.getOuterClass() != null) cn =
cn.getOuterClass();
addError("Cycle detected: a cycle exists in the type hierarc
hy between " + node.getName() + " and " + cn.getName(), type);
return;
}
Collections.addAll(todo, next.getInterfaces());
todo.add(next.getUnresolvedSuperClass());
todo.add(next.getOuterClass());
} while (!todo.isEmpty());
}
}
// GROOVY-7812(#2): Static inner classes cannot be accessed from other files when running by 'groovy' command // GROOVY-7812(#2): Static inner classes cannot be accessed from other files when running by 'groovy' command
private void resolveOuterNestedClassFurther(final ClassNode node) { private void resolveOuterNestedClassFurther(final ClassNode node) {
CompileUnit compileUnit = currentClass.getCompileUnit(); CompileUnit compileUnit = currentClass.getCompileUnit();
if (null == compileUnit) return; if (null == compileUnit) return;
Map<String, ConstructedOuterNestedClassNode> classesToResolve = compileU nit.getClassesToResolve(); Map<String, ConstructedOuterNestedClassNode> classesToResolve = compileU nit.getClassesToResolve();
List<String> resolvedInnerClassNameList = new LinkedList<>(); List<String> resolvedInnerClassNameList = new LinkedList<>();
for (Map.Entry<String, ConstructedOuterNestedClassNode> entry : classesT oResolve.entrySet()) { for (Map.Entry<String, ConstructedOuterNestedClassNode> entry : classesT oResolve.entrySet()) {
skipping to change at line 1509 skipping to change at line 1551
constructedOuterNestedClass.setRedirect(innerClassNode); constructedOuterNestedClass.setRedirect(innerClassNode);
resolvedInnerClassNameList.add(innerClassName); resolvedInnerClassNameList.add(innerClassName);
} }
} }
for (String innerClassName : resolvedInnerClassNameList) { for (String innerClassName : resolvedInnerClassNameList) {
classesToResolve.remove(innerClassName); classesToResolve.remove(innerClassName);
} }
} }
private void checkCyclicInheritance(final ClassNode originalNode, final Clas
sNode parentToCompare, final ClassNode[] interfacesToCompare) {
if (!originalNode.isInterface()) {
if (parentToCompare == null) return;
if (originalNode == parentToCompare.redirect()) {
addError("Cyclic inheritance involving " + parentToCompare.getNa
me() + " in class " + originalNode.getName(), originalNode);
return;
}
if (interfacesToCompare != null && interfacesToCompare.length > 0) {
for (ClassNode intfToCompare : interfacesToCompare) {
if (originalNode == intfToCompare.redirect()) {
addError("Cycle detected: the type " + originalNode.getN
ame() + " cannot implement itself" , originalNode);
return;
}
}
}
if (parentToCompare == ClassHelper.OBJECT_TYPE) return;
checkCyclicInheritance(originalNode, parentToCompare.getUnresolvedSu
perClass(), null);
} else {
if (interfacesToCompare != null && interfacesToCompare.length > 0) {
// check interfaces at this level first
for (ClassNode intfToCompare : interfacesToCompare) {
if(originalNode == intfToCompare.redirect()) {
addError("Cyclic inheritance involving " + intfToCompare
.getName() + " in interface " + originalNode.getName(), originalNode);
return;
}
}
// check next level of interfaces
for (ClassNode intf : interfacesToCompare) {
checkCyclicInheritance(originalNode, null, intf.getInterface
s());
}
}
}
}
@Override
public void visitCatchStatement(final CatchStatement cs) { public void visitCatchStatement(final CatchStatement cs) {
resolveOrFail(cs.getExceptionType(), cs); resolveOrFail(cs.getExceptionType(), cs);
if (cs.getExceptionType() == ClassHelper.DYNAMIC_TYPE) { if (cs.getExceptionType() == ClassHelper.DYNAMIC_TYPE) {
cs.getVariable().setType(ClassHelper.make(Exception.class)); cs.getVariable().setType(ClassHelper.make(Exception.class));
} }
super.visitCatchStatement(cs); super.visitCatchStatement(cs);
} }
@Override @Override
public void visitForLoop(final ForStatement forLoop) { public void visitForLoop(final ForStatement forLoop) {
 End of changes. 6 change blocks. 
47 lines changed or deleted 52 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)