mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-24 13:51:12 +00:00
7198582: (java) Minor refactor of JavacParser
Reviewed-by: jjg, ksrini
This commit is contained in:
parent
b3aacc5029
commit
ed2bca8140
@ -251,7 +251,7 @@ public class Resolve {
|
||||
/** 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;
|
||||
}
|
||||
|
||||
|
||||
@ -2165,27 +2165,10 @@ public class JavacParser implements Parser {
|
||||
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 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
@ -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 @@ import com.sun.tools.classfile.Method;
|
||||
* 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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user