From 12fefba4792d88a7964dd8c053b6a3e2a7b56d67 Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Sat, 13 Jul 2013 05:00:30 +0530 Subject: [PATCH] further completion stuff, including System.out.println() --- pdex/Todo, GSoC 2013.txt | 7 ++-- .../mode/experimental/ASTGenerator.java | 34 ++++++++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pdex/Todo, GSoC 2013.txt b/pdex/Todo, GSoC 2013.txt index 8ee9a09e6..300bf8a73 100644 --- a/pdex/Todo, GSoC 2013.txt +++ b/pdex/Todo, GSoC 2013.txt @@ -15,10 +15,11 @@ x Discovered another major issue due to offset differences -> While looking for Ex - "s.substring(int(13.4))." fails. Thinking to just do the substitutions before sending it to updatePredictions(), coz offsets aren't really a concern here, right? Yup, fixed it! x! Code completion with library code, non-nested seems to be broken, fix it. Fixed. x Completion for external classes - ArrayList, HashMap, etc. -*! Recursive lookup for compiled(library) code! -*! Library CC for nested would be tricky. Need to jump from local->compiled code while searching recursively. Recursive find's current implementation is based on ASTNode return type. Afaik, no way to instantiate orphaned ASTNode objects(or did I miss it?). ASTNode objects have to be created only from the main ast instance. But I need to find a way to switch to compiled instances from local class instance. +x! Recursive lookup for compiled(library) code! +x! Library CC for nested would be tricky. Need to jump from local->compiled code while searching recursively. Recursive find's current implementation is based on ASTNode return type. Afaik, no way to instantiate orphaned ASTNode objects(or did I miss it?). ASTNode objects have to be created only from the main ast instance. But I need to find a way to switch to compiled instances from local class instance. *! May be I should just implement recursive find for compiled code first, see how it goes and hopefully it would give me some ideas about how to integrating the two. - - Making very good progress here. The elegance of recurion - Hats off! + - Making very good progress here. The elegance of recurion - Hats off! + - Many of the cases seem to have been covered, and I'm achieving more and more code unification as I'm working through the problem step by step x! Should I implement wrapper for ASTNode? - possibly needed for code completion with compiled and non-compiled code. Done. * Trie implementation would be lower priority, "premature optimisation is pure evil". Get all features of CC working good enough and then plan this. x Differentiating between multiple statements on the same line. How to? Done with offset handling. diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 382113adf..b7161e9b9 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -563,9 +563,17 @@ public class ASTGenerator { if(astNode instanceof SimpleName){ ASTNode decl = findDeclaration2(((SimpleName)astNode),nearestNode); if(decl != null){ + // see if locally defined System.out.println(getNodeAsString(astNode)+" found decl -> " + getNodeAsString(decl)); return new ClassMember(extracTypeInfo(decl)); } + else { + // or in a predefined class? + Class tehClass = findClassIfExists(((SimpleName) astNode).toString()); + if (tehClass != null) { + return new ClassMember(tehClass); + } + } astNode = astNode.getParent(); } switch (astNode.getNodeType()) { @@ -585,6 +593,7 @@ public class ASTGenerator { * System.out.println(), or maybe belonging to super class, etc. */ System.out.println("resolve 3rd par, Can't resolve " + fa.getExpression()); + return null; } System.out.println("FA, SN Type " + getNodeAsString(stp)); @@ -657,6 +666,11 @@ public class ASTGenerator { /*The type wasn't found in local code, so it might be something like * System.out.println(), or maybe belonging to super class, etc. */ + Class tehClass = findClassIfExists(qn.getQualifier().toString()); + if (tehClass != null) { + return definedIn3rdPartyClass(new ClassMember(tehClass), qn + .getName().toString()); + } System.out.println("resolve 3rd par, Can't resolve " + qn.getQualifier()); return null; } @@ -1268,17 +1282,24 @@ public class ASTGenerator { System.out.println(tehClass.getName() + " located."); return tehClass; } -// else if(impS.endsWith(className)){ -// tehClass = Class.forName(impS, false, errorCheckerService.getSketchClassLoader()); -// System.out.println(tehClass.getName() + " located."); -// return tehClass; -// } } catch (ClassNotFoundException e) { // it does not exist on the classpath System.out.println("Doesn't exist in package: " + impS); } } + + // And finally, the daddy + String daddy = "java.lang." + className; + try { + tehClass = Class.forName(daddy, false, + errorCheckerService.getSketchClassLoader()); + System.out.println(tehClass.getName() + " located."); + return tehClass; + } catch (ClassNotFoundException e) { + // it does not exist on the classpath + System.out.println("Doesn't exist in package: " + daddy); + } return tehClass; } @@ -2512,6 +2533,8 @@ public class ASTGenerator { SimpleType stp = extracTypeInfo(findDeclaration2((qn.getQualifier()), alternateParent)); + if(stp == null) + return null; declaringClass = findDeclaration2(stp.getName(), alternateParent); System.out.println(qn.getQualifier() + "->" + qn.getName()); System.out.println("QN decl class: " + getNodeAsString(declaringClass)); @@ -2909,6 +2932,7 @@ public class ASTGenerator { case ASTNode.VARIABLE_DECLARATION_FRAGMENT: return extracTypeInfo(node.getParent()); } + System.out.println("Unknown type info request " + getNodeAsString(node)); return null; }