< prev index next >

src/jdk.jshell/share/classes/jdk/jshell/Eval.java

Print this page

        

@@ -96,11 +96,10 @@
  * @author Robert Field
  */
 class Eval {
 
     private static final Pattern IMPORT_PATTERN = Pattern.compile("import\\p{javaWhitespace}+(?<static>static\\p{javaWhitespace}+)?(?<fullname>[\\p{L}\\p{N}_\\$\\.]+\\.(?<name>[\\p{L}\\p{N}_\\$]+|\\*))");
-    private static final Pattern DEFAULT_PREFIX = Pattern.compile("\\p{javaWhitespace}*(default)\\p{javaWhitespace}+");
 
     // for uses that should not change state -- non-evaluations
     private boolean preserveState = false;
 
     private int varNumber = 0;

@@ -200,17 +199,11 @@
             if (units.isEmpty()) {
                 return compileFailResult(pt, userSource, Kind.ERRONEOUS);
             }
             Tree unitTree = units.get(0);
             if (pt.getDiagnostics().hasOtherThanNotStatementErrors()) {
-                Matcher matcher = DEFAULT_PREFIX.matcher(compileSource);
-                DiagList dlist = matcher.lookingAt()
-                        ? new DiagList(new ModifierDiagnostic(true,
-                            state.messageFormat("jshell.diag.modifier.single.fatal", "'default'"),
-                            matcher.start(1), matcher.end(1)))
-                        : pt.getDiagnostics();
-                return compileFailResult(dlist, userSource, kindOfTree(unitTree));
+                return compileFailResult(pt, userSource, kindOfTree(unitTree));
             }
 
             // Erase illegal/ignored modifiers
             String compileSourceInt = new MaskCommentsAndModifiers(compileSource, true).cleared();
 

@@ -972,11 +965,11 @@
             ins.stream().forEach(u -> u.setWrap(ins, ins));
             state.taskFactory.analyze(outerWrapSet(ins), at -> {
                 ins.stream().forEach(u -> u.setDiagnostics(at));
 
                 // corral any Snippets that need it
-                if (ins.stream().filter(u -> u.corralIfNeeded(ins)).count() > 0) {
+                if (ins.stream().anyMatch(u -> u.corralIfNeeded(ins))) {
                     // if any were corralled, re-analyze everything
                     state.taskFactory.analyze(outerWrapSet(ins), cat -> {
                         ins.stream().forEach(u -> u.setCorralledDiagnostics(cat));
                         ins.stream().forEach(u -> u.setStatus(cat));
                         return null;

@@ -1159,25 +1152,38 @@
                         String.join(" ", objectMethods));
             }
         };
     }
 
-    private class ModifierDiagnostic extends Diag {
+    private DiagList modifierDiagnostics(ModifiersTree modtree,
+            final TreeDissector dis, boolean isAbstractProhibited) {
+
+        class ModifierDiagnostic extends Diag {
 
             final boolean fatal;
             final String message;
-            final long start;
-            final long end;
+            long start;
+            long end;
 
-            ModifierDiagnostic(boolean fatal,
-                    final String message,
-                    long start,
-                    long end) {
+            ModifierDiagnostic(List<Modifier> list, boolean fatal) {
                 this.fatal = fatal;
-                this.message = message;
-                this.start = start;
-                this.end = end;
+                StringBuilder sb = new StringBuilder();
+                for (Modifier mod : list) {
+                    sb.append("'");
+                    sb.append(mod.toString());
+                    sb.append("' ");
+                }
+                String key = (list.size() > 1)
+                        ? fatal
+                            ? "jshell.diag.modifier.plural.fatal"
+                            : "jshell.diag.modifier.plural.ignore"
+                        : fatal
+                            ? "jshell.diag.modifier.single.fatal"
+                            : "jshell.diag.modifier.single.ignore";
+                this.message = state.messageFormat(key, sb.toString());
+                start = dis.getStartPosition(modtree);
+                end = dis.getEndPosition(modtree);
             }
 
             @Override
             public boolean isError() {
                 return fatal;

@@ -1207,14 +1213,11 @@
 
             @Override
             public String getMessage(Locale locale) {
                 return message;
             }
-    }
-
-    private DiagList modifierDiagnostics(ModifiersTree modtree,
-                                         final TreeDissector dis, boolean isAbstractProhibited) {
+        }
 
         List<Modifier> list = new ArrayList<>();
         boolean fatal = false;
         for (Modifier mod : modtree.getFlags()) {
             switch (mod) {

@@ -1238,30 +1241,13 @@
                 case FINAL:
                     list.add(mod);
                     break;
             }
         }
-        if (list.isEmpty()) {
-            return new DiagList();
-        } else {
-            StringBuilder sb = new StringBuilder();
-            for (Modifier mod : list) {
-                sb.append("'");
-                sb.append(mod.toString());
-                sb.append("' ");
-            }
-            String key = (list.size() > 1)
-                    ? fatal
-                    ? "jshell.diag.modifier.plural.fatal"
-                    : "jshell.diag.modifier.plural.ignore"
-                    : fatal
-                    ? "jshell.diag.modifier.single.fatal"
-                    : "jshell.diag.modifier.single.ignore";
-            String message = state.messageFormat(key, sb.toString().trim());
-            return new DiagList(new ModifierDiagnostic(fatal, message,
-                    dis.getStartPosition(modtree), dis.getEndPosition(modtree)));
-        }
+        return list.isEmpty()
+                ? new DiagList()
+                : new DiagList(new ModifierDiagnostic(list, fatal));
     }
 
     String computeDeclareName(TypeSymbol ts) {
         return Util.JSHELL_ANONYMOUS + "$" + Long.toUnsignedString(anonCount++);
     }
< prev index next >