Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 260046 Details for
Bug 488860
Binding recovery fails for the other occurrences of a unresolvable binding (making createASTs order dependent)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Runner file
file_488860.txt (text/plain), 4.56 KB, created by
Davy Landman
on 2016-03-02 09:03:52 EST
(
hide
)
Description:
Runner file
Filename:
MIME Type:
Creator:
Davy Landman
Created:
2016-03-02 09:03:52 EST
Size:
4.56 KB
patch
obsolete
>import java.io.File; >import java.nio.file.Path; >import java.util.HashMap; >import java.util.Hashtable; >import java.util.Map; >import java.util.concurrent.atomic.AtomicBoolean; > >import org.eclipse.jdt.core.JavaCore; >import org.eclipse.jdt.core.dom.AST; >import org.eclipse.jdt.core.dom.ASTParser; >import org.eclipse.jdt.core.dom.ASTVisitor; >import org.eclipse.jdt.core.dom.CompilationUnit; >import org.eclipse.jdt.core.dom.FileASTRequestor; >import org.eclipse.jdt.core.dom.MethodDeclaration; > >public class JDTOrderDependence { > > private static final int LEVEL = AST.JLS4; // btw also fails with JLS8 > private static final boolean BINDINGS_RECOVERY = true; // needs to be true, else no recovery happens > private static final boolean ERROR_RECOVERY = false; > > private static final File root = new File("/tmp/testing"); > private static final String nestedClass1 = new File(root, "NestedClass1.java").getAbsolutePath(); > private static final String nestedClass2 = new File(root, "NestedClass2.java").getAbsolutePath(); > private static final String qualifiedName1 = new File(root, "QualifiedName1.java").getAbsolutePath(); > private static final String qualifiedName2 = new File(root, "QualifiedName2.java").getAbsolutePath(); > private static final String qualifiedGeneric = new File(root, "QualifiedNameGeneric.java").getAbsolutePath(); > > public static void main(String[] args) { > assert root.exists() && root.isDirectory(); > > System.err.println("Binding recovery single file:"); > checkBindingPresent("Single class (nested)\t\t", nestedClass2, "method2", getASTs(root, nestedClass2)); > checkBindingPresent("Single class (qualified)\t", qualifiedName2, "method2", getASTs(root, qualifiedName2)); > checkBindingPresent("Single class (qualified-generic)", qualifiedGeneric, "method", getASTs(root, qualifiedGeneric)); > System.err.println("Binding recovery multiple file:"); > checkBindingPresent("Target 1st (nested)", nestedClass2, "method2", getASTs(root, nestedClass2, nestedClass1)); > checkBindingPresent("Target 2nd (nested)", nestedClass2, "method2", getASTs(root, nestedClass1, nestedClass2)); > checkBindingPresent("Target 1st (qualified)", qualifiedName2, "method2", getASTs(root, qualifiedName2, qualifiedName1)); > checkBindingPresent("Target 2nd (qualified)", qualifiedName2, "method2", getASTs(root, qualifiedName1, qualifiedName2)); > } > > static void checkBindingPresent(final String name, String classFileName, final String methodName, Map<String, CompilationUnit> asts) { > final AtomicBoolean found = new AtomicBoolean(false); > asts.get(classFileName).accept(new ASTVisitor() { > @Override > public boolean visit(MethodDeclaration node) { > if (node.getName().toString().equals(methodName)) { > if (node.resolveBinding() == null) { > System.err.println(name + "\t=> Failed"); > } > else { > System.err.println(name + "\t=> Success"); > } > found.set(true); > } > return true; > } > }); > if (!found.get()) { > System.err.println(name + "\t=> method \"missing\" in AST"); > } > } > > private static Map<String, CompilationUnit> getASTs(File sourcePath, String... files) { > ASTParser parser = constructASTParser(new String[]{sourcePath.getAbsolutePath()}); > final HashMap<String, CompilationUnit> result = new HashMap<>(); > parser.createASTs(files, null, new String[0], new FileASTRequestor() { > @Override > public void acceptAST(String sourceFilePath, CompilationUnit ast) { > result.put(sourceFilePath, ast); > } > > }, null); > return result; > } > > private static ASTParser constructASTParser(String[] sourcePath) { > ASTParser parser = ASTParser.newParser(LEVEL); > parser.setResolveBindings(true); > parser.setBindingsRecovery(BINDINGS_RECOVERY); > parser.setStatementsRecovery(ERROR_RECOVERY); > > Hashtable<String, String> options = new Hashtable<String, String>(); > options.put(JavaCore.COMPILER_SOURCE, "1.7"); > options.put(JavaCore.COMPILER_COMPLIANCE, "1.7"); > options.put(JavaCore.CORE_ENCODING, "UTF-8"); > parser.setCompilerOptions(options); > > parser.setEnvironment(null, sourcePath, null, true); > return parser; > } > > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 488860
: 260046 |
260047
|
260048