From 95e04cd45fe4e91bd49f97a252b130133792c42f 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 90c290121f..cca6bebb6d 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 28e3b4f99faa055c4d977c86a0e3a649567d1dfa 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 5368765e69..bc2bdef703 100644 --- a/java/src/processing/mode/java/pdex/ASTGenerator.java +++ b/java/src/processing/mode/java/pdex/ASTGenerator.java @@ -1015,9 +1015,10 @@ protected static DefaultListModel filterPredictions(List filterPredictions(List") ? "" : "") - + cc.getElementName() + "(...)" + label.substring(x + 1)); - } - else { - cc.setLabel(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); } - 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 2a9d9f9361..ca48ab15d0 100644 --- a/java/src/processing/mode/java/pdex/CompletionCandidate.java +++ b/java/src/processing/mode/java/pdex/CompletionCandidate.java @@ -33,11 +33,11 @@ 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 CompletionCandidate(String name, String labelStr, String completionStr, i label = labelStr; completionString = completionStr; this.type = type; + wrappedObject = null; } public CompletionCandidate(String name, int type) { @@ -165,6 +166,17 @@ public CompletionCandidate(String name, int type) { 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 String getNoHtmlLabel(){ } } - 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 int compareTo(CompletionCandidate cc) { return (elementName.compareTo(cc.getElementName())); } - public void regenerateCompletionString(){ + public CompletionCandidate withRegeneratedCompString() { if (wrappedObject instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration)wrappedObject; @@ -243,8 +254,7 @@ public void regenerateCompletionString(){ 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 @@ else if (wrappedObject instanceof Method) { 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 @@ else if (wrappedObject instanceof Method) { label.append(" - " + method.getDeclaringClass().getSimpleName() + ""); * */ } + return this; } } From 0516c558eb1f26313853ca5c276aa1a680ab11d0 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 cca6bebb6d..8add550ee6 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