mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 17:40:48 +01:00
prediction from 3rd party libraries
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
destdir="bin"
|
||||
encoding="UTF-8"
|
||||
includeAntRuntime="false"
|
||||
classpath="../core/library/core.jar; ${env.JAVA_HOME}/lib/tools.jar; ../app/lib/ant.jar; ../app/lib/ant-launcher.jar; ../app/lib/antlr.jar; ../app/lib/apple.jar; ../app/lib/jdt-core.jar; ../app/lib/jna.jar; ../app/lib/org-netbeans-swing-outline.jar; ../app/pde.jar; mode/CompilationChecker.jar; mode/com.ibm.icu_4.4.2.v20110823.jar; mode/jdi.jar; mode/jdimodel.jar; mode/org.eclipse.core.contenttype_3.4.200.v20120523-2004.jar; mode/org.eclipse.core.jobs_3.5.300.v20120622-204750.jar; mode/org.eclipse.core.resources_3.8.1.v20120802-154922.jar; mode/org.eclipse.core.runtime_3.8.0.v20120521-2346.jar; mode/org.eclipse.equinox.common_3.6.100.v20120522-1841.jar; mode/org.eclipse.equinox.preferences_3.5.0.v20120522-1841.jar; mode/org.eclipse.jdt.core_3.8.2.v20120814-155456.jar; mode/org.eclipse.jdt.debug_3.7.101.v20120725-115645.jar; mode/org.eclipse.osgi_3.8.1.v20120830-144521.jar; mode/org.eclipse.text_3.5.200.v20120523-1310.jar"
|
||||
classpath="../core/library/core.jar; ${env.JAVA_HOME}/lib/tools.jar; ../app/lib/ant.jar; ../app/lib/ant-launcher.jar; ../app/lib/antlr.jar; ../app/lib/apple.jar; ../app/lib/jdt-core.jar; ../app/lib/jna.jar; ../app/lib/org-netbeans-swing-outline.jar; ../app/pde.jar; mode/CompilationChecker.jar; mode/com.ibm.icu_4.4.2.v20110823.jar; mode/jdi.jar; mode/jdimodel.jar; mode/org.eclipse.core.contenttype_3.4.200.v20120523-2004.jar; mode/org.eclipse.core.jobs_3.5.300.v20120622-204750.jar; mode/org.eclipse.core.resources_3.8.1.v20120802-154922.jar; mode/org.eclipse.core.runtime_3.8.0.v20120521-2346.jar; mode/org.eclipse.equinox.common_3.6.100.v20120522-1841.jar; mode/org.eclipse.equinox.preferences_3.5.0.v20120522-1841.jar; mode/org.eclipse.jdt.core_3.8.2.v20120814-155456.jar; mode/org.eclipse.jdt.debug_3.7.101.v20120725-115645.jar; mode/org.eclipse.osgi_3.8.1.v20120830-144521.jar; mode/org.eclipse.text_3.5.200.v20120523-1310.jar; mode/classpath-explorer-1.0.jar"
|
||||
debug="on">
|
||||
<src path="src" />
|
||||
</javac>
|
||||
|
||||
@@ -7,6 +7,10 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -47,6 +51,12 @@ import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
|
||||
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
|
||||
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
|
||||
|
||||
import com.google.classpath.ClassPath;
|
||||
import com.google.classpath.ClassPathFactory;
|
||||
import com.google.classpath.RegExpResourceFilter;
|
||||
import com.ibm.icu.util.StringTokenizer;
|
||||
import com.sun.jdi.Type;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.SketchCode;
|
||||
|
||||
@@ -87,7 +97,7 @@ public class ASTGenerator {
|
||||
JScrollPane sp2 = new JScrollPane();
|
||||
sp2.setViewportView(tableAuto);
|
||||
frameAutoComp.add(sp2);
|
||||
|
||||
//loadJars();
|
||||
}
|
||||
|
||||
public class ASTNodeWrapper {
|
||||
@@ -162,8 +172,11 @@ public class ASTGenerator {
|
||||
// return;
|
||||
jtree.setModel(new DefaultTreeModel(codeTree));
|
||||
((DefaultTreeModel) jtree.getModel()).reload();
|
||||
if (!frame2.isVisible())
|
||||
if (!frame2.isVisible()) {
|
||||
frame2.setVisible(true);
|
||||
loadJars();
|
||||
//System.out.println(System.getProperty("java.home"));
|
||||
}
|
||||
if (!frameAutoComp.isVisible())
|
||||
frameAutoComp.setVisible(true);
|
||||
jtree.validate();
|
||||
@@ -171,10 +184,55 @@ public class ASTGenerator {
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
|
||||
System.err.println("++>" + System.getProperty("java.class.path"));
|
||||
// System.out.println(System.getProperty("java.class.path"));
|
||||
// System.out.println("-------------------------------");
|
||||
return codeTree;
|
||||
}
|
||||
|
||||
private ClassPathFactory factory;
|
||||
|
||||
private ClassPath classPath;
|
||||
|
||||
private void loadJars() {
|
||||
try {
|
||||
factory = new ClassPathFactory();
|
||||
|
||||
String tehPaths = System.getProperty("java.class.path")
|
||||
+ File.pathSeparatorChar + System.getProperty("java.home")
|
||||
+ "/lib/rt.jar";
|
||||
StringBuffer tehPath = new StringBuffer(System.getProperty("java.class.path")
|
||||
+ File.pathSeparatorChar + System.getProperty("java.home")
|
||||
+ "/lib/rt.jar");
|
||||
if(errorCheckerService.classpathJars != null){
|
||||
for (URL jarPath : errorCheckerService.classpathJars) {
|
||||
tehPath.append(jarPath.getPath() + File.pathSeparatorChar);
|
||||
}
|
||||
}
|
||||
|
||||
//String paths[] = tehPaths.split(File.separatorChar +"");
|
||||
StringTokenizer st = new StringTokenizer(tehPath.toString(), File.pathSeparatorChar
|
||||
+ "");
|
||||
while (st.hasMoreElements()) {
|
||||
System.out.println("- " + st.nextToken());
|
||||
}
|
||||
classPath = factory.createFromPath(tehPath.toString());
|
||||
for (String packageName : classPath.listPackages("")) {
|
||||
System.out.println(packageName);
|
||||
}
|
||||
RegExpResourceFilter regExpResourceFilter = new RegExpResourceFilter(
|
||||
".*",
|
||||
"Vec3D.class");
|
||||
String[] resources = classPath.findResources("", regExpResourceFilter);
|
||||
for (String className : resources) {
|
||||
System.out.println("-> " + className);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public DefaultMutableTreeNode buildAST() {
|
||||
return buildAST2(errorCheckerService.sourceCode);
|
||||
}
|
||||
@@ -295,8 +353,10 @@ public class ASTGenerator {
|
||||
return findDeclaration2(((MethodInvocation) expression).getName(),
|
||||
nearestNode);
|
||||
} else if (expression instanceof FieldAccess) {
|
||||
System.out.println("2. Field access " + getNodeAsString(((FieldAccess)expression).getExpression()));
|
||||
return resolveExpression(nearestNode, ((FieldAccess)expression).getExpression());
|
||||
System.out.println("2. Field access "
|
||||
+ getNodeAsString(((FieldAccess) expression).getExpression()));
|
||||
return resolveExpression(nearestNode,
|
||||
((FieldAccess) expression).getExpression());
|
||||
//return findDeclaration2(((FieldAccess) expression).getExpression(), nearestNode);
|
||||
} else if (expression instanceof QualifiedName) {
|
||||
System.out.println("1. Resolving "
|
||||
@@ -430,6 +490,9 @@ public class ASTGenerator {
|
||||
}
|
||||
anode = anode.getParent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// Complex expression of type blah.blah2().doIt,etc
|
||||
@@ -443,24 +506,23 @@ public class ASTGenerator {
|
||||
System.err.println("DET " + getNodeAsString(det));
|
||||
if (det != null) {
|
||||
TypeDeclaration td = null;
|
||||
SimpleType stp = null;
|
||||
if (det instanceof MethodDeclaration) {
|
||||
if (((MethodDeclaration) det).getReturnType2() instanceof SimpleType) {
|
||||
SimpleType stp = (SimpleType) (((MethodDeclaration) det)
|
||||
.getReturnType2());
|
||||
stp = (SimpleType) (((MethodDeclaration) det).getReturnType2());
|
||||
td = (TypeDeclaration) findDeclaration(stp.getName());
|
||||
}
|
||||
} else if (det instanceof FieldDeclaration) {
|
||||
if (((FieldDeclaration) det).getType() instanceof SimpleType) {
|
||||
SimpleType stp = (SimpleType) (((FieldDeclaration) det)
|
||||
.getType());
|
||||
stp = (SimpleType) (((FieldDeclaration) det).getType());
|
||||
td = (TypeDeclaration) findDeclaration(stp.getName());
|
||||
}
|
||||
} else if (det instanceof VariableDeclarationStatement) {
|
||||
SimpleType stp = (SimpleType) (((VariableDeclarationStatement) det)
|
||||
stp = (SimpleType) (((VariableDeclarationStatement) det)
|
||||
.getType());
|
||||
td = (TypeDeclaration) findDeclaration(stp.getName());
|
||||
}
|
||||
|
||||
System.out.println("ST is " + stp.getName());
|
||||
// Now td contains the type returned by a()
|
||||
System.err.println(getNodeAsString(det) + " defined in "
|
||||
+ getNodeAsString(td));
|
||||
@@ -488,6 +550,45 @@ public class ASTGenerator {
|
||||
.startsWith(child.toString()))
|
||||
candidates.add(getNodeAsString(td.getMethods()[i]));
|
||||
}
|
||||
} else {
|
||||
if (stp != null) {
|
||||
System.out.println("Couldn't determine type! "
|
||||
+ stp.getName().toString());
|
||||
RegExpResourceFilter regExpResourceFilter;
|
||||
regExpResourceFilter = new RegExpResourceFilter(".*", stp
|
||||
.getName().toString() + ".class");
|
||||
String[] resources = classPath
|
||||
.findResources("", regExpResourceFilter);
|
||||
for (String className : resources) {
|
||||
System.out.println("-> " + className);
|
||||
}
|
||||
if(resources.length > 0){
|
||||
String matchedClass = resources[0];
|
||||
matchedClass = matchedClass.substring(0,matchedClass.length() - 6);
|
||||
matchedClass = matchedClass.replace('/', '.');
|
||||
System.out.println("Matched class: " + matchedClass);
|
||||
try {
|
||||
Class<?> probableClass = Class.forName(matchedClass, false, errorCheckerService.classLoader);
|
||||
for (Method method : probableClass.getMethods()) {
|
||||
StringBuffer label = new StringBuffer(method.getName() + "(");
|
||||
for (Class<?> type : method.getParameterTypes()) {
|
||||
label.append(type.getSimpleName() + ",");
|
||||
}
|
||||
label.append(")");
|
||||
candidates.add(label.toString());
|
||||
}
|
||||
for (Field field : probableClass.getFields()) {
|
||||
candidates.add(field.getName());
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Couldn't load " + matchedClass);
|
||||
}
|
||||
|
||||
//processing/core/PVector.class
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -265,10 +265,11 @@ public class ErrorCheckerService implements Runnable{
|
||||
sourceCode = preprocessCode(editor.getSketch().getMainProgram());
|
||||
|
||||
syntaxCheck();
|
||||
System.err.println(editor.getSketch().getName()+ " MCO " + mainClassOffset);
|
||||
System.err.println(editor.getSketch().getName()+ "1 MCO " + mainClassOffset);
|
||||
// No syntax errors, proceed for compilation check, Stage 2.
|
||||
|
||||
if (problems.length == 0 && editor.compilationCheckEnabled) {
|
||||
mainClassOffset++; // just a hack.
|
||||
astGenerator.buildAST();
|
||||
sourceCode = xqpreproc.doYourThing(sourceCode, programImports);
|
||||
prepareCompilerClasspath();
|
||||
@@ -280,7 +281,7 @@ public class ErrorCheckerService implements Runnable{
|
||||
// System.out.println(sourceCode);
|
||||
// System.out.println("--------------------------");
|
||||
compileCheck();
|
||||
|
||||
System.err.println(editor.getSketch().getName()+ "2 MCO " + mainClassOffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -332,7 +333,7 @@ public class ErrorCheckerService implements Runnable{
|
||||
// System.out.println(p.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected URLClassLoader classLoader;
|
||||
private void compileCheck() {
|
||||
|
||||
// Currently (Sept, 2012) I'm using Java's reflection api to load the
|
||||
@@ -370,19 +371,21 @@ public class ErrorCheckerService implements Runnable{
|
||||
|
||||
File[] jarFiles = f.listFiles(fileFilter);
|
||||
// System.out.println( "Jar files found? " + (jarFiles != null));
|
||||
for (File jarFile : jarFiles) {
|
||||
classpathJars.add(jarFile.toURI().toURL());
|
||||
}
|
||||
//for (File jarFile : jarFiles) {
|
||||
//classpathJars.add(jarFile.toURI().toURL());
|
||||
//}
|
||||
|
||||
classpath = new URL[classpathJars.size()]; // + 1 for
|
||||
// Compilation
|
||||
// Checker class
|
||||
for (int i = 0; i < classpathJars.size(); i++) {
|
||||
classpath[i] = classpathJars.get(i);
|
||||
classpath = new URL[classpathJars.size() + jarFiles.length];
|
||||
int ii = 0;
|
||||
for (; ii < classpathJars.size(); ii++) {
|
||||
classpath[ii] = classpathJars.get(ii);
|
||||
}
|
||||
for (int i = 0; i < jarFiles.length; i++) {
|
||||
classpath[ii++] = jarFiles[i].toURI().toURL();
|
||||
}
|
||||
|
||||
// System.out.println("CP Len -- " + classpath.length);
|
||||
URLClassLoader classLoader = new URLClassLoader(classpath);
|
||||
classLoader = new URLClassLoader(classpath);
|
||||
// System.out.println("1.");
|
||||
checkerClass = Class.forName("CompilationChecker", true,
|
||||
classLoader);
|
||||
|
||||
Reference in New Issue
Block a user