7198582: (java) Minor refactor of JavacParser
authorksrini
Sat, 29 Sep 2012 09:00:58 -0700
changeset 14056 0ea78d6e0b7b
parent 14055 e9394dd57b19
child 14057 b4b0377b8dba
7198582: (java) Minor refactor of JavacParser Reviewed-by: jjg, ksrini Contributed-by: jan.lahoda@oracle.com
langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
langtools/src/share/classes/com/sun/tools/javap/CodeWriter.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Sep 28 14:57:31 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Sat Sep 29 09:00:58 2012 -0700
@@ -251,7 +251,7 @@
     /** An environment is "static" if its static level is greater than
      *  the one of its outer environment
      */
-    static boolean isStatic(Env<AttrContext> env) {
+    protected static boolean isStatic(Env<AttrContext> env) {
         return env.info.staticLevel > env.outer.info.staticLevel;
     }
 
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Sep 28 14:57:31 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sat Sep 29 09:00:58 2012 -0700
@@ -2165,27 +2165,10 @@
         while (true) {
             int pos = token.pos;
             switch (token.kind) {
-            case CASE: {
-                nextToken();
-                JCExpression pat = parseExpression();
-                accept(COLON);
-                List<JCStatement> stats = blockStatements();
-                JCCase c = F.at(pos).Case(pat, stats);
-                if (stats.isEmpty())
-                    storeEnd(c, S.prevToken().endPos);
-                cases.append(c);
+            case CASE:
+            case DEFAULT:
+                cases.append(switchBlockStatementGroup());
                 break;
-            }
-            case DEFAULT: {
-                nextToken();
-                accept(COLON);
-                List<JCStatement> stats = blockStatements();
-                JCCase c = F.at(pos).Case(null, stats);
-                if (stats.isEmpty())
-                    storeEnd(c, S.prevToken().endPos);
-                cases.append(c);
-                break;
-            }
             case RBRACE: case EOF:
                 return cases.toList();
             default:
@@ -2196,6 +2179,32 @@
         }
     }
 
+    protected JCCase switchBlockStatementGroup() {
+        int pos = token.pos;
+        List<JCStatement> stats;
+        JCCase c;
+        switch (token.kind) {
+        case CASE:
+            nextToken();
+            JCExpression pat = parseExpression();
+            accept(COLON);
+            stats = blockStatements();
+            c = F.at(pos).Case(pat, stats);
+            if (stats.isEmpty())
+                storeEnd(c, S.prevToken().endPos);
+            return c;
+        case DEFAULT:
+            nextToken();
+            accept(COLON);
+            stats = blockStatements();
+            c = F.at(pos).Case(null, stats);
+            if (stats.isEmpty())
+                storeEnd(c, S.prevToken().endPos);
+            return c;
+        }
+        throw new AssertionError("should not reach here");
+    }
+
     /** MoreStatementExpressions = { COMMA StatementExpression }
      */
     <T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos,
--- a/langtools/src/share/classes/com/sun/tools/javap/CodeWriter.java	Fri Sep 28 14:57:31 2012 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javap/CodeWriter.java	Sat Sep 29 09:00:58 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,8 +45,8 @@
  *  This code and its internal interfaces are subject to change or
  *  deletion without notice.</b>
  */
-class CodeWriter extends BasicWriter {
-    static CodeWriter instance(Context context) {
+public class CodeWriter extends BasicWriter {
+    public static CodeWriter instance(Context context) {
         CodeWriter instance = context.get(CodeWriter.class);
         if (instance == null)
             instance = new CodeWriter(context);