< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java

Print this page




  75     private final boolean parseModuleInfo;
  76 
  77     /** The scanner used for lexical analysis.
  78      */
  79     protected Lexer S;
  80 
  81     /** The factory to be used for abstract syntax tree construction.
  82      */
  83     protected TreeMaker F;
  84 
  85     /** The log to be used for error diagnostics.
  86      */
  87     private Log log;
  88 
  89     /** The Source language setting. */
  90     private Source source;
  91 
  92     /** The name table. */
  93     private Names names;
  94 



  95     /** End position mappings container */
  96     protected final AbstractEndPosTable endPosTable;
  97 
  98     // Because of javac's limited lookahead, some contexts are ambiguous in
  99     // the presence of type annotations even though they are not ambiguous
 100     // in the absence of type annotations.  Consider this code:
 101     //   void m(String [] m) { }
 102     //   void m(String ... m) { }
 103     // After parsing "String", javac calls bracketsOpt which immediately
 104     // returns if the next character is not '['.  Similarly, javac can see
 105     // if the next token is ... and in that case parse an ellipsis.  But in
 106     // the presence of type annotations:
 107     //   void m(String @A [] m) { }
 108     //   void m(String @A ... m) { }
 109     // no finite lookahead is enough to determine whether to read array
 110     // levels or an ellipsis.  Furthermore, if you call bracketsOpt, then
 111     // bracketsOpt first reads all the leading annotations and only then
 112     // discovers that it needs to fail.  bracketsOpt needs a way to push
 113     // back the extra annotations that it read.  (But, bracketsOpt should
 114     // not *always* be allowed to push back extra annotations that it finds


 169         this.allowDiamond = source.allowDiamond();
 170         this.allowMulticatch = source.allowMulticatch();
 171         this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
 172         this.allowLambda = source.allowLambda();
 173         this.allowMethodReferences = source.allowMethodReferences();
 174         this.allowDefaultMethods = source.allowDefaultMethods();
 175         this.allowStaticInterfaceMethods = source.allowStaticInterfaceMethods();
 176         this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
 177         this.allowTypeAnnotations = source.allowTypeAnnotations();
 178         this.allowModules = source.allowModules();
 179         this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams();
 180         this.allowUnderscoreIdentifier = source.allowUnderscoreIdentifier();
 181         this.allowPrivateInterfaceMethods = source.allowPrivateInterfaceMethods();
 182         this.allowLocalVariableTypeInference = source.allowLocalVariableTypeInference();
 183         this.keepDocComments = keepDocComments;
 184         this.parseModuleInfo = parseModuleInfo;
 185         docComments = newDocCommentTable(keepDocComments, fac);
 186         this.keepLineMap = keepLineMap;
 187         this.errorTree = F.Erroneous();
 188         endPosTable = newEndPosTable(keepEndPositions);

 189     }
 190 
 191     protected AbstractEndPosTable newEndPosTable(boolean keepEndPositions) {
 192         return  keepEndPositions
 193                 ? new SimpleEndPosTable(this)
 194                 : new EmptyEndPosTable(this);
 195     }
 196 
 197     protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) {
 198         return keepDocComments ? new LazyDocCommentTable(fac) : null;
 199     }
 200 
 201     /** Switch: Should diamond operator be recognized?
 202      */
 203     boolean allowDiamond;
 204 
 205     /** Switch: Should multicatch clause be accepted?
 206      */
 207     boolean allowMulticatch;
 208 


 622             nextToken();
 623             return names.error;
 624         } else if (token.kind == ENUM) {
 625             error(token.pos, "enum.as.identifier");
 626             nextToken();
 627             return names.error;
 628         } else if (token.kind == THIS) {
 629             if (allowThisIdent) {
 630                 // Make sure we're using a supported source version.
 631                 checkTypeAnnotations();
 632                 Name name = token.name();
 633                 nextToken();
 634                 return name;
 635             } else {
 636                 error(token.pos, "this.as.identifier");
 637                 nextToken();
 638                 return names.error;
 639             }
 640         } else if (token.kind == UNDERSCORE) {
 641             if (allowUnderscoreIdentifier) {


 642                 warning(token.pos, "underscore.as.identifier");

 643             } else {
 644                 error(token.pos, "underscore.as.identifier");
 645             }
 646             Name name = token.name();
 647             nextToken();
 648             return name;
 649         } else {
 650             accept(IDENTIFIER);
 651             if (advanceOnErrors) {
 652                 nextToken();
 653             }
 654             return names.error;
 655         }
 656     }
 657 
 658     /**
 659      * Qualident = Ident { DOT [Annotations] Ident }
 660      */
 661     public JCExpression qualident(boolean allowAnnos) {
 662         JCExpression t = toP(F.at(token.pos).Ident(ident()));




  75     private final boolean parseModuleInfo;
  76 
  77     /** The scanner used for lexical analysis.
  78      */
  79     protected Lexer S;
  80 
  81     /** The factory to be used for abstract syntax tree construction.
  82      */
  83     protected TreeMaker F;
  84 
  85     /** The log to be used for error diagnostics.
  86      */
  87     private Log log;
  88 
  89     /** The Source language setting. */
  90     private Source source;
  91 
  92     /** The name table. */
  93     private Names names;
  94 
  95     /** The lint settings. */
  96     private Lint lint;
  97 
  98     /** End position mappings container */
  99     protected final AbstractEndPosTable endPosTable;
 100 
 101     // Because of javac's limited lookahead, some contexts are ambiguous in
 102     // the presence of type annotations even though they are not ambiguous
 103     // in the absence of type annotations.  Consider this code:
 104     //   void m(String [] m) { }
 105     //   void m(String ... m) { }
 106     // After parsing "String", javac calls bracketsOpt which immediately
 107     // returns if the next character is not '['.  Similarly, javac can see
 108     // if the next token is ... and in that case parse an ellipsis.  But in
 109     // the presence of type annotations:
 110     //   void m(String @A [] m) { }
 111     //   void m(String @A ... m) { }
 112     // no finite lookahead is enough to determine whether to read array
 113     // levels or an ellipsis.  Furthermore, if you call bracketsOpt, then
 114     // bracketsOpt first reads all the leading annotations and only then
 115     // discovers that it needs to fail.  bracketsOpt needs a way to push
 116     // back the extra annotations that it read.  (But, bracketsOpt should
 117     // not *always* be allowed to push back extra annotations that it finds


 172         this.allowDiamond = source.allowDiamond();
 173         this.allowMulticatch = source.allowMulticatch();
 174         this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
 175         this.allowLambda = source.allowLambda();
 176         this.allowMethodReferences = source.allowMethodReferences();
 177         this.allowDefaultMethods = source.allowDefaultMethods();
 178         this.allowStaticInterfaceMethods = source.allowStaticInterfaceMethods();
 179         this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
 180         this.allowTypeAnnotations = source.allowTypeAnnotations();
 181         this.allowModules = source.allowModules();
 182         this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams();
 183         this.allowUnderscoreIdentifier = source.allowUnderscoreIdentifier();
 184         this.allowPrivateInterfaceMethods = source.allowPrivateInterfaceMethods();
 185         this.allowLocalVariableTypeInference = source.allowLocalVariableTypeInference();
 186         this.keepDocComments = keepDocComments;
 187         this.parseModuleInfo = parseModuleInfo;
 188         docComments = newDocCommentTable(keepDocComments, fac);
 189         this.keepLineMap = keepLineMap;
 190         this.errorTree = F.Erroneous();
 191         endPosTable = newEndPosTable(keepEndPositions);
 192         this.lint = fac.lint;
 193     }
 194 
 195     protected AbstractEndPosTable newEndPosTable(boolean keepEndPositions) {
 196         return  keepEndPositions
 197                 ? new SimpleEndPosTable(this)
 198                 : new EmptyEndPosTable(this);
 199     }
 200 
 201     protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) {
 202         return keepDocComments ? new LazyDocCommentTable(fac) : null;
 203     }
 204 
 205     /** Switch: Should diamond operator be recognized?
 206      */
 207     boolean allowDiamond;
 208 
 209     /** Switch: Should multicatch clause be accepted?
 210      */
 211     boolean allowMulticatch;
 212 


 626             nextToken();
 627             return names.error;
 628         } else if (token.kind == ENUM) {
 629             error(token.pos, "enum.as.identifier");
 630             nextToken();
 631             return names.error;
 632         } else if (token.kind == THIS) {
 633             if (allowThisIdent) {
 634                 // Make sure we're using a supported source version.
 635                 checkTypeAnnotations();
 636                 Name name = token.name();
 637                 nextToken();
 638                 return name;
 639             } else {
 640                 error(token.pos, "this.as.identifier");
 641                 nextToken();
 642                 return names.error;
 643             }
 644         } else if (token.kind == UNDERSCORE) {
 645             if (allowUnderscoreIdentifier) {
 646                 if (lint.isEnabled(Lint.LintCategory.FUTURE) &&
 647                     !lint.isSuppressed(Lint.LintCategory.FUTURE)) {
 648                     warning(token.pos, "underscore.as.identifier");
 649                 }
 650             } else {
 651                 error(token.pos, "underscore.as.identifier");
 652             }
 653             Name name = token.name();
 654             nextToken();
 655             return name;
 656         } else {
 657             accept(IDENTIFIER);
 658             if (advanceOnErrors) {
 659                 nextToken();
 660             }
 661             return names.error;
 662         }
 663     }
 664 
 665     /**
 666      * Qualident = Ident { DOT [Annotations] Ident }
 667      */
 668     public JCExpression qualident(boolean allowAnnos) {
 669         JCExpression t = toP(F.at(token.pos).Ident(ident()));


< prev index next >