equal
deleted
inserted
replaced
209 return new CompletionInfo(status, unitEndPos, srcInput, ""); |
209 return new CompletionInfo(status, unitEndPos, srcInput, ""); |
210 } |
210 } |
211 throw new InternalError(); |
211 throw new InternalError(); |
212 } |
212 } |
213 |
213 |
214 private OuterWrap wrapInClass(Wrap guts) { |
|
215 String imports = proc.maps.packageAndImportsExcept(null, null); |
|
216 return OuterWrap.wrapInClass(proc.maps.packageName(), REPL_DOESNOTMATTER_CLASS_NAME, imports, "", guts); |
|
217 } |
|
218 |
|
219 private Tree.Kind guessKind(String code) { |
214 private Tree.Kind guessKind(String code) { |
220 ParseTask pt = proc.taskFactory.new ParseTask(code); |
215 ParseTask pt = proc.taskFactory.new ParseTask(code); |
221 List<? extends Tree> units = pt.units(); |
216 List<? extends Tree> units = pt.units(); |
222 if (units.isEmpty()) { |
217 if (units.isEmpty()) { |
223 return Tree.Kind.BLOCK; |
218 return Tree.Kind.BLOCK; |
256 code += ";"; |
251 code += ";"; |
257 } |
252 } |
258 OuterWrap codeWrap; |
253 OuterWrap codeWrap; |
259 switch (guessKind(code)) { |
254 switch (guessKind(code)) { |
260 case IMPORT: |
255 case IMPORT: |
261 codeWrap = OuterWrap.wrapImport(null, Wrap.simpleWrap(code + "any.any")); |
256 codeWrap = proc.outerMap.wrapImport(Wrap.simpleWrap(code + "any.any"), null); |
262 break; |
257 break; |
263 case METHOD: |
258 case METHOD: |
264 codeWrap = wrapInClass(Wrap.classMemberWrap(code)); |
259 codeWrap = proc.outerMap.wrapInTrialClass(Wrap.classMemberWrap(code)); |
265 break; |
260 break; |
266 default: |
261 default: |
267 codeWrap = wrapInClass(Wrap.methodWrap(code)); |
262 codeWrap = proc.outerMap.wrapInTrialClass(Wrap.methodWrap(code)); |
268 break; |
263 break; |
269 } |
264 } |
270 String requiredPrefix = identifier; |
265 String requiredPrefix = identifier; |
271 return computeSuggestions(codeWrap, cursor, anchor).stream() |
266 return computeSuggestions(codeWrap, cursor, anchor).stream() |
272 .filter(s -> s.continuation.startsWith(requiredPrefix) && !s.continuation.equals(REPL_DOESNOTMATTER_CLASS_NAME)) |
267 .filter(s -> s.continuation.startsWith(requiredPrefix) && !s.continuation.equals(REPL_DOESNOTMATTER_CLASS_NAME)) |
944 } |
939 } |
945 |
940 |
946 if (guessKind(code) == Kind.IMPORT) |
941 if (guessKind(code) == Kind.IMPORT) |
947 return null; |
942 return null; |
948 |
943 |
949 OuterWrap codeWrap = wrapInClass(Wrap.methodWrap(code)); |
944 OuterWrap codeWrap = proc.outerMap.wrapInTrialClass(Wrap.methodWrap(code)); |
950 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap); |
945 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap); |
951 SourcePositions sp = at.trees().getSourcePositions(); |
946 SourcePositions sp = at.trees().getSourcePositions(); |
952 CompilationUnitTree topLevel = at.firstCuTree(); |
947 CompilationUnitTree topLevel = at.firstCuTree(); |
953 TreePath tp = pathFor(topLevel, sp, codeWrap.snippetIndexToWrapIndex(cursor)); |
948 TreePath tp = pathFor(topLevel, sp, codeWrap.snippetIndexToWrapIndex(cursor)); |
954 |
949 |
1062 switch (guessKind(code)) { |
1057 switch (guessKind(code)) { |
1063 case IMPORT: case METHOD: case CLASS: case ENUM: |
1058 case IMPORT: case METHOD: case CLASS: case ENUM: |
1064 case INTERFACE: case ANNOTATION_TYPE: case VARIABLE: |
1059 case INTERFACE: case ANNOTATION_TYPE: case VARIABLE: |
1065 return null; |
1060 return null; |
1066 default: |
1061 default: |
1067 codeWrap = wrapInClass(Wrap.methodWrap(code)); |
1062 codeWrap = proc.outerMap.wrapInTrialClass(Wrap.methodWrap(code)); |
1068 break; |
1063 break; |
1069 } |
1064 } |
1070 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap); |
1065 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap); |
1071 SourcePositions sp = at.trees().getSourcePositions(); |
1066 SourcePositions sp = at.trees().getSourcePositions(); |
1072 CompilationUnitTree topLevel = at.firstCuTree(); |
1067 CompilationUnitTree topLevel = at.firstCuTree(); |
1102 OuterWrap codeWrap; |
1097 OuterWrap codeWrap; |
1103 switch (guessKind(code)) { |
1098 switch (guessKind(code)) { |
1104 case IMPORT: |
1099 case IMPORT: |
1105 return new QualifiedNames(Collections.emptyList(), -1, true, false); |
1100 return new QualifiedNames(Collections.emptyList(), -1, true, false); |
1106 case METHOD: |
1101 case METHOD: |
1107 codeWrap = wrapInClass(Wrap.classMemberWrap(code)); |
1102 codeWrap = proc.outerMap.wrapInTrialClass(Wrap.classMemberWrap(code)); |
1108 break; |
1103 break; |
1109 default: |
1104 default: |
1110 codeWrap = wrapInClass(Wrap.methodWrap(code)); |
1105 codeWrap = proc.outerMap.wrapInTrialClass(Wrap.methodWrap(code)); |
1111 break; |
1106 break; |
1112 } |
1107 } |
1113 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap); |
1108 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap); |
1114 SourcePositions sp = at.trees().getSourcePositions(); |
1109 SourcePositions sp = at.trees().getSourcePositions(); |
1115 CompilationUnitTree topLevel = at.firstCuTree(); |
1110 CompilationUnitTree topLevel = at.firstCuTree(); |