diff --git a/app/src/processing/app/Library.java b/app/src/processing/app/Library.java index 3c9fcf257..69966b637 100644 --- a/app/src/processing/app/Library.java +++ b/app/src/processing/app/Library.java @@ -256,7 +256,7 @@ public class Library extends LocalContribution { * @param importToLibraryTable mapping from package names to Library objects */ // public void addPackageList(HashMap importToLibraryTable) { - public void addPackageList(HashMap> importToLibraryTable) { + public void addPackageList(Map> importToLibraryTable) { // PApplet.println(packages); for (String pkg : packageList) { // pw.println(pkg + "\t" + libraryFolder.getAbsolutePath()); diff --git a/app/src/processing/app/Mode.java b/app/src/processing/app/Mode.java index 376ab4a94..6dc13581f 100644 --- a/app/src/processing/app/Mode.java +++ b/app/src/processing/app/Mode.java @@ -54,7 +54,7 @@ public abstract class Mode { protected File folder; protected TokenMarker tokenMarker; - protected HashMap keywordToReference = + protected Map keywordToReference = new HashMap(); protected Settings theme; @@ -62,8 +62,7 @@ public abstract class Mode { // protected Tool formatter; // maps imported packages to their library folder -// protected HashMap importToLibraryTable; - protected HashMap> importToLibraryTable; + protected Map> importToLibraryTable; // these menus are shared so that they needn't be rebuilt for all windows // each time a sketch is created, renamed, or moved. @@ -321,6 +320,11 @@ public abstract class Mode { // reset the table mapping imports to libraries importToLibraryTable = new HashMap>(); + Library core = getCoreLibrary(); + if (core != null) { + core.addPackageList(importToLibraryTable); + } + coreLibraries = Library.list(librariesFolder); for (Library lib : coreLibraries) { lib.addPackageList(importToLibraryTable); @@ -342,7 +346,7 @@ public abstract class Mode { public Library getLibrary(String pkgName) throws SketchException { - ArrayList libraries = importToLibraryTable.get(pkgName); + List libraries = importToLibraryTable.get(pkgName); if (libraries == null) { return null; diff --git a/java/src/processing/mode/java/pdex/ASTGenerator.java b/java/src/processing/mode/java/pdex/ASTGenerator.java index 028d60048..2c04dd1c1 100644 --- a/java/src/processing/mode/java/pdex/ASTGenerator.java +++ b/java/src/processing/mode/java/pdex/ASTGenerator.java @@ -1210,7 +1210,7 @@ public class ASTGenerator { int res[] = errorCheckerService .calculateTabIndexAndLineNumber(javaLineNumber); if (res != null) { - return errorCheckerService.getPDECodeAtLine(res[0], res[1]); + return errorCheckerService.getPdeCodeAtLine(res[0], res[1]); } return null; } @@ -1657,7 +1657,7 @@ public class ASTGenerator { // Obtain correspondin java code at that line, match offsets if (lineNode != null) { - String pdeCodeLine = errorCheckerService.getPDECodeAtLine(editor + String pdeCodeLine = errorCheckerService.getPdeCodeAtLine(editor .getSketch().getCurrentCodeIndex(), lineNumber); String javaCodeLine = getJavaSourceCodeLine(pdeLineNumber); @@ -3301,15 +3301,13 @@ public class ASTGenerator { } log("Looking for class " + className); - RegExpResourceFilter regf = new RegExpResourceFilter( - Pattern.compile(".*"), - Pattern - .compile(className - + ".class", - Pattern.CASE_INSENSITIVE)); - String[] resources = classPath - .findResources("", regf); - ArrayList candidates = new ArrayList(); + RegExpResourceFilter regf = + new RegExpResourceFilter(Pattern.compile(".*"), + Pattern.compile(className + ".class", + Pattern.CASE_INSENSITIVE)); + // TODO once saw NPE here...possible for classPath to be null? [fry 150808] + String[] resources = classPath.findResources("", regf); + List candidates = new ArrayList(); for (String res : resources) { candidates.add(res); } diff --git a/java/src/processing/mode/java/pdex/ASTNodeWrapper.java b/java/src/processing/mode/java/pdex/ASTNodeWrapper.java index c5fb22845..4c6b3053e 100644 --- a/java/src/processing/mode/java/pdex/ASTNodeWrapper.java +++ b/java/src/processing/mode/java/pdex/ASTNodeWrapper.java @@ -195,7 +195,7 @@ public class ASTNodeWrapper { } int pdeoffsets[] = getPDECodeOffsets(ecs); - String pdeCode = ecs.getPDECodeAtLine(pdeoffsets[0],pdeoffsets[1] - 1).trim(); + String pdeCode = ecs.getPdeCodeAtLine(pdeoffsets[0],pdeoffsets[1] - 1).trim(); int vals[] = createOffsetMapping(ecs, pdeCode,nodeOffset - altStartPos,nodeLength); if (vals != null) return new int[] { @@ -635,7 +635,7 @@ public class ASTNodeWrapper { */ public int[][] getOffsetMapping(ErrorCheckerService ecs){ int pdeoffsets[] = getPDECodeOffsets(ecs); - String pdeCode = ecs.getPDECodeAtLine(pdeoffsets[0],pdeoffsets[1] - 1).trim(); + String pdeCode = ecs.getPdeCodeAtLine(pdeoffsets[0],pdeoffsets[1] - 1).trim(); return getOffsetMapping(ecs, pdeCode); } diff --git a/java/src/processing/mode/java/pdex/ErrorCheckerService.java b/java/src/processing/mode/java/pdex/ErrorCheckerService.java index c7ecc2473..ed87a5b44 100644 --- a/java/src/processing/mode/java/pdex/ErrorCheckerService.java +++ b/java/src/processing/mode/java/pdex/ErrorCheckerService.java @@ -51,6 +51,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import processing.app.Base; import processing.app.Library; +import processing.app.Sketch; import processing.app.SketchCode; import processing.app.Util; import processing.app.syntax.SyntaxDocument; @@ -529,7 +530,7 @@ public class ErrorCheckerService implements Runnable { problemsList.clear(); Base.log("Error Check disabled, so not updating UI."); } - calcPDEOffsetsForProbList(); + calcPdeOffsetsForProbList(); updateErrorTable(); editor.updateErrorBar(problemsList); updateEditorStatus(); @@ -625,7 +626,6 @@ public class ErrorCheckerService implements Runnable { protected URLClassLoader classLoader; protected void compileCheck() { - // 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 @@ -640,15 +640,16 @@ public class ErrorCheckerService implements Runnable { options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(options); - if (compileCheckCU == null) + if (compileCheckCU == null) { compileCheckCU = (CompilationUnit) parser.createAST(null); - else { + } else { synchronized (compileCheckCU) { - compileCheckCU = (CompilationUnit) parser.createAST(null); + compileCheckCU = (CompilationUnit) parser.createAST(null); } } - if(!hasSyntaxErrors()) + if (!hasSyntaxErrors()) { lastCorrectCU = compileCheckCU; + } cu = compileCheckCU; compilationUnitState = 2; @@ -661,17 +662,12 @@ public class ErrorCheckerService implements Runnable { // a better method, do let me know. try { - // NOTE TO SELF: If classpath contains null Strings // URLClassLoader shoots NPE bullets. // If imports have changed, reload classes with new classpath. if (loadCompClass) { classPath = new URL[classpathJars.size()]; -// int ii = 0; -// for (; ii < classpathJars.size(); ii++) { -// classPath[ii] = classpathJars.get(ii); -// } classpathJars.toArray(classPath); compilationChecker = null; @@ -738,7 +734,7 @@ public class ErrorCheckerService implements Runnable { /** * Calculates PDE Offsets from Java Offsets for Problems */ - private void calcPDEOffsetsForProbList() { + private void calcPdeOffsetsForProbList() { try { PlainDocument javaSource = new PlainDocument(); @@ -757,15 +753,22 @@ public class ErrorCheckerService implements Runnable { } int pkgNameOffset = ("package " + className + ";\n").length(); // package name is added only during compile check - if(compilationUnitState != 2) pkgNameOffset = 0; + if (compilationUnitState != 2) { + pkgNameOffset = 0; + } for (Problem p : problemsList) { int prbStart = p.getIProblem().getSourceStart() - pkgNameOffset; int prbEnd = p.getIProblem().getSourceEnd() - pkgNameOffset; int javaLineNumber = p.getSourceLineNumber() - 1; + // not sure if this is necessary [fry 150808] if (compilationUnitState == 2) { javaLineNumber--; } + // errors on the first line were setting this to -1 [fry 150808] + if (javaLineNumber < 0) { + javaLineNumber = 0; + } Element lineElement = javaSource.getDefaultRootElement().getElement(javaLineNumber); if (lineElement == null) { @@ -958,38 +961,34 @@ public class ErrorCheckerService implements Runnable { public void updateErrorTable() { try { String[][] errorData = new String[problemsList.size()][3]; - for (int i = 0; i < problemsList.size(); i++) { - errorData[i][0] = problemsList.get(i).getMessage(); ////TODO: this is temporary - //+ " : " + errorMsgSimplifier.getIDName(problemsList.get(i).getIProblem().getID()); - errorData[i][1] = editor.getSketch() - .getCode(problemsList.get(i).getTabIndex()).getPrettyName(); - errorData[i][2] = (problemsList.get(i).getLineNumber() + 1) + ""; + int index = 0; +// for (int i = 0; i < problemsList.size(); i++) { + for (Problem p : problemsList) { + errorData[index][0] = p.getMessage(); + errorData[index][1] = editor.getSketch().getCode(p.getTabIndex()).getPrettyName(); + errorData[index][2] = Integer.toString(p.getLineNumber() + 1); // Added +1 because lineNumbers internally are 0-indexed - //TODO: This is temporary - if (tempErrorLog.size() < 200) - tempErrorLog.put(problemsList.get(i).getMessage(), problemsList - .get(i).getIProblem()); +// //TODO: This is temporary +// if (tempErrorLog.size() < 200) { +// tempErrorLog.put(p.getMessage(), p.getIProblem()); +// } if (JavaMode.importSuggestEnabled) { - Problem p = problemsList.get(i); - if(p.getIProblem().getID() == IProblem.UndefinedType) { - String args[] = p.getIProblem().getArguments(); + if (p.getIProblem().getID() == IProblem.UndefinedType) { + String[] args = p.getIProblem().getArguments(); if (args.length > 0) { String missingClass = args[0]; - // log("Will suggest for type:" + missingClass); - //astGenerator.suggestImports(missingClass); String[] si = astGenerator.getSuggestImports(missingClass); - if(si != null && si.length > 0){ + if (si != null && si.length > 0) { p.setImportSuggestions(si); - errorData[i][0] = "" - + problemsList.get(i).getMessage() - + " (Import Suggestions available)"; + errorData[index][0] = "" + p.getMessage() + + " (Import Suggestions available)"; } - } } } + index++; } DefaultTableModel tm = @@ -997,7 +996,7 @@ public class ErrorCheckerService implements Runnable { editor.updateTable(tm); } catch (Exception e) { - Base.log("Exception at updateErrorTable() " + e); + Base.loge("Exception at updateErrorTable()", e); e.printStackTrace(); pauseThread(); } @@ -1005,18 +1004,16 @@ public class ErrorCheckerService implements Runnable { /** Repaints the textarea if required */ - public void updatePaintedThingys() { - currentTab = editor.getSketch().getCodeIndex( - editor.getSketch().getCurrentCode()); + private void updatePaintedThingys() { +// currentTab = editor.getSketch().getCodeIndex(editor.getSketch().getCurrentCode()); + currentTab = editor.getSketch().getCurrentCodeIndex(); //log("Tab changed " + currentTab + " LT " + lastTab); if (currentTab != lastTab) { textModified.set(5); lastTab = currentTab; editor.getTextArea().repaint(); editor.statusEmpty(); - return; } - } @@ -1026,7 +1023,7 @@ public class ErrorCheckerService implements Runnable { * Updates editor status bar, depending on whether the caret is on an error * line or not */ - public void updateEditorStatus() { + private void updateEditorStatus() { if (editor.getStatusMode() == EditorStatus.EDIT) return; // editor.statusNotice("Position: " + @@ -1071,7 +1068,7 @@ public class ErrorCheckerService implements Runnable { * - line start offset, int[3] - offset from line start. int[2] and * int[3] are on TODO */ - public int[] JavaToPdeOffsets(int line, int offset){ + protected int[] JavaToPdeOffsets(int line, int offset) { int codeIndex = 0; int x = line - mainClassOffset; @@ -1136,18 +1133,20 @@ public class ErrorCheckerService implements Runnable { } } } catch (Exception e) { - System.err - .println("Things got messed up in ErrorCheckerService.JavaToPdeOffset()"); + System.err.println("Error inside ErrorCheckerService.JavaToPdeOffset()"); + e.printStackTrace(); } return new int[] { codeIndex, x }; } - public String getPDECodeAtLine(int tab, int linenumber){ + + protected 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. @@ -1156,7 +1155,7 @@ public class ErrorCheckerService implements Runnable { * - IProblem * @return int[0] - tab number, int[1] - line number */ - public int[] calculateTabIndexAndLineNumber(int javalineNumber) { + protected int[] calculateTabIndexAndLineNumber(int javalineNumber) { // String[] lines = {};// = PApplet.split(sourceString, '\n'); int codeIndex = 0; @@ -1212,30 +1211,24 @@ public class ErrorCheckerService implements Runnable { codeIndex++; } } else { - if (codeIndex >= editor.getSketch().getCodeCount()) { codeIndex = editor.getSketch().getCodeCount() - 1; } break; } - } } } catch (Exception e) { - System.err - .println("Things got messed up in ErrorCheckerService.calculateTabIndexAndLineNumber()"); + System.err.println("Things got messed up in ErrorCheckerService.calculateTabIndexAndLineNumber()"); } - return new int[] { codeIndex, x }; } + /** * Returns line number of corresponding java source - * @param tab - * @param pdeLineNum - * @return */ - public int getJavaLineNumFromPDElineNum(int tab, int pdeLineNum){ + protected int getJavaLineNumFromPDElineNum(int tab, int pdeLineNum){ int jLineNum = programImports.size() + 1; for (int i = 0; i < tab; i++) { SketchCode sc = editor.getSketch().getCode(i); @@ -1245,6 +1238,7 @@ public class ErrorCheckerService implements Runnable { return jLineNum; } + /** * Fetches code from the editor tabs and pre-processes it into parsable pure * java source. And there's a difference between parsable and compilable. @@ -1258,38 +1252,26 @@ public class ErrorCheckerService implements Runnable { * @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(); - StringBuilder rawCode = new StringBuilder(); - + final Sketch sketch = editor.getSketch(); try { - - for (SketchCode sc : editor.getSketch().getCode()) { + for (SketchCode sc : sketch.getCode()) { if (sc.isExtension("pde")) { try { - - if (editor.getSketch().getCurrentCode().equals(sc)) { - - rawCode.append(scrapImportStatements(sc.getDocument() - .getText(0, - sc.getDocument() - .getLength()), - editor.getSketch() - .getCodeIndex(sc))); + if (sketch.getCurrentCode().equals(sc)) { + Document d = sc.getDocument(); + rawCode.append(scrapImportStatements(d.getText(0, d.getLength()), + sketch.getCodeIndex(sc))); } else { - - rawCode.append(scrapImportStatements(sc.getProgram(), editor - .getSketch().getCodeIndex(sc))); - + rawCode.append(scrapImportStatements(sc.getProgram(), + sketch.getCodeIndex(sc))); } rawCode.append('\n'); } catch (Exception e) { - System.err.println("Exception in preprocessCode() - bigCode " - + e.toString()); + e.printStackTrace(); } rawCode.append('\n'); } @@ -1347,24 +1329,25 @@ public class ErrorCheckerService implements Runnable { checkForChangedImports(); - className = (editor == null) ? "DefaultClass" : editor.getSketch() - .getName(); - + 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); - if (!matcher.find()) { - sourceAlt = xqpreproc.prepareImports(programImports) + "public class " + className + " extends PApplet {\n" - + "public void setup() {\n" + sourceAlt - + "\nnoLoop();\n}\n" + "\n}\n"; - staticMode = true; - - } else { - sourceAlt = xqpreproc.prepareImports(programImports) + "public class " + className + " extends PApplet {\n" - + sourceAlt + "\n}"; - staticMode = false; + staticMode = !matcher.find(); + StringBuilder sb = new StringBuilder(); + sb.append(xqpreproc.prepareImports(programImports)); + sb.append("public class " + className + " extends PApplet {\n"); + if (staticMode) { + sb.append("public void setup() {\n"); } + sb.append(sourceAlt); + if (staticMode) { + sb.append("\nnoLoop();\n}"); + } + sb.append("\n}"); + sourceAlt = sb.toString(); int position = sourceAlt.indexOf("{") + 1; mainClassOffset = 1; @@ -1373,21 +1356,15 @@ public class ErrorCheckerService implements Runnable { mainClassOffset++; } } - if(staticMode) { + if (staticMode) { mainClassOffset++; } - //mainClassOffset += 2; - // Handle unicode characters sourceAlt = substituteUnicode(sourceAlt); - -// log("-->\n" + sourceAlt + "\n<--"); -// log("PDE code processed - " -// + editor.getSketch().getName()); sourceCode = sourceAlt; return sourceAlt; - } + /** * Now defunct. * The super method that highlights any ASTNode in the pde editor =D diff --git a/todo.txt b/todo.txt index a3de020ca..ecf1c2950 100644 --- a/todo.txt +++ b/todo.txt @@ -3,10 +3,17 @@ X make download-jdk-macosx target work properly X remove "pair is" debug messages X create sketchbook subfolders on startup X https://github.com/processing/processing/issues/3548 +X Cannot find "processing.core" library. Line 12 in tab sketch_150704a +X also happens with "import to com.jogamp.opengl.GL2" +X https://github.com/processing/processing/issues/3547 + +export X save export settings to preferences X disable Export button when no platforms selected X prevent Export with examples and untitled/unsaved sketches - +X if no platforms selected in export, will still say "done exporting!" +X maybe if none selected, should default select the current platform +X why are none selected in the first place? not getting saved? earlier/cleaning X CM ongoing notes and questions @@ -22,11 +29,6 @@ _ but anything else reports "font sadness" b/c it's using the system JRE _ https://github.com/processing/processing/issues/3543 -_ if no platforms selected in export, will still say "done exporting!" -_ maybe if none selected, should default select the current platform -_ why are none selected in the first place? not getting saved? - - 3.0 final _ Contributions Manager UI design _ https://github.com/processing/processing/issues/3482 @@ -82,7 +84,6 @@ _ can't install processing-java into /usr/bin with El Capitan _ https://github.com/processing/processing/issues/3497 _ Foundation library examples should appear under "Core" or "Foundation" _ https://github.com/processing/processing/issues/3524 -_ Cannot find "processing.core" library. Line 12 in tab sketch_150704a _ dim out the Run button if there are compile errors detected _ the AST checker has better error message handling for those cases _ and hitting Run replaces the useful error with something weird