Skip to content

Commit 7f940e4

Browse files
committed
deal with a few warnings and code cleanups
1 parent b52260a commit 7f940e4

File tree

1 file changed

+24
-62
lines changed

1 file changed

+24
-62
lines changed

java/src/processing/mode/java/CompletionGenerator.java

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,21 @@ public static CompletionCandidate[] checkForTypes(ASTNode node) {
112112
}
113113

114114
if (vdfs != null) {
115-
CompletionCandidate ret[] = new CompletionCandidate[vdfs.size()];
115+
CompletionCandidate[] outgoing = new CompletionCandidate[vdfs.size()];
116116
int i = 0;
117117
for (VariableDeclarationFragment vdf : vdfs) {
118118
// ret[i++] = new CompletionCandidate(getNodeAsString2(vdf), "", "",
119119
// CompletionCandidate.LOCAL_VAR);
120-
ret[i++] = new CompletionCandidate(vdf);
120+
outgoing[i++] = new CompletionCandidate(vdf);
121121
}
122-
return ret;
122+
return outgoing;
123123
}
124-
125124
return null;
126125
}
127126

128127
/**
129128
* Find the parent of the expression in a().b, this would give me the return
130-
* type of a(), so that we can find all children of a() begininng with b
131-
*
132-
* @param nearestNode
133-
* @param expression
134-
* @return
129+
* type of a(), so that we can find all children of a() beginning with b
135130
*/
136131
public static ASTNode resolveExpression(ASTNode nearestNode,
137132
ASTNode expression, boolean noCompare) {
@@ -191,9 +186,6 @@ public static ASTNode resolveExpression(ASTNode nearestNode,
191186
* Finds the type of the expression in foo.bar().a().b, this would give me the
192187
* type of b if it exists in return type of a(). If noCompare is true,
193188
* it'll return type of a()
194-
* @param nearestNode
195-
* @param astNode
196-
* @return
197189
*/
198190
public static ClassMember resolveExpression3rdParty(PreprocSketch ps, ASTNode nearestNode,
199191
ASTNode astNode, boolean noCompare) {
@@ -475,12 +467,8 @@ public static Class<?> getArrayClass(String elementClass, ClassLoader classLoade
475467

476468
/**
477469
* For a().abc.a123 this would return a123
478-
*
479-
* @param expression
480-
* @return
481470
*/
482-
public static ASTNode getChildExpression(ASTNode expression) {
483-
// ASTNode anode = null;
471+
static public ASTNode getChildExpression(ASTNode expression) {
484472
if (expression instanceof SimpleName) {
485473
return expression;
486474
} else if (expression instanceof FieldAccess) {
@@ -497,8 +485,7 @@ public static ASTNode getChildExpression(ASTNode expression) {
497485
return null;
498486
}
499487

500-
public static ASTNode getParentExpression(ASTNode expression) {
501-
// ASTNode anode = null;
488+
static public ASTNode getParentExpression(ASTNode expression) {
502489
if (expression instanceof SimpleName) {
503490
return expression;
504491
} else if (expression instanceof FieldAccess) {
@@ -518,18 +505,13 @@ public static ASTNode getParentExpression(ASTNode expression) {
518505

519506
/**
520507
* Loads classes from .jar files in sketch classpath
521-
*
522-
* @param typeName
523-
* @param child
524-
* @param noCompare
525-
* @return
526508
*/
527-
public static ArrayList<CompletionCandidate> getMembersForType(PreprocSketch ps,
509+
public static List<CompletionCandidate> getMembersForType(PreprocSketch ps,
528510
String typeName,
529511
String child,
530512
boolean noCompare,
531513
boolean staticOnly) {
532-
ArrayList<CompletionCandidate> candidates = new ArrayList<>();
514+
List<CompletionCandidate> candidates = new ArrayList<>();
533515
log("In GMFT(), Looking for match " + child
534516
+ " in class " + typeName + " noCompare " + noCompare + " staticOnly "
535517
+ staticOnly);
@@ -561,7 +543,7 @@ public static ArrayList<CompletionCandidate> getMembersForType(PreprocSketch ps,
561543
{
562544
FieldDeclaration[] fields = td.getFields();
563545
for (FieldDeclaration field : fields) {
564-
if (staticOnly && !isStatic(field.modifiers())) {
546+
if (staticOnly && notStatic(field.modifiers())) {
565547
continue;
566548
}
567549
List<VariableDeclarationFragment> vdfs = field.fragments();
@@ -576,7 +558,7 @@ public static ArrayList<CompletionCandidate> getMembersForType(PreprocSketch ps,
576558
{
577559
MethodDeclaration[] methods = td.getMethods();
578560
for (MethodDeclaration method : methods) {
579-
if (staticOnly && !isStatic(method.modifiers())) {
561+
if (staticOnly && notStatic(method.modifiers())) {
580562
continue;
581563
}
582564
if (noCompare) {
@@ -616,7 +598,7 @@ public static ArrayList<CompletionCandidate> getMembersForType(PreprocSketch ps,
616598
log("Couldn't find class " + tehClass.getTypeAsString());
617599
return candidates;
618600
}
619-
log("Loaded " + probableClass.toString());
601+
log("Loaded " + probableClass);
620602
}
621603
for (Method method : probableClass.getMethods()) {
622604
if (!Modifier.isStatic(method.getModifiers()) && staticOnly) {
@@ -668,19 +650,17 @@ public static ArrayList<CompletionCandidate> getMembersForType(PreprocSketch ps,
668650
return candidates;
669651
}
670652

671-
private static boolean isStatic(List<org.eclipse.jdt.core.dom.Modifier> modifiers) {
653+
private static boolean notStatic(List<org.eclipse.jdt.core.dom.Modifier> modifiers) {
672654
for (org.eclipse.jdt.core.dom.Modifier m : modifiers) {
673-
if (m.isStatic()) return true;
655+
if (m.isStatic()) return false;
674656
}
675-
return false;
657+
return true;
676658
}
677659

678660

679661
/**
680662
* Searches for the particular class in the default list of imports as well as
681663
* the Sketch classpath
682-
* @param className
683-
* @return
684664
*/
685665
protected static Class<?> findClassIfExists(PreprocSketch ps, String className){
686666
if (className == null){
@@ -903,8 +883,6 @@ protected static ASTNode findClosestNode(int lineNumber, ASTNode node) {
903883

904884
/**
905885
* Fetches line number of the node in its CompilationUnit.
906-
* @param node
907-
* @return
908886
*/
909887
public static int getLineNumber(ASTNode node) {
910888
return ((CompilationUnit) node.getRoot()).getLineNumber(node
@@ -933,9 +911,6 @@ public void showTabOutline() {
933911
* Give this thing a {@link Name} instance - a {@link SimpleName} from the
934912
* ASTNode for ex, and it tries its level best to locate its declaration in
935913
* the AST. It really does.
936-
*
937-
* @param findMe
938-
* @return
939914
*/
940915
protected static ASTNode findDeclaration(Name findMe) {
941916

@@ -1128,9 +1103,6 @@ protected static ASTNode findDeclaration(Name findMe) {
11281103

11291104
/**
11301105
* A variation of findDeclaration() but accepts an alternate parent ASTNode
1131-
* @param findMe
1132-
* @param alternateParent
1133-
* @return
11341106
*/
11351107
protected static ASTNode findDeclaration2(Name findMe, ASTNode alternateParent) {
11361108
ASTNode declaringClass;
@@ -1464,9 +1436,6 @@ public String getTypeAsString(){
14641436

14651437
/**
14661438
* Find the SimpleType from FD, SVD, VDS, etc
1467-
*
1468-
* @param node
1469-
* @return
14701439
*/
14711440
public static SimpleType extracTypeInfo(ASTNode node) {
14721441
if (node == null) {
@@ -1638,22 +1607,22 @@ else if (node instanceof MethodInvocation)
16381607
value = ((MethodInvocation) node).getName().toString() + " | "
16391608
+ className;
16401609
else if (node instanceof FieldDeclaration)
1641-
value = node.toString() + " FldDecl | ";
1610+
value = node + " FldDecl | ";
16421611
else if (node instanceof SingleVariableDeclaration)
16431612
value = ((SingleVariableDeclaration) node).getName() + " - "
16441613
+ ((SingleVariableDeclaration) node).getType() + " | SVD ";
16451614
else if (node instanceof ExpressionStatement)
1646-
value = node.toString() + className;
1615+
value = node + className;
16471616
else if (node instanceof SimpleName)
16481617
value = ((SimpleName) node).getFullyQualifiedName() + " | " + className;
16491618
else if (node instanceof QualifiedName)
1650-
value = node.toString() + " | " + className;
1619+
value = node + " | " + className;
16511620
else if(node instanceof FieldAccess)
1652-
value = node.toString() + " | ";
1621+
value = node + " | ";
16531622
else if (className.startsWith("Variable"))
1654-
value = node.toString() + " | " + className;
1623+
value = node + " | " + className;
16551624
else if (className.endsWith("Type"))
1656-
value = node.toString() + " | " + className;
1625+
value = node + " | " + className;
16571626
value += " [" + node.getStartPosition() + ","
16581627
+ (node.getStartPosition() + node.getLength()) + "]";
16591628
value += " Line: "
@@ -1725,10 +1694,6 @@ protected static List<CompletionCandidate> trimCandidates(String newWord, List<C
17251694

17261695
/**
17271696
* The main function that calculates possible code completion candidates
1728-
*
1729-
* @param pdePhrase
1730-
* @param line
1731-
* @param lineStartNonWSOffset
17321697
*/
17331698
public List<CompletionCandidate> preparePredictions(final PreprocSketch ps,
17341699
final String pdePhrase,
@@ -1829,16 +1794,13 @@ public List<CompletionCandidate> preparePredictions(final PreprocSketch ps,
18291794
if (td.getStructuralProperty(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) != null) {
18301795
SimpleType st = (SimpleType) td.getStructuralProperty(TypeDeclaration.SUPERCLASS_TYPE_PROPERTY);
18311796
log("Superclass " + st.getName());
1832-
ArrayList<CompletionCandidate> tempCandidates =
1797+
List<CompletionCandidate> tempCandidates =
18331798
getMembersForType(ps, st.getName().toString(), phrase, false, false);
1834-
for (CompletionCandidate can : tempCandidates) {
1835-
candidates.add(can);
1836-
}
1837-
//findDeclaration(st.getName())
1799+
candidates.addAll(tempCandidates);
18381800
}
18391801
}
18401802
List<StructuralPropertyDescriptor> sprops =
1841-
nearestNode.structuralPropertiesForType();
1803+
nearestNode.structuralPropertiesForType();
18421804
for (StructuralPropertyDescriptor sprop : sprops) {
18431805
ASTNode cnode;
18441806
if (!sprop.isChildListProperty()) {
@@ -1918,7 +1880,7 @@ public List<CompletionCandidate> preparePredictions(final PreprocSketch ps,
19181880
expr.astNode.getNodeType() == ASTNode.SIMPLE_TYPE;
19191881
boolean isMethod = expr.method != null;
19201882
boolean staticOnly = !isMethod && !isArray && !isSimpleType;
1921-
log("Expr is " + expr.toString());
1883+
log("Expr is " + expr);
19221884
String lookFor = (noCompare || (childExpr == null)) ?
19231885
"" : childExpr.toString();
19241886
candidates = getMembersForType(ps, expr, lookFor, noCompare, staticOnly);

0 commit comments

Comments
 (0)