mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 11:21:06 +01:00
cleaning up the mess while trying to find completion problems
This commit is contained in:
@@ -43,7 +43,7 @@ public class JavaMode extends Mode {
|
||||
|
||||
public JavaMode(Base base, File folder) {
|
||||
super(base, folder);
|
||||
|
||||
|
||||
initLogger();
|
||||
loadPreferences();
|
||||
}
|
||||
@@ -52,8 +52,8 @@ public class JavaMode extends Mode {
|
||||
public String getTitle() {
|
||||
return "Java";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ public class JavaMode extends Mode {
|
||||
// try {
|
||||
// coreLibrary = getLibrary("processing.core");
|
||||
// System.out.println("core found at " + coreLibrary.getLibraryPath());
|
||||
// } catch (SketchException e) {
|
||||
// } catch (SketchException e) {
|
||||
// Base.log("Serious problem while locating processing.core", e);
|
||||
// }
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class JavaMode extends Mode {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Runner handlePresent(Sketch sketch,
|
||||
RunnerListener listener) throws SketchException {
|
||||
final JavaEditor editor = (JavaEditor)listener;
|
||||
@@ -132,7 +132,7 @@ public class JavaMode extends Mode {
|
||||
|
||||
|
||||
/** Handles the standard Java "Run" or "Present" */
|
||||
public Runner handleLaunch(Sketch sketch, RunnerListener listener,
|
||||
public Runner handleLaunch(Sketch sketch, RunnerListener listener,
|
||||
final boolean present) throws SketchException {
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
@@ -236,12 +236,12 @@ public class JavaMode extends Mode {
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
return build.exportApplication();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
// Merged from ExperimentalMode
|
||||
|
||||
|
||||
|
||||
void initLogger() {
|
||||
final boolean VERBOSE_LOGGING = true;
|
||||
@@ -272,8 +272,8 @@ public class JavaMode extends Mode {
|
||||
Logger.getLogger(JavaMode.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//ImageIcon classIcon, fieldIcon, methodIcon, localVarIcon;
|
||||
|
||||
// protected void loadIcons() {
|
||||
@@ -284,7 +284,7 @@ public class JavaMode extends Mode {
|
||||
// localVarIcon = new ImageIcon(iconPath + File.separator + "field_default_obj.png");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
static public volatile boolean errorCheckEnabled = true;
|
||||
static public volatile boolean warningsEnabled = true;
|
||||
static public volatile boolean codeCompletionsEnabled = true;
|
||||
@@ -380,8 +380,8 @@ public class JavaMode extends Mode {
|
||||
if (Preferences.get(prefImportSuggestEnabled) == null)
|
||||
Preferences.setBoolean(prefImportSuggestEnabled, importSuggestEnabled);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static public void main(String[] args) {
|
||||
processing.app.Base.main(args);
|
||||
}
|
||||
|
||||
@@ -25,16 +25,14 @@ import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -67,7 +65,6 @@ import javax.swing.JTree;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
@@ -93,7 +90,6 @@ import org.eclipse.jdt.core.dom.FieldDeclaration;
|
||||
import org.eclipse.jdt.core.dom.MethodDeclaration;
|
||||
import org.eclipse.jdt.core.dom.MethodInvocation;
|
||||
import org.eclipse.jdt.core.dom.Name;
|
||||
import org.eclipse.jdt.core.dom.NodeFinder;
|
||||
import org.eclipse.jdt.core.dom.ParameterizedType;
|
||||
import org.eclipse.jdt.core.dom.PrimitiveType;
|
||||
import org.eclipse.jdt.core.dom.QualifiedName;
|
||||
@@ -106,6 +102,9 @@ import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
|
||||
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
|
||||
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Library;
|
||||
@@ -120,54 +119,35 @@ import com.google.classpath.ClassPath;
|
||||
import com.google.classpath.ClassPathFactory;
|
||||
import com.google.classpath.RegExpResourceFilter;
|
||||
|
||||
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
public class ASTGenerator {
|
||||
|
||||
protected ErrorCheckerService errorCheckerService;
|
||||
|
||||
protected JavaEditor editor;
|
||||
|
||||
public DefaultMutableTreeNode codeTree = new DefaultMutableTreeNode();
|
||||
|
||||
protected DefaultMutableTreeNode currentParent = null;
|
||||
|
||||
/**
|
||||
* AST Window
|
||||
*/
|
||||
protected JFrame frmASTView;
|
||||
|
||||
protected JFrame frameAutoComp;
|
||||
|
||||
/**
|
||||
* Swing component wrapper for AST, used for internal testing
|
||||
*/
|
||||
/** Swing component wrapper for AST, used for internal testing */
|
||||
protected JTree jtree;
|
||||
|
||||
/**
|
||||
* JTree used for testing refactoring operations
|
||||
*/
|
||||
protected JTree treeRename;
|
||||
/** JTree used for testing refactoring operations */
|
||||
protected JTree refactorTree;
|
||||
|
||||
protected CompilationUnit compilationUnit;
|
||||
|
||||
protected JTable tableAuto;
|
||||
|
||||
protected JEditorPane javadocPane;
|
||||
|
||||
protected JScrollPane scrollPane;
|
||||
|
||||
protected JFrame frmRename;
|
||||
|
||||
protected JButton btnRename;
|
||||
|
||||
protected JButton btnListOccurrence;
|
||||
|
||||
protected JTextField txtRenameField;
|
||||
|
||||
protected JFrame frmOccurenceList;
|
||||
|
||||
protected JLabel lblRefactorOldName;
|
||||
|
||||
|
||||
public ASTGenerator(ErrorCheckerService ecs) {
|
||||
this.errorCheckerService = ecs;
|
||||
this.editor = ecs.getEditor();
|
||||
@@ -178,7 +158,8 @@ public class ASTGenerator {
|
||||
predictionOngoing = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
protected void setupGUI(){
|
||||
|
||||
protected void setupGUI() {
|
||||
frmASTView = new JFrame();
|
||||
|
||||
jtree = new JTree();
|
||||
@@ -229,40 +210,13 @@ public class ASTGenerator {
|
||||
frmOccurenceList.setSize(300, 400);
|
||||
Toolkit.setIcon(frmOccurenceList);
|
||||
JScrollPane sp2 = new JScrollPane();
|
||||
treeRename = new JTree();
|
||||
sp2.setViewportView(treeRename);
|
||||
refactorTree = new JTree();
|
||||
sp2.setViewportView(refactorTree);
|
||||
frmOccurenceList.add(sp2);
|
||||
//occurenceListFrame.setVisible(true);
|
||||
|
||||
// frameAutoComp = new JFrame();
|
||||
// frameAutoComp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
// frameAutoComp.setBounds(new Rectangle(1280, 100, 460, 620));
|
||||
// Toolkit.setIcon(frameAutoComp);
|
||||
// tableAuto = new JTable();
|
||||
// JScrollPane sp3 = new JScrollPane();
|
||||
// sp3.setViewportView(tableAuto);
|
||||
// frameAutoComp.add(sp3);
|
||||
|
||||
// frmJavaDoc = new JFrame();
|
||||
// frmJavaDoc.setTitle("P5 InstaHelp");
|
||||
// //jdocWindow.setUndecorated(true);
|
||||
// frmJavaDoc.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
// javadocPane = new JEditorPane();
|
||||
// javadocPane.setContentType("text/html");
|
||||
// javadocPane.setText("<html> </html>");
|
||||
// javadocPane.setEditable(false);
|
||||
// scrollPane = new JScrollPane();
|
||||
// scrollPane.setViewportView(javadocPane);
|
||||
// frmJavaDoc.add(scrollPane);
|
||||
//frmJavaDoc.setUndecorated(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle AST View window
|
||||
*/
|
||||
public static final boolean SHOWAST = !true;
|
||||
|
||||
public static final boolean SHOW_AST = !true;
|
||||
|
||||
protected DefaultMutableTreeNode buildAST(String source, CompilationUnit cu) {
|
||||
if (cu == null) {
|
||||
@@ -299,7 +253,7 @@ public class ASTGenerator {
|
||||
|
||||
protected void done() {
|
||||
if (codeTree != null) {
|
||||
if(SHOWAST){
|
||||
if(SHOW_AST){
|
||||
if (jtree.hasFocus() || frmASTView.hasFocus())
|
||||
return;
|
||||
jtree.setModel(new DefaultTreeModel(codeTree));
|
||||
@@ -348,95 +302,100 @@ public class ASTGenerator {
|
||||
* Loads up .jar files and classes defined in it for completion lookup
|
||||
*/
|
||||
protected void loadJars() {
|
||||
// SwingWorker worker = new SwingWorker() {
|
||||
// protected void done(){
|
||||
// }
|
||||
// protected Object doInBackground() throws Exception {
|
||||
// return null;
|
||||
// }
|
||||
// };
|
||||
// worker.execute();
|
||||
factory = new ClassPathFactory();
|
||||
|
||||
Thread t = new Thread(new Runnable() {
|
||||
StringBuilder tehPath = new StringBuilder(System
|
||||
.getProperty("java.class.path"));
|
||||
// Starting with JDK 1.7, no longer using Apple's Java, so
|
||||
// rt.jar has the same path on all OSes
|
||||
tehPath.append(File.pathSeparatorChar
|
||||
+ System.getProperty("java.home") + File.separator + "lib"
|
||||
+ File.separator + "rt.jar" + File.pathSeparatorChar);
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
factory = new ClassPathFactory();
|
||||
|
||||
StringBuilder tehPath = new StringBuilder(System
|
||||
.getProperty("java.class.path"));
|
||||
// Starting with JDK 1.7, no longer using Apple's Java, so
|
||||
// rt.jar has the same path on all OSes
|
||||
tehPath.append(File.pathSeparatorChar
|
||||
+ System.getProperty("java.home") + File.separator + "lib"
|
||||
+ File.separator + "rt.jar" + File.pathSeparatorChar);
|
||||
|
||||
if (errorCheckerService.classpathJars != null) {
|
||||
synchronized (errorCheckerService.classpathJars) {
|
||||
for (URL jarPath : errorCheckerService.classpathJars) {
|
||||
//log(jarPath.getPath());
|
||||
tehPath.append(jarPath.getPath() + File.pathSeparatorChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// String paths[] = tehPath.toString().split(File.separatorChar +"");
|
||||
// StringTokenizer st = new StringTokenizer(tehPath.toString(),
|
||||
// File.pathSeparatorChar + "");
|
||||
// while (st.hasMoreElements()) {
|
||||
// String sstr = (String) st.nextElement();
|
||||
// log(sstr);
|
||||
// }
|
||||
|
||||
classPath = factory.createFromPath(tehPath.toString());
|
||||
log("Classpath created " + (classPath != null));
|
||||
// for (String packageName : classPath.listPackages("")) {
|
||||
// log(packageName);
|
||||
// }
|
||||
// RegExpResourceFilter regExpResourceFilter = new RegExpResourceFilter(
|
||||
// ".*",
|
||||
// "ArrayList.class");
|
||||
// String[] resources = classPath.findResources("", regExpResourceFilter);
|
||||
// for (String className : resources) {
|
||||
// log("-> " + className);
|
||||
// }
|
||||
log("Sketch classpath jars loaded.");
|
||||
if (Base.isMacOS()) {
|
||||
File f = new File(System.getProperty("java.home") + File.separator + "bundle"
|
||||
+ File.separator + "Classes" + File.separator + "classes.jar");
|
||||
log(f.getAbsolutePath() + " | classes.jar found?"
|
||||
+ f.exists());
|
||||
} else {
|
||||
File f = new File(System.getProperty("java.home") + File.separator
|
||||
+ "lib" + File.separator + "rt.jar" + File.separator);
|
||||
log(f.getAbsolutePath() + " | rt.jar found?"
|
||||
+ f.exists());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (errorCheckerService.classpathJars != null) {
|
||||
synchronized (errorCheckerService.classpathJars) {
|
||||
for (URL jarPath : errorCheckerService.classpathJars) {
|
||||
//log(jarPath.getPath());
|
||||
tehPath.append(jarPath.getPath() + File.pathSeparatorChar);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
classPath = factory.createFromPath(tehPath.toString());
|
||||
log("Classpath created " + (classPath != null));
|
||||
log("Sketch classpath jars loaded.");
|
||||
if (Base.isMacOS()) {
|
||||
File f = new File(System.getProperty("java.home") + File.separator + "bundle"
|
||||
+ File.separator + "Classes" + File.separator + "classes.jar");
|
||||
log(f.getAbsolutePath() + " | classes.jar found?"
|
||||
+ f.exists());
|
||||
} else {
|
||||
File f = new File(System.getProperty("java.home") + File.separator
|
||||
+ "lib" + File.separator + "rt.jar" + File.separator);
|
||||
log(f.getAbsolutePath() + " | rt.jar found?"
|
||||
+ f.exists());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected TreeMap<String, String> jdocMap;
|
||||
|
||||
protected void loadJavaDoc() {
|
||||
jdocMap = new TreeMap<String, String>();
|
||||
|
||||
// presently loading only p5 reference for PApplet
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
JavadocHelper.loadJavaDoc(jdocMap, editor.getMode().getReferenceFolder());
|
||||
try {
|
||||
loadJavaDoc(jdocMap, editor.getMode().getReferenceFolder());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
static void loadJavaDoc(TreeMap<String, String> jdocMap,
|
||||
File referenceFolder) throws IOException, MalformedURLException {
|
||||
Document doc;
|
||||
|
||||
FileFilter fileFilter = new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if(!file.getName().endsWith("_.html"))
|
||||
return false;
|
||||
int k = 0;
|
||||
for (int i = 0; i < file.getName().length(); i++) {
|
||||
if(file.getName().charAt(i)== '_')
|
||||
k++;
|
||||
if(k > 1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
for (File docFile : referenceFolder.listFiles(fileFilter)) {
|
||||
doc = Jsoup.parse(docFile, null);
|
||||
Elements elm = doc.getElementsByClass("ref-item");
|
||||
String msg = "";
|
||||
String methodName = docFile.getName().substring(0, docFile.getName().indexOf('_'));
|
||||
//System.out.println(methodName);
|
||||
for (Iterator<org.jsoup.nodes.Element> it = elm.iterator(); it.hasNext();) {
|
||||
org.jsoup.nodes.Element ele = it.next();
|
||||
msg = "<html><body> <strong><div style=\"width: 300px; text-justification: justify;\"></strong><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"ref-item\">"
|
||||
+ ele.html() + "</table></div></html></body></html>";
|
||||
//mat.replaceAll("");
|
||||
msg = msg.replaceAll("img src=\"", "img src=\""
|
||||
+ referenceFolder.toURI().toURL().toString() + "/");
|
||||
//System.out.println(ele.text());
|
||||
}
|
||||
jdocMap.put(methodName, msg);
|
||||
}
|
||||
System.out.println("JDoc loaded "+jdocMap.size());
|
||||
}
|
||||
|
||||
|
||||
public DefaultMutableTreeNode buildAST(CompilationUnit cu) {
|
||||
return buildAST(errorCheckerService.sourceCode, cu);
|
||||
}
|
||||
@@ -817,16 +776,16 @@ public class ASTGenerator {
|
||||
* @param line
|
||||
* @param lineStartNonWSOffset
|
||||
*/
|
||||
public void preparePredictions(final String word, final int line, final int lineStartNonWSOffset) {
|
||||
if(predictionOngoing.get()) return;
|
||||
|
||||
public void preparePredictions(final String word, final int line,
|
||||
final int lineStartNonWSOffset) {
|
||||
if (predictionOngoing.get()) return;
|
||||
if (!JavaMode.codeCompletionsEnabled) return;
|
||||
if (word.length() < predictionMinLength) return;
|
||||
|
||||
predictionOngoing.set(true);
|
||||
// This method is called from TextArea.fetchPhrase, which is called via a SwingWorker instance
|
||||
// in TextArea.processKeyEvent
|
||||
if(caretWithinLineComment()){
|
||||
if (caretWithinLineComment()) {
|
||||
log("No predictions.");
|
||||
predictionOngoing.set(false);
|
||||
return;
|
||||
@@ -874,8 +833,7 @@ public class ASTGenerator {
|
||||
// Adjust line number for tabbed sketches
|
||||
if (errorCheckerService != null) {
|
||||
editor = errorCheckerService.getEditor();
|
||||
int codeIndex = editor.getSketch().getCodeIndex(editor
|
||||
.getCurrentTab());
|
||||
int codeIndex = editor.getSketch().getCodeIndex(editor.getCurrentTab());
|
||||
if (codeIndex > 0)
|
||||
for (int i = 0; i < codeIndex; i++) {
|
||||
SketchCode sc = editor.getSketch().getCode(i);
|
||||
@@ -940,21 +898,19 @@ public class ASTGenerator {
|
||||
// definitions.
|
||||
if (nearestNode instanceof TypeDeclaration) {
|
||||
TypeDeclaration td = (TypeDeclaration) nearestNode;
|
||||
if (td
|
||||
.getStructuralProperty(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) != null) {
|
||||
SimpleType st = (SimpleType) td
|
||||
.getStructuralProperty(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY);
|
||||
if (td.getStructuralProperty(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) != null) {
|
||||
SimpleType st = (SimpleType) td.getStructuralProperty(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY);
|
||||
log("Superclass " + st.getName());
|
||||
for (CompletionCandidate can : getMembersForType(st.getName()
|
||||
.toString(), word2, noCompare, false)) {
|
||||
ArrayList<CompletionCandidate> candidates =
|
||||
getMembersForType(st.getName().toString(), word2, noCompare, false);
|
||||
for (CompletionCandidate can : candidates) {
|
||||
candidates.add(can);
|
||||
}
|
||||
//findDeclaration(st.getName())
|
||||
|
||||
}
|
||||
}
|
||||
List<StructuralPropertyDescriptor> sprops = nearestNode
|
||||
.structuralPropertiesForType();
|
||||
List<StructuralPropertyDescriptor> sprops =
|
||||
nearestNode.structuralPropertiesForType();
|
||||
for (StructuralPropertyDescriptor sprop : sprops) {
|
||||
ASTNode cnode = null;
|
||||
if (!sprop.isChildListProperty()) {
|
||||
@@ -970,8 +926,8 @@ public class ASTGenerator {
|
||||
}
|
||||
} else {
|
||||
// Childlist prop
|
||||
List<ASTNode> nodelist = (List<ASTNode>) nearestNode
|
||||
.getStructuralProperty(sprop);
|
||||
List<ASTNode> nodelist = (List<ASTNode>)
|
||||
nearestNode.getStructuralProperty(sprop);
|
||||
for (ASTNode clnode : nodelist) {
|
||||
CompletionCandidate[] types = checkForTypes(clnode);
|
||||
if (types != null) {
|
||||
@@ -990,19 +946,13 @@ public class ASTGenerator {
|
||||
log("Empty can. " + word2);
|
||||
if (classPath != null) {
|
||||
RegExpResourceFilter regExpResourceFilter;
|
||||
regExpResourceFilter = new RegExpResourceFilter(
|
||||
Pattern
|
||||
.compile(".*"),
|
||||
Pattern
|
||||
.compile(word2
|
||||
+ "[a-zA-Z_0-9]*.class",
|
||||
Pattern.CASE_INSENSITIVE));
|
||||
String[] resources = classPath.findResources("",
|
||||
regExpResourceFilter);
|
||||
regExpResourceFilter = new RegExpResourceFilter(Pattern.compile(".*"),
|
||||
Pattern.compile(word2 + "[a-zA-Z_0-9]*.class",
|
||||
Pattern.CASE_INSENSITIVE));
|
||||
String[] resources = classPath.findResources("", regExpResourceFilter);
|
||||
for (String matchedClass2 : resources) {
|
||||
matchedClass2 = matchedClass2.replace('/', '.'); //package name
|
||||
String matchedClass = matchedClass2.substring(0, matchedClass2
|
||||
.length() - 6);
|
||||
String matchedClass = matchedClass2.substring(0, matchedClass2.length() - 6);
|
||||
int d = matchedClass.lastIndexOf('.');
|
||||
if (ignorableImport(matchedClass2,matchedClass.substring(d + 1)))
|
||||
continue;
|
||||
@@ -1853,50 +1803,50 @@ public class ASTGenerator {
|
||||
return ((CompilationUnit) node.getRoot()).getLineNumber(pos);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//traversal2();
|
||||
}
|
||||
|
||||
public static void traversal2() {
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS4);
|
||||
String source = readFile("/media/quarkninja/Work/TestStuff/low.java");
|
||||
// String source = "package decl; \npublic class ABC{\n int ret(){\n}\n}";
|
||||
parser.setSource(source.toCharArray());
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
|
||||
parser.setCompilerOptions(options);
|
||||
|
||||
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
log(CompilationUnit.propertyDescriptors(AST.JLS4).size());
|
||||
|
||||
DefaultMutableTreeNode astTree = new DefaultMutableTreeNode("CompilationUnit");
|
||||
Base.loge("Errors: " + cu.getProblems().length);
|
||||
visitRecur(cu, astTree);
|
||||
Base.log("" + astTree.getChildCount());
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
JFrame frame2 = new JFrame();
|
||||
JTree jtree = new JTree(astTree);
|
||||
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame2.setBounds(new Rectangle(100, 100, 460, 620));
|
||||
JScrollPane sp = new JScrollPane();
|
||||
sp.setViewportView(jtree);
|
||||
frame2.add(sp);
|
||||
frame2.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ASTNode found = NodeFinder.perform(cu, 468, 5);
|
||||
if (found != null) {
|
||||
Base.log(found.toString());
|
||||
}
|
||||
}
|
||||
// public static void main(String[] args) {
|
||||
// traversal2();
|
||||
// }
|
||||
//
|
||||
// public static void traversal2() {
|
||||
// ASTParser parser = ASTParser.newParser(AST.JLS4);
|
||||
// String source = readFile("/media/quarkninja/Work/TestStuff/low.java");
|
||||
//// String source = "package decl; \npublic class ABC{\n int ret(){\n}\n}";
|
||||
// parser.setSource(source.toCharArray());
|
||||
// parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
//
|
||||
// Map<String, String> options = JavaCore.getOptions();
|
||||
//
|
||||
// JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
|
||||
// options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
|
||||
// parser.setCompilerOptions(options);
|
||||
//
|
||||
// CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
// log(CompilationUnit.propertyDescriptors(AST.JLS4).size());
|
||||
//
|
||||
// DefaultMutableTreeNode astTree = new DefaultMutableTreeNode("CompilationUnit");
|
||||
// Base.loge("Errors: " + cu.getProblems().length);
|
||||
// visitRecur(cu, astTree);
|
||||
// Base.log("" + astTree.getChildCount());
|
||||
//
|
||||
// try {
|
||||
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
// JFrame frame2 = new JFrame();
|
||||
// JTree jtree = new JTree(astTree);
|
||||
// frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
// frame2.setBounds(new Rectangle(100, 100, 460, 620));
|
||||
// JScrollPane sp = new JScrollPane();
|
||||
// sp.setViewportView(jtree);
|
||||
// frame2.add(sp);
|
||||
// frame2.setVisible(true);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// ASTNode found = NodeFinder.perform(cu, 468, 5);
|
||||
// if (found != null) {
|
||||
// Base.log(found.toString());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
final ASTGenerator thisASTGenerator = this;
|
||||
@@ -1999,7 +1949,7 @@ public class ASTGenerator {
|
||||
}
|
||||
});
|
||||
|
||||
treeRename.addTreeSelectionListener(new TreeSelectionListener() {
|
||||
refactorTree.addTreeSelectionListener(new TreeSelectionListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
@@ -2012,11 +1962,11 @@ public class ASTGenerator {
|
||||
}
|
||||
|
||||
protected void done() {
|
||||
if(treeRename
|
||||
if(refactorTree
|
||||
.getLastSelectedPathComponent() == null){
|
||||
return;
|
||||
}
|
||||
DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) treeRename
|
||||
DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) refactorTree
|
||||
.getLastSelectedPathComponent();
|
||||
|
||||
if (tnode.getUserObject() instanceof ASTNodeWrapper) {
|
||||
@@ -2053,9 +2003,9 @@ public class ASTGenerator {
|
||||
//else log("New name looks K.");
|
||||
|
||||
errorCheckerService.pauseThread();
|
||||
if(treeRename.isVisible()){
|
||||
treeRename.setModel(new DefaultTreeModel(defCU));
|
||||
((DefaultTreeModel) treeRename.getModel()).reload();
|
||||
if(refactorTree.isVisible()){
|
||||
refactorTree.setModel(new DefaultTreeModel(defCU));
|
||||
((DefaultTreeModel) refactorTree.getModel()).reload();
|
||||
}
|
||||
// frmOccurenceList.setTitle("Usage of \"" + selText + "\" : "
|
||||
// + defCU.getChildCount() + " time(s)");
|
||||
@@ -2156,9 +2106,9 @@ public class ASTGenerator {
|
||||
}
|
||||
if(defCU.getChildCount() == 0)
|
||||
return;
|
||||
treeRename.setModel(new DefaultTreeModel(defCU));
|
||||
((DefaultTreeModel) treeRename.getModel()).reload();
|
||||
treeRename.setRootVisible(false);
|
||||
refactorTree.setModel(new DefaultTreeModel(defCU));
|
||||
((DefaultTreeModel) refactorTree.getModel()).reload();
|
||||
refactorTree.setRootVisible(false);
|
||||
frmOccurenceList.setTitle("Usage of \"" + selText + "\" : "
|
||||
+ defCU.getChildCount() + " time(s)");
|
||||
frmOccurenceList.setLocation(editor.getX() + editor.getWidth(),editor.getY());
|
||||
@@ -3729,41 +3679,41 @@ public class ASTGenerator {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void jdocWindowVisible(boolean visible) {
|
||||
// frmJavaDoc.setVisible(visible);
|
||||
}
|
||||
// public void jdocWindowVisible(boolean visible) {
|
||||
// // frmJavaDoc.setVisible(visible);
|
||||
// }
|
||||
|
||||
public static String readFile(String path) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(
|
||||
new File(
|
||||
path))));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
// ret.append("package " + className + ";\n");
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
ret.append(line);
|
||||
ret.append("\n");
|
||||
}
|
||||
return ret.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// public static String readFile2(String path) {
|
||||
// BufferedReader reader = null;
|
||||
// try {
|
||||
// reader = new BufferedReader(
|
||||
// new InputStreamReader(
|
||||
// new FileInputStream(
|
||||
// new File(
|
||||
// path))));
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// StringBuilder ret = new StringBuilder();
|
||||
// // ret.append("package " + className + ";\n");
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// ret.append(line);
|
||||
// ret.append("\n");
|
||||
// }
|
||||
// return ret.toString();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// try {
|
||||
// reader.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
static private void log(Object object) {
|
||||
|
||||
@@ -66,7 +66,7 @@ import processing.mode.java.preproc.PdePreprocessor;
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ErrorCheckerService implements Runnable {
|
||||
|
||||
|
||||
protected JavaEditor editor;
|
||||
|
||||
/** Error check happens every sleepTime milliseconds */
|
||||
@@ -74,7 +74,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
|
||||
/** The amazing eclipse ast parser */
|
||||
protected ASTParser parser;
|
||||
|
||||
|
||||
/**
|
||||
* Used to indirectly stop the Error Checker Thread
|
||||
*/
|
||||
@@ -124,7 +124,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
* Fixed p5 offsets for all sketches
|
||||
*/
|
||||
public int defaultImportsOffset;
|
||||
|
||||
|
||||
/**
|
||||
* Is the sketch running in static mode or active mode?
|
||||
*/
|
||||
@@ -133,17 +133,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
/**
|
||||
* Compilation Unit for current sketch
|
||||
*/
|
||||
protected CompilationUnit cu;
|
||||
|
||||
protected CompilationUnit cu;
|
||||
|
||||
/**
|
||||
* The Compilation Unit generated during compile check
|
||||
*/
|
||||
protected CompilationUnit compileCheckCU;
|
||||
|
||||
|
||||
/**
|
||||
* This Compilation Unit points to the last error free CU
|
||||
*/
|
||||
protected CompilationUnit lastCorrectCU;
|
||||
protected CompilationUnit lastCorrectCU;
|
||||
|
||||
/**
|
||||
* If true, compilation checker will be reloaded with updated classpath
|
||||
@@ -162,7 +162,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
*/
|
||||
protected CompilationChecker compilationChecker;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* List of jar files to be present in compilation checker's classpath
|
||||
*/
|
||||
@@ -207,7 +207,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
* Regexp for import statements. (Used from Processing source)
|
||||
*/
|
||||
final public String importRegexp = "(?:^|;)\\s*(import\\s+)((?:static\\s+)?\\S+)(\\s*;)";
|
||||
|
||||
|
||||
/**
|
||||
* Regexp for function declarations. (Used from Processing source)
|
||||
*/
|
||||
@@ -215,23 +215,23 @@ public class ErrorCheckerService implements Runnable {
|
||||
.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*"
|
||||
+ "(void|int|float|double|String|char|byte|boolean)"
|
||||
+ "(\\s*\\[\\s*\\])?\\s+[a-zA-Z0-9]+\\s*\\(", Pattern.MULTILINE);
|
||||
|
||||
|
||||
protected ErrorMessageSimplifier errorMsgSimplifier;
|
||||
|
||||
|
||||
public ErrorCheckerService(JavaEditor debugEditor) {
|
||||
ensureMinP5Version();
|
||||
this.editor = debugEditor;
|
||||
stopThread = new AtomicBoolean(false);
|
||||
pauseThread = new AtomicBoolean(false);
|
||||
|
||||
|
||||
problemsList = new ArrayList<Problem>();
|
||||
classpathJars = new ArrayList<URL>();
|
||||
|
||||
|
||||
initParser();
|
||||
//initializeErrorWindow();
|
||||
xqpreproc = new XQPreprocessor();
|
||||
PdePreprocessor pdePrepoc = new PdePreprocessor(null);
|
||||
defaultImportsOffset = pdePrepoc.getCoreImports().length +
|
||||
defaultImportsOffset = pdePrepoc.getCoreImports().length +
|
||||
pdePrepoc.getDefaultImports().length + 1;
|
||||
astGenerator = new ASTGenerator(this);
|
||||
syntaxErrors = new AtomicBoolean(true);
|
||||
@@ -243,7 +243,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
// sc.getDocument().addDocumentListener(sketchChangedListener);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes ASTParser
|
||||
*/
|
||||
@@ -260,16 +260,16 @@ public class ErrorCheckerService implements Runnable {
|
||||
pauseThread();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialiazes the Error Window
|
||||
*/
|
||||
/*public void initializeErrorWindow() {
|
||||
|
||||
|
||||
if (editor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (errorWindow != null) {
|
||||
return;
|
||||
}
|
||||
@@ -290,7 +290,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* Ensure user is running the minimum P5 version
|
||||
*/
|
||||
@@ -302,17 +302,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
Base.showWarning("Error", "ERROR: PDE X requires Processing 2.1.2 or higher.", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Error checking doesn't happen before this interval has ellapsed since the
|
||||
* last runManualErrorCheck() call.
|
||||
*/
|
||||
private final static long errorCheckInterval = 500;
|
||||
|
||||
|
||||
/**
|
||||
* Bypass sleep time
|
||||
*/
|
||||
|
||||
|
||||
private volatile boolean noSleep = false;
|
||||
|
||||
/**
|
||||
@@ -320,22 +320,22 @@ public class ErrorCheckerService implements Runnable {
|
||||
* to each SketchCode object. Whenever the document is edited, runManualErrorCheck()
|
||||
* is called. Internally, an atomic integer counter is incremented.
|
||||
* The ECS thread checks the value of this counter evey sleepTime seconds.
|
||||
* If the counter is non zero, error checking is done(in the ECS thread)
|
||||
* If the counter is non zero, error checking is done(in the ECS thread)
|
||||
* and the counter is reset.
|
||||
*/
|
||||
public void run() {
|
||||
stopThread.set(false);
|
||||
|
||||
|
||||
checkCode();
|
||||
lastErrorCheckCall = System.currentTimeMillis();
|
||||
|
||||
|
||||
if(!hasSyntaxErrors())
|
||||
editor.showProblemListView(XQConsoleToggle.CONSOLE);
|
||||
// Make sure astGen has at least one CU to start with
|
||||
// This is when the loaded sketch already has syntax errors.
|
||||
// Completion wouldn't be complete, but it'd be still something
|
||||
// better than nothing
|
||||
astGenerator.buildAST(cu);
|
||||
astGenerator.buildAST(cu);
|
||||
handleErrorCheckingToggle();
|
||||
while (!stopThread.get()) {
|
||||
try {
|
||||
@@ -351,7 +351,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
Base.log("Oops! [ErrorCheckerThreaded]: " + e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
updatePaintedThingys();
|
||||
updateEditorStatus();
|
||||
updateSketchCodeListeners();
|
||||
@@ -367,7 +367,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
checkForMissingImports();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
astGenerator.disposeAllWindows();
|
||||
compilationChecker = null;
|
||||
checkerClass = null;
|
||||
@@ -376,8 +376,8 @@ public class ErrorCheckerService implements Runnable {
|
||||
Base.loge("Thread stopped: " + editor.getSketch().getName());
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected void updateSketchCodeListeners() {
|
||||
for (final SketchCode sc : editor.getSketch().getCode()) {
|
||||
boolean flag = false;
|
||||
@@ -397,12 +397,12 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void checkForMissingImports() {
|
||||
if (JavaMode.importSuggestEnabled) {
|
||||
for (Problem p : problemsList) {
|
||||
if(p.getIProblem().getID() == IProblem.UndefinedType) {
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
Base.log("Will suggest for type:" + missingClass);
|
||||
@@ -413,14 +413,14 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected ASTGenerator astGenerator;
|
||||
|
||||
|
||||
public ASTGenerator getASTGenerator() {
|
||||
return astGenerator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This thing acts as an event queue counter of sort.
|
||||
* Since error checking happens on demand, anytime this counter
|
||||
@@ -428,14 +428,14 @@ public class ErrorCheckerService implements Runnable {
|
||||
* It's thread safe to avoid any mess.
|
||||
*/
|
||||
protected AtomicInteger textModified = new AtomicInteger();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Time stamp of last runManualErrorCheck() call.
|
||||
*/
|
||||
private volatile long lastErrorCheckCall = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Triggers error check
|
||||
*/
|
||||
@@ -444,17 +444,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
textModified.incrementAndGet();
|
||||
lastErrorCheckCall = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: Experimental, lookout for threading related issues
|
||||
public void quickErrorCheck() {
|
||||
noSleep = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected SketchChangedListener sketchChangedListener;
|
||||
protected class SketchChangedListener implements DocumentListener{
|
||||
|
||||
|
||||
private SketchChangedListener(){
|
||||
}
|
||||
|
||||
@@ -481,15 +481,15 @@ public class ErrorCheckerService implements Runnable {
|
||||
//log("doc changed update, man error check..");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* state = 1 > syntax check done<br>
|
||||
* state = 2 > compilation check done
|
||||
*/
|
||||
public int compilationUnitState = 0;
|
||||
|
||||
|
||||
protected boolean checkCode() {
|
||||
// log("checkCode() " + textModified.get());
|
||||
lastTimeStamp = System.currentTimeMillis();
|
||||
@@ -499,14 +499,14 @@ public class ErrorCheckerService implements Runnable {
|
||||
syntaxCheck();
|
||||
// log(editor.getSketch().getName() + "1 MCO " + mainClassOffset);
|
||||
// No syntax errors, proceed for compilation check, Stage 2.
|
||||
|
||||
|
||||
//if(hasSyntaxErrors()) astGenerator.buildAST(null);
|
||||
if (!hasSyntaxErrors()) {
|
||||
|
||||
|
||||
}
|
||||
if (problems.length == 0 && !editor.hasJavaTabs()) {
|
||||
//mainClassOffset++; // just a hack.
|
||||
|
||||
|
||||
sourceCode = xqpreproc.doYourThing(sourceCode, programImports);
|
||||
prepareCompilerClasspath();
|
||||
// mainClassOffset = xqpreproc.mainClassOffset; // tiny, but
|
||||
@@ -516,10 +516,10 @@ public class ErrorCheckerService implements Runnable {
|
||||
// }
|
||||
// log(sourceCode);
|
||||
// log("--------------------------");
|
||||
compileCheck();
|
||||
compileCheck();
|
||||
// log(editor.getSketch().getName() + "2 MCO " + mainClassOffset);
|
||||
}
|
||||
|
||||
|
||||
astGenerator.buildAST(cu);
|
||||
if (!JavaMode.errorCheckEnabled) {
|
||||
problemsList.clear();
|
||||
@@ -532,7 +532,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
editor.getTextArea().repaint();
|
||||
updatePaintedThingys();
|
||||
editor.updateErrorToggle();
|
||||
|
||||
|
||||
int x = textModified.get();
|
||||
//log("TM " + x);
|
||||
if (x >= 2) {
|
||||
@@ -552,17 +552,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected AtomicBoolean syntaxErrors, containsErrors;
|
||||
|
||||
|
||||
public boolean hasSyntaxErrors(){
|
||||
return syntaxErrors.get();
|
||||
}
|
||||
|
||||
|
||||
public boolean hasErrors(){
|
||||
return containsErrors.get();
|
||||
}
|
||||
|
||||
|
||||
public TreeMap<String, IProblem> tempErrorLog;
|
||||
|
||||
protected void syntaxCheck() {
|
||||
@@ -577,7 +577,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
|
||||
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
|
||||
parser.setCompilerOptions(options);
|
||||
|
||||
|
||||
if (cu == null)
|
||||
cu = (CompilationUnit) parser.createAST(null);
|
||||
else {
|
||||
@@ -587,7 +587,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
compilationUnitState = 1;
|
||||
synchronized (problemsList) {
|
||||
|
||||
|
||||
// Store errors returned by the ast parser
|
||||
problems = cu.getProblems();
|
||||
// log("Problem Count: " + problems.length);
|
||||
@@ -608,24 +608,24 @@ public class ErrorCheckerService implements Runnable {
|
||||
syntaxErrors.set(false);
|
||||
containsErrors.set(false);
|
||||
parser.setSource(sourceCode.toCharArray());
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
parser.setCompilerOptions(options);
|
||||
lastCorrectCU = (CompilationUnit) parser.createAST(null);
|
||||
lastCorrectCU = (CompilationUnit) parser.createAST(null);
|
||||
} else {
|
||||
syntaxErrors.set(true);
|
||||
containsErrors.set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected URLClassLoader classLoader;
|
||||
|
||||
|
||||
protected void compileCheck() {
|
||||
|
||||
// CU needs to be updated coz before compileCheck xqpreprocessor is run on
|
||||
|
||||
// CU needs to be updated coz before compileCheck xqpreprocessor is run on
|
||||
// the source code which makes some further changes
|
||||
//TODO Check if this breaks things
|
||||
|
||||
//TODO Check if this breaks things
|
||||
|
||||
parser.setSource(sourceCode.toCharArray());
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
|
||||
@@ -635,7 +635,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
|
||||
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
|
||||
parser.setCompilerOptions(options);
|
||||
|
||||
|
||||
if (compileCheckCU == null)
|
||||
compileCheckCU = (CompilationUnit) parser.createAST(null);
|
||||
else {
|
||||
@@ -646,7 +646,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
if(!hasSyntaxErrors())
|
||||
lastCorrectCU = compileCheckCU;
|
||||
cu = compileCheckCU;
|
||||
|
||||
|
||||
compilationUnitState = 2;
|
||||
// Currently (Sept, 2012) I'm using Java's reflection api to load the
|
||||
// CompilationChecker class(from CompilationChecker.jar) that houses the
|
||||
@@ -664,25 +664,25 @@ public class ErrorCheckerService implements Runnable {
|
||||
// If imports have changed, reload classes with new classpath.
|
||||
if (loadCompClass) {
|
||||
|
||||
classpath = new URL[classpathJars.size()];
|
||||
classpath = new URL[classpathJars.size()];
|
||||
int ii = 0;
|
||||
for (; ii < classpathJars.size(); ii++) {
|
||||
classpath[ii] = classpathJars.get(ii);
|
||||
}
|
||||
|
||||
|
||||
compilationChecker = null;
|
||||
classLoader = null;
|
||||
System.gc();
|
||||
// log("CP Len -- " + classpath.length);
|
||||
classLoader = new URLClassLoader(classpath);
|
||||
compilationChecker = new CompilationChecker();
|
||||
compilationChecker = new CompilationChecker();
|
||||
loadCompClass = false;
|
||||
}
|
||||
|
||||
if (compilerSettings == null) {
|
||||
prepareCompilerSetting();
|
||||
}
|
||||
|
||||
|
||||
synchronized (problemsList) {
|
||||
problems = compilationChecker.getErrors(className, sourceCode, compilerSettings, classLoader);
|
||||
if (problems == null) {
|
||||
@@ -690,24 +690,24 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
for (int i = 0; i < problems.length; i++) {
|
||||
|
||||
|
||||
IProblem problem = problems[i];
|
||||
|
||||
// added a -1 to line number because in compile check code
|
||||
// an extra package statement is added, so all line numbers
|
||||
// are increased by 1
|
||||
int a[] = calculateTabIndexAndLineNumber(problem.getSourceLineNumber() - 1);
|
||||
|
||||
|
||||
Problem p = new Problem(problem, a[0], a[1]);
|
||||
if (problem.isError()) {
|
||||
p.setType(Problem.ERROR);
|
||||
containsErrors.set(true); // set flag
|
||||
}
|
||||
|
||||
|
||||
if (problem.isWarning()) {
|
||||
p.setType(Problem.WARNING);
|
||||
}
|
||||
|
||||
|
||||
// If warnings are disabled, skip 'em
|
||||
if (p.isWarning() && !JavaMode.warningsEnabled) {
|
||||
continue;
|
||||
@@ -716,7 +716,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
catch (Exception e) {
|
||||
System.err.println("compileCheck() problem." + e);
|
||||
e.printStackTrace();
|
||||
@@ -731,15 +731,15 @@ public class ErrorCheckerService implements Runnable {
|
||||
" windows and then reopen this sketch.");
|
||||
pauseThread();
|
||||
}
|
||||
|
||||
|
||||
// log("Compilecheck, Done.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates PDE Offsets from Java Offsets for Problems
|
||||
*/
|
||||
private void calcPDEOffsetsForProbList() {
|
||||
try {
|
||||
try {
|
||||
PlainDocument javaSource = new PlainDocument();
|
||||
// Code in pde tabs stored as PlainDocument
|
||||
PlainDocument pdeTabs[] = new PlainDocument[editor.getSketch()
|
||||
@@ -766,7 +766,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
int pkgNameOffset = ("package " + className + ";\n").length();
|
||||
// package name is added only during compile check
|
||||
if(compilationUnitState != 2) pkgNameOffset = 0;
|
||||
|
||||
|
||||
for (Problem p : problemsList) {
|
||||
int prbStart = p.getIProblem().getSourceStart() - pkgNameOffset, prbEnd = p
|
||||
.getIProblem().getSourceEnd() - pkgNameOffset;
|
||||
@@ -785,7 +785,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
String javaLine = javaSource
|
||||
.getText(lineElement.getStartOffset(), lineElement.getEndOffset()
|
||||
- lineElement.getStartOffset());
|
||||
|
||||
|
||||
Element pdeLineElement = pdeTabs[p.getTabIndex()]
|
||||
.getDefaultRootElement().getElement(p.getLineNumber());
|
||||
if (pdeLineElement == null) {
|
||||
@@ -813,15 +813,15 @@ public class ErrorCheckerService implements Runnable {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CompilationUnit getLastCorrectCU(){
|
||||
return lastCorrectCU;
|
||||
}
|
||||
|
||||
|
||||
public CompilationUnit getLatestCU(){
|
||||
return compileCheckCU;
|
||||
}
|
||||
|
||||
|
||||
private int loadClassCounter = 0;
|
||||
public URLClassLoader getSketchClassLoader() {
|
||||
loadClassCounter++;
|
||||
@@ -839,13 +839,13 @@ public class ErrorCheckerService implements Runnable {
|
||||
* libraries. This would be needed for compilation check. Also, adds
|
||||
* stuff(jar files, class files, candy) from the code folder. And it looks
|
||||
* messed up.
|
||||
*
|
||||
*
|
||||
*/
|
||||
protected void prepareCompilerClasspath() {
|
||||
if (!loadCompClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
synchronized (classpathJars) {
|
||||
// log("1..");
|
||||
classpathJars = new ArrayList<URL>();
|
||||
@@ -855,7 +855,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
String item = impstat.getImportName();
|
||||
int dot = item.lastIndexOf('.');
|
||||
entry = (dot == -1) ? item : item.substring(0, dot);
|
||||
|
||||
|
||||
entry = entry.substring(6).trim();
|
||||
// log("Entry--" + entry);
|
||||
if (ignorableImport(entry)) {
|
||||
@@ -863,7 +863,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
continue;
|
||||
}
|
||||
Library library = null;
|
||||
|
||||
|
||||
// Try to get the library classpath and add it to the list
|
||||
try {
|
||||
library = editor.getMode().getLibrary(entry);
|
||||
@@ -886,7 +886,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
// Look around in the code folder for jar files
|
||||
if (editor.getSketch().hasCodeFolder()) {
|
||||
File codeFolder = editor.getSketch().getCodeFolder();
|
||||
|
||||
|
||||
// get a list of .jar files in the "code" folder
|
||||
// (class files in subfolders should also be picked up)
|
||||
String codeFolderClassPath = Base
|
||||
@@ -903,7 +903,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
System.out
|
||||
.println("Please make sure that the library is present in <sketchbook "
|
||||
+ "folder>/libraries folder or in the code folder of your sketch");
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
String codeFolderPath[] = PApplet.split(
|
||||
@@ -914,7 +914,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
classpathJars.add(new File(codeFolderPath[i])
|
||||
.toURI().toURL());
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e2) {
|
||||
System.out
|
||||
.println("Yikes! codefolder, prepareImports(): "
|
||||
@@ -933,25 +933,30 @@ public class ErrorCheckerService implements Runnable {
|
||||
.println("Please make sure that the library is present in <sketchbook "
|
||||
+ "folder>/libraries folder or in the code folder of your sketch");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
System.err
|
||||
.println("Yikes! There was some problem in prepareImports(): "
|
||||
+ e);
|
||||
System.err.println("I was processing: " + entry);
|
||||
|
||||
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
astGenerator.loadJars(); // update jar file for completion lookup
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
astGenerator.loadJars(); // update jar file for completion lookup
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Ignore processing packages, java.*.*. etc.
|
||||
*
|
||||
*
|
||||
* @param packageName
|
||||
* @return boolean
|
||||
*/
|
||||
@@ -992,7 +997,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
CompilerOptions.IGNORE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the error table in the Error Window.
|
||||
*/
|
||||
@@ -1012,11 +1017,11 @@ public class ErrorCheckerService implements Runnable {
|
||||
if (tempErrorLog.size() < 200)
|
||||
tempErrorLog.put(problemsList.get(i).getMessage(), problemsList
|
||||
.get(i).getIProblem());
|
||||
|
||||
|
||||
if (JavaMode.importSuggestEnabled) {
|
||||
Problem p = problemsList.get(i);
|
||||
if(p.getIProblem().getID() == IProblem.UndefinedType) {
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
// log("Will suggest for type:" + missingClass);
|
||||
@@ -1034,16 +1039,16 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
DefaultTableModel tm =
|
||||
DefaultTableModel tm =
|
||||
new DefaultTableModel(errorData, XQErrorTable.columnNames);
|
||||
editor.updateTable(tm);
|
||||
|
||||
|
||||
/*
|
||||
if (errorWindow != null) {
|
||||
if (errorWindow.isVisible()) {
|
||||
errorWindow.updateTable(tm);
|
||||
}
|
||||
|
||||
|
||||
// A rotating slash animation on the title bar to show
|
||||
// that error checker thread is running
|
||||
|
||||
@@ -1068,9 +1073,9 @@ public class ErrorCheckerService implements Runnable {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Repaints the textarea if required */
|
||||
public void updatePaintedThingys() {
|
||||
public void updatePaintedThingys() {
|
||||
currentTab = editor.getSketch().getCodeIndex(
|
||||
editor.getSketch().getCurrentCode());
|
||||
//log("Tab changed " + currentTab + " LT " + lastTab);
|
||||
@@ -1083,17 +1088,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected int lastCaretLine = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Updates editor status bar, depending on whether the caret is on an error
|
||||
* line or not
|
||||
*/
|
||||
public void updateEditorStatus() {
|
||||
if (editor.getStatusMode() == EditorStatus.EDIT) return;
|
||||
|
||||
|
||||
// editor.statusNotice("Position: " +
|
||||
// editor.getTextArea().getCaretLine());
|
||||
if (JavaMode.errorCheckEnabled) {
|
||||
@@ -1101,7 +1106,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
for (ErrorMarker emarker : editor.getErrorPoints()) {
|
||||
if (emarker.getProblem().getLineNumber() == editor.getTextArea().getCaretLine()) {
|
||||
if (emarker.getType() == ErrorMarker.Warning) {
|
||||
editor.statusMessage(emarker.getProblem().getMessage(),
|
||||
editor.statusMessage(emarker.getProblem().getMessage(),
|
||||
JavaEditor.STATUS_INFO);
|
||||
} else {
|
||||
editor.statusMessage(emarker.getProblem().getMessage(),
|
||||
@@ -1112,7 +1117,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This line isn't an error line anymore, so probably just clear it
|
||||
if (editor.statusMessageType == JavaEditor.STATUS_COMPILER_ERR) {
|
||||
editor.statusEmpty();
|
||||
@@ -1124,10 +1129,10 @@ public class ErrorCheckerService implements Runnable {
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Maps offset from java code to pde code. Returns a bunch of offsets as array
|
||||
*
|
||||
*
|
||||
* @param line
|
||||
* - line number in java code
|
||||
* @param offset
|
||||
@@ -1207,17 +1212,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
return new int[] { codeIndex, x };
|
||||
}
|
||||
|
||||
|
||||
public String getPDECodeAtLine(int tab, int linenumber){
|
||||
if(linenumber < 0) return null;
|
||||
editor.getSketch().setCurrentCode(tab);
|
||||
return editor.getTextArea().getLineText(linenumber);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the tab number and line number of the error in that particular
|
||||
* tab. Provides mapping between pure java and pde code.
|
||||
*
|
||||
*
|
||||
* @param problem
|
||||
* - IProblem
|
||||
* @return int[0] - tab number, int[1] - line number
|
||||
@@ -1295,7 +1300,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
|
||||
return new int[] { codeIndex, x };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns line number of corresponding java source
|
||||
* @param tab
|
||||
@@ -1321,17 +1326,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
* color representation<li>Converts all 'color' datatypes to int
|
||||
* (experimental) <li>Appends class declaration statement after determining
|
||||
* the mode the sketch is in - ACTIVE or STATIC
|
||||
*
|
||||
*
|
||||
* @return String - Pure java representation of PDE code. Note that this
|
||||
* code is not yet compile ready.
|
||||
*/
|
||||
*/
|
||||
|
||||
protected String preprocessCode(String pdeCode) {
|
||||
|
||||
|
||||
programImports = new ArrayList<ImportStatement>();
|
||||
|
||||
|
||||
StringBuilder rawCode = new StringBuilder();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
for (SketchCode sc : editor.getSketch().getCode()) {
|
||||
@@ -1417,7 +1422,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
className = (editor == null) ? "DefaultClass" : editor.getSketch()
|
||||
.getName();
|
||||
|
||||
|
||||
|
||||
// Check whether the code is being written in STATIC mode(no function
|
||||
// declarations) - append class declaration and void setup() declaration
|
||||
Matcher matcher = FUNCTION_DECL.matcher(sourceAlt);
|
||||
@@ -1425,14 +1430,14 @@ public class ErrorCheckerService implements Runnable {
|
||||
sourceAlt = xqpreproc.prepareImports(programImports) + "public class " + className + " extends PApplet {\n"
|
||||
+ "public void setup() {\n" + sourceAlt
|
||||
+ "\nnoLoop();\n}\n" + "\n}\n";
|
||||
staticMode = true;
|
||||
staticMode = true;
|
||||
|
||||
} else {
|
||||
sourceAlt = xqpreproc.prepareImports(programImports) + "public class " + className + " extends PApplet {\n"
|
||||
+ sourceAlt + "\n}";
|
||||
staticMode = false;
|
||||
staticMode = false;
|
||||
}
|
||||
|
||||
|
||||
int position = sourceAlt.indexOf("{") + 1;
|
||||
mainClassOffset = 1;
|
||||
for (int i = 0; i <= position; i++) {
|
||||
@@ -1451,10 +1456,10 @@ public class ErrorCheckerService implements Runnable {
|
||||
// log("PDE code processed - "
|
||||
// + editor.getSketch().getName());
|
||||
sourceCode = sourceAlt;
|
||||
return sourceAlt;
|
||||
return sourceAlt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Now defunct.
|
||||
* The super method that highlights any ASTNode in the pde editor =D
|
||||
@@ -1479,16 +1484,16 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean highlightNode(ASTNode node){
|
||||
ASTNodeWrapper awrap = new ASTNodeWrapper(node);
|
||||
return highlightNode(awrap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scrolls to the error source in code. And selects the line text. Used by
|
||||
* XQErrorTable and ErrorBar
|
||||
*
|
||||
*
|
||||
* @param errorIndex
|
||||
* - index of error
|
||||
*/
|
||||
@@ -1496,13 +1501,13 @@ public class ErrorCheckerService implements Runnable {
|
||||
if (editor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (errorIndex < problemsList.size() && errorIndex >= 0) {
|
||||
Problem p = problemsList.get(errorIndex);
|
||||
scrollToErrorLine(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void scrollToErrorLine(Problem p) {
|
||||
if (editor == null) {
|
||||
return;
|
||||
@@ -1522,7 +1527,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
(p.getPDELineStopOffset()
|
||||
- p.getPDELineStartOffset() + 1));
|
||||
}
|
||||
|
||||
|
||||
// scroll, but within boundaries
|
||||
// It's also a bit silly that if parameters to scrollTo() are out of range,
|
||||
// a BadLocation Exception is thrown internally and caught in JTextArea AND
|
||||
@@ -1533,17 +1538,17 @@ public class ErrorCheckerService implements Runnable {
|
||||
editor.getTextArea().scrollTo(p.getLineNumber(), 0);
|
||||
}
|
||||
editor.repaint();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Base.loge("Error while selecting text in scrollToErrorLine(), for problem: " + p, e);
|
||||
}
|
||||
// log("---");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static method for scroll to a particular line in the PDE. Also highlights
|
||||
* the length of the text. Requires the editor instance as arguement.
|
||||
*
|
||||
*
|
||||
* @param edt
|
||||
* @param tabIndex
|
||||
* @param lineNoInTab
|
||||
@@ -1567,7 +1572,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
edt.getTextArea().scrollTo(lineNoInTab - 1, 0);
|
||||
edt.repaint();
|
||||
Base.log(lineStartOffset + " LSO,len " + length);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println(e
|
||||
+ " : Error while selecting text in static scrollToErrorLine()");
|
||||
@@ -1576,7 +1581,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if import statements in the sketch have changed. If they have,
|
||||
* compiler classpath needs to be updated.
|
||||
@@ -1604,7 +1609,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
protected int pdeImportsCount;
|
||||
|
||||
|
||||
public int getPdeImportsCount() {
|
||||
return pdeImportsCount;
|
||||
}
|
||||
@@ -1612,7 +1617,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
/**
|
||||
* Removes import statements from tabSource, replaces each with white spaces
|
||||
* and adds the import to the list of program imports
|
||||
*
|
||||
*
|
||||
* @param tabProgram
|
||||
* - Code in a tab
|
||||
* @param tabNumber
|
||||
@@ -1663,7 +1668,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
* Replaces non-ascii characters with their unicode escape sequences and
|
||||
* stuff. Used as it is from
|
||||
* processing.src.processing.mode.java.preproc.PdePreprocessor
|
||||
*
|
||||
*
|
||||
* @param program
|
||||
* - Input String containing non ascii characters
|
||||
* @return String - Converted String
|
||||
@@ -1706,7 +1711,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
return new String(p2, 0, index);
|
||||
}
|
||||
|
||||
|
||||
public void handleErrorCheckingToggle(){
|
||||
if (!JavaMode.errorCheckEnabled) {
|
||||
// unticked Menu Item
|
||||
@@ -1726,7 +1731,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
runManualErrorCheck();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stops the Error Checker Service thread
|
||||
*/
|
||||
@@ -1752,12 +1757,12 @@ public class ErrorCheckerService implements Runnable {
|
||||
public JavaEditor getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
// public static void log(String message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// log(message);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void log2(String message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// System.out.print(message);
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Copyright (c) 2012-15 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class JavadocHelper {
|
||||
|
||||
public static void loadJavaDoc(TreeMap<String, String> jdocMap, File p5Ref){
|
||||
Document doc;
|
||||
|
||||
//Pattern pat = Pattern.compile("\\w+");
|
||||
try {
|
||||
if (p5Ref == null) {
|
||||
System.out.println("P5 Ref location null");
|
||||
p5Ref = new File(
|
||||
"/home/quarkninja/Workspaces/processing-workspace/processing/build/linux/work/modes/java/reference");
|
||||
}
|
||||
|
||||
FileFilter fileFilter = new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if(!file.getName().endsWith("_.html"))
|
||||
return false;
|
||||
int k = 0;
|
||||
for (int i = 0; i < file.getName().length(); i++) {
|
||||
if(file.getName().charAt(i)== '_')
|
||||
k++;
|
||||
if(k > 1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
for (File docFile : p5Ref.listFiles(fileFilter)) {
|
||||
|
||||
doc = Jsoup.parse(docFile, null);
|
||||
Elements elm = doc.getElementsByClass("ref-item");
|
||||
String msg = "";
|
||||
String methodName = docFile.getName().substring(0, docFile.getName().indexOf('_'));
|
||||
//System.out.println(methodName);
|
||||
for (Iterator<Element> it = elm.iterator(); it.hasNext();) {
|
||||
Element ele = it.next();
|
||||
msg = "<html><body> <strong><div style=\"width: 300px; text-justification: justify;\"></strong><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"ref-item\">"
|
||||
+ ele.html() + "</table></div></html></body></html>";
|
||||
//mat.replaceAll("");
|
||||
msg = msg.replaceAll("img src=\"", "img src=\""
|
||||
+ p5Ref.toURI().toURL().toString() + "/");
|
||||
//System.out.println(ele.text());
|
||||
}
|
||||
jdocMap.put(methodName, msg);
|
||||
}
|
||||
System.out.println("JDoc loaded "+jdocMap.size());
|
||||
/* File javaDocFile = new File(
|
||||
"/home/quarkninja/Workspaces/processing-workspace/processing/build/javadoc/core/processing/core/PApplet.html");
|
||||
//SimpleOpenNI.SimpleOpenNI
|
||||
doc = Jsoup.parse(javaDocFile, null);
|
||||
|
||||
String msg = "";
|
||||
Elements elm = doc.getElementsByTag("pre");
|
||||
// Elements desc = doc.getElementsByTag("dl");
|
||||
//System.out.println(elm.toString());
|
||||
|
||||
for (Iterator iterator = elm.iterator(); iterator.hasNext();) {
|
||||
Element element = (Element) iterator.next();
|
||||
|
||||
//System.out.println(element.text());
|
||||
// if (element.nextElementSibling() != null)
|
||||
// System.out.println(element.nextElementSibling().text());
|
||||
//System.out.println("-------------------");
|
||||
msg = "<html><body> <strong><div style=\"width: 300px; text-justification: justify;\"></strong>"
|
||||
+ element.html()
|
||||
+ element.nextElementSibling()
|
||||
+ "</div></html></body></html>";
|
||||
int k = 0;
|
||||
Matcher matcher = pat.matcher(element.text());
|
||||
ArrayList<String> parts = new ArrayList<String>();
|
||||
while (matcher.find()) {
|
||||
// System.out.print("Start index: " + matcher.start());
|
||||
// System.out.print(" End index: " + matcher.end() + " ");
|
||||
if (k == 0 && !matcher.group().equals("public")) {
|
||||
k = -1;
|
||||
break;
|
||||
}
|
||||
// System.out.print(matcher.group() + " ");
|
||||
parts.add(matcher.group());
|
||||
k++;
|
||||
}
|
||||
if (k <= 0 || parts.size() < 3)
|
||||
continue;
|
||||
int i = 0;
|
||||
if (parts.get(i).equals("public"))
|
||||
i++;
|
||||
if (parts.get(i).equals("static") || parts.get(i).equals("final")
|
||||
|| parts.get(i).equals("class"))
|
||||
i++;
|
||||
if (parts.get(i).equals("static") || parts.get(i).equals("final"))
|
||||
i++;
|
||||
// System.out.println("Ret Type " + parts.get(i));
|
||||
|
||||
i++; // return type
|
||||
|
||||
//System.out.println("Name " + parts.get(i));
|
||||
jdocMap.put(parts.get(i), msg);
|
||||
}
|
||||
|
||||
// for (String key : jdocMap.keySet()) {
|
||||
// System.out.println("Method: " + key);
|
||||
// System.out.println("Method: " + jdocMap.get(key));
|
||||
// }
|
||||
*
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user