From 1345f77f93e8ec4dd0be4a272b69a4e1ee09334f Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Fri, 30 Oct 2015 03:03:58 +0100 Subject: [PATCH 1/3] Workaround for JRE bug freezing the PDE Because of a JRE bug, code completion will occasionally freeze the PDE. Never seen this one before, however, it happened to me three times in a row while I was giving a lecture today and I had to kill the PDE and write all the code again. I can reproduce it back to beta 7. It is caused by JIT compiler, workaround is to disable it for this particular method. See https://bugs.openjdk.java.net/browse/JDK-8060036 and http://kingsfleet.blogspot.com.br/2014/11/but-thats-impossible-or-finding-out.html --- build/windows/config.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/windows/config.xml b/build/windows/config.xml index 90c290121..cca6bebb6 100644 --- a/build/windows/config.xml +++ b/build/windows/config.xml @@ -43,6 +43,10 @@ -Djna.nounpack=true 1.8.0_51 + + -XX:CompileCommand=exclude,javax/swing/text/GlyphView,getBreakSpot 256 From a1eb3473380dbb49586a8482640e8d6dd7440eb7 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Fri, 30 Oct 2015 03:27:08 +0100 Subject: [PATCH 2/3] Make CompletionCandidate immutable This one goes from ASTGenerator on a background thread to the JList which displays code suggestions. Until refactored, I'm making it immutable with convenience methods returning mutated copies to prevent possible threading issues. --- .../mode/java/pdex/ASTGenerator.java | 22 +++++----- .../mode/java/pdex/CompletionCandidate.java | 42 ++++++++++++------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/java/src/processing/mode/java/pdex/ASTGenerator.java b/java/src/processing/mode/java/pdex/ASTGenerator.java index 5368765e6..bc2bdef70 100644 --- a/java/src/processing/mode/java/pdex/ASTGenerator.java +++ b/java/src/processing/mode/java/pdex/ASTGenerator.java @@ -1015,9 +1015,10 @@ public class ASTGenerator { if (candidates.get(0).getElementName() .equals(candidates.get(candidates.size() - 1).getElementName())) { log("All CC are methods only: " + candidates.get(0).getElementName()); - for (CompletionCandidate candidate : candidates) { - candidate.regenerateCompletionString(); - defListModel.addElement(candidate); + for (int i = 0; i < candidates.size(); i++) { + CompletionCandidate cc = candidates.get(i).withRegeneratedCompString(); + candidates.set(i, cc); + defListModel.addElement(cc); } } else { @@ -1030,14 +1031,15 @@ public class ASTGenerator { CompletionCandidate cc = candidates.get(i - 1); String label = cc.getLabel(); int x = label.lastIndexOf(')'); - if(candidates.get(i).getType() == CompletionCandidate.PREDEF_METHOD) { - cc.setLabel((cc.getLabel().contains("") ? "" : "") - + cc.getElementName() + "(...)" + label.substring(x + 1)); + String newLabel; + if (candidates.get(i).getType() == CompletionCandidate.PREDEF_METHOD) { + newLabel = (cc.getLabel().contains("") ? "" : "") + + cc.getElementName() + "(...)" + label.substring(x + 1); + } else { + newLabel = cc.getElementName() + "(...)" + label.substring(x + 1); } - else { - cc.setLabel(cc.getElementName() + "(...)" + label.substring(x + 1)); - } - cc.setCompletionString(cc.getElementName() + "("); + String newCompString = cc.getElementName() + "("; + candidates.set(i - 1, cc.withLabelAndCompString(newLabel, newCompString)); ignoredSome = true; continue; } diff --git a/java/src/processing/mode/java/pdex/CompletionCandidate.java b/java/src/processing/mode/java/pdex/CompletionCandidate.java index 2a9d9f936..ca48ab15d 100644 --- a/java/src/processing/mode/java/pdex/CompletionCandidate.java +++ b/java/src/processing/mode/java/pdex/CompletionCandidate.java @@ -33,11 +33,11 @@ import org.eclipse.jdt.core.dom.VariableDeclarationFragment; public class CompletionCandidate implements Comparable{ - private String elementName; - private String label; // the toString value - private String completionString; - private Object wrappedObject; - private int type; + private final String elementName; + private final String label; // the toString value + private final String completionString; + private final Object wrappedObject; + private final int type; static final int PREDEF_CLASS = 0; static final int PREDEF_FIELD = 1; @@ -158,6 +158,7 @@ public class CompletionCandidate implements Comparable{ label = labelStr; completionString = completionStr; this.type = type; + wrappedObject = null; } public CompletionCandidate(String name, int type) { @@ -165,6 +166,17 @@ public class CompletionCandidate implements Comparable{ label = name; completionString = name; this.type = type; + wrappedObject = null; + } + + private CompletionCandidate(String elementName, String label, + String completionString, int type, + Object wrappedObject) { + this.elementName = elementName; + this.label = label; + this.completionString = completionString; + this.type = type; + this.wrappedObject = wrappedObject; } public String getElementName() { @@ -204,14 +216,13 @@ public class CompletionCandidate implements Comparable{ } } - public void setLabel(String label) { - this.label = label; - } - - public void setCompletionString(String completionString) { - this.completionString = completionString; + public CompletionCandidate withLabelAndCompString(String label, + String completionString) { + return new CompletionCandidate(this.elementName, label, completionString, + this.type, this.wrappedObject); } + @Override public int compareTo(CompletionCandidate cc) { if(type != cc.getType()){ return cc.getType() - type; @@ -219,7 +230,7 @@ public class CompletionCandidate implements Comparable{ return (elementName.compareTo(cc.getElementName())); } - public void regenerateCompletionString(){ + public CompletionCandidate withRegeneratedCompString() { if (wrappedObject instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration)wrappedObject; @@ -243,8 +254,7 @@ public class CompletionCandidate implements Comparable{ if (method.getReturnType2() != null) label.append(" : " + method.getReturnType2()); cstr.append(")"); - this.label = label.toString(); - this.completionString = cstr.toString(); + return this.withLabelAndCompString(label.toString(), cstr.toString()); } else if (wrappedObject instanceof Method) { Method method = (Method)wrappedObject; @@ -265,8 +275,7 @@ public class CompletionCandidate implements Comparable{ label.append(" : " + method.getReturnType().getSimpleName()); label.append(" - " + method.getDeclaringClass().getSimpleName() + ""); cstr.append(")"); - this.label = label.toString(); - this.completionString = cstr.toString(); + return this.withLabelAndCompString(label.toString(), cstr.toString()); /* * StringBuilder label = new StringBuilder(""+method.getName() + "("); StringBuilder cstr = new StringBuilder(method.getName() + "("); @@ -286,6 +295,7 @@ public class CompletionCandidate implements Comparable{ label.append(" - " + method.getDeclaringClass().getSimpleName() + ""); * */ } + return this; } } From c3222348e1148ad7a6aaba39a1b9004c1ac7090e Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Fri, 30 Oct 2015 03:30:37 +0100 Subject: [PATCH 3/3] Styling --- build/windows/config.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/windows/config.xml b/build/windows/config.xml index cca6bebb6..8add550ee 100644 --- a/build/windows/config.xml +++ b/build/windows/config.xml @@ -43,10 +43,10 @@ -Djna.nounpack=true 1.8.0_51 - - -XX:CompileCommand=exclude,javax/swing/text/GlyphView,getBreakSpot + + -XX:CompileCommand=exclude,javax/swing/text/GlyphView,getBreakSpot 256