Package com.google.dart.engine.internal.parser

Examples of com.google.dart.engine.internal.parser.CommentAndMetadata


   * @param className the name of the class containing the member being parsed
   * @return the class member that was parsed, or {@code null} if what was found was not a valid
   *         class member
   */
  protected ClassMember parseClassMember(String className) {
    CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
    Modifiers modifiers = parseModifiers();
    if (matchesKeyword(Keyword.VOID)) {
      TypeName returnType = parseReturnType();
      if (matchesKeyword(Keyword.GET) && tokenMatchesIdentifier(peek())) {
        validateModifiersForGetterOrSetterOrMethod(modifiers);
        return parseGetter(
            commentAndMetadata,
            modifiers.getExternalKeyword(),
            modifiers.getStaticKeyword(),
            returnType);
      } else if (matchesKeyword(Keyword.SET) && tokenMatchesIdentifier(peek())) {
        validateModifiersForGetterOrSetterOrMethod(modifiers);
        return parseSetter(
            commentAndMetadata,
            modifiers.getExternalKeyword(),
            modifiers.getStaticKeyword(),
            returnType);
      } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
        validateModifiersForOperator(modifiers);
        return parseOperator(commentAndMetadata, modifiers.getExternalKeyword(), returnType);
      } else if (matchesIdentifier()
          && peek().matchesAny(
              TokenType.OPEN_PAREN,
              TokenType.OPEN_CURLY_BRACKET,
              TokenType.FUNCTION)) {
        validateModifiersForGetterOrSetterOrMethod(modifiers);
        return parseMethodDeclarationAfterReturnType(
            commentAndMetadata,
            modifiers.getExternalKeyword(),
            modifiers.getStaticKeyword(),
            returnType);
      } else {
        //
        // We have found an error of some kind. Try to recover.
        //
        if (matchesIdentifier()) {
          if (peek().matchesAny(TokenType.EQ, TokenType.COMMA, TokenType.SEMICOLON)) {
            //
            // We appear to have a variable declaration with a type of "void".
            //
            reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
            return parseInitializedIdentifierList(
                commentAndMetadata,
                modifiers.getStaticKeyword(),
                validateModifiersForField(modifiers),
                returnType);
          }
        }
        if (isOperator(currentToken)) {
          //
          // We appear to have found an operator declaration without the 'operator' keyword.
          //
          validateModifiersForOperator(modifiers);
          return parseOperator(commentAndMetadata, modifiers.getExternalKeyword(), returnType);
        }
        reportErrorForToken(ParserErrorCode.EXPECTED_EXECUTABLE, currentToken);
        return null;
      }
    } else if (matchesKeyword(Keyword.GET) && tokenMatchesIdentifier(peek())) {
      validateModifiersForGetterOrSetterOrMethod(modifiers);
      return parseGetter(
          commentAndMetadata,
          modifiers.getExternalKeyword(),
          modifiers.getStaticKeyword(),
          null);
    } else if (matchesKeyword(Keyword.SET) && tokenMatchesIdentifier(peek())) {
      validateModifiersForGetterOrSetterOrMethod(modifiers);
      return parseSetter(
          commentAndMetadata,
          modifiers.getExternalKeyword(),
          modifiers.getStaticKeyword(),
          null);
    } else if (matchesKeyword(Keyword.OPERATOR) && isOperator(peek())) {
      validateModifiersForOperator(modifiers);
      return parseOperator(commentAndMetadata, modifiers.getExternalKeyword(), null);
    } else if (!matchesIdentifier()) {
      if (isOperator(currentToken)) {
        //
        // We appear to have found an operator declaration without the 'operator' keyword.
        //
        validateModifiersForOperator(modifiers);
        return parseOperator(commentAndMetadata, modifiers.getExternalKeyword(), null);
      }
      Token keyword = modifiers.getVarKeyword();
      if (keyword == null) {
        keyword = modifiers.getFinalKeyword();
      }
      if (keyword == null) {
        keyword = modifiers.getConstKeyword();
      }
      if (keyword != null) {
        //
        // We appear to have found an incomplete field declaration.
        //
        reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
        ArrayList<VariableDeclaration> variables = new ArrayList<VariableDeclaration>();
        variables.add(new VariableDeclaration(null, null, createSyntheticIdentifier(), null, null));
        return new FieldDeclaration(
            commentAndMetadata.getComment(),
            commentAndMetadata.getMetadata(),
            null,
            new VariableDeclarationList(null, null, keyword, null, variables),
            expectSemicolon());
      }
      reportErrorForToken(ParserErrorCode.EXPECTED_CLASS_MEMBER, currentToken);
      if (commentAndMetadata.getComment() != null || !commentAndMetadata.getMetadata().isEmpty()) {
        //
        // We appear to have found an incomplete declaration at the end of the class. At this point
        // it consists of a metadata, which we don't want to loose, so we'll treat it as a method
        // declaration with a missing name, parameters and empty body.
        //
        return new MethodDeclaration(
            commentAndMetadata.getComment(),
            commentAndMetadata.getMetadata(),
            null,
            null,
            null,
            null,
            null,
View Full Code Here


    boolean directiveFoundAfterDeclaration = false;
    List<Directive> directives = new ArrayList<Directive>();
    List<CompilationUnitMember> declarations = new ArrayList<CompilationUnitMember>();
    Token memberStart = currentToken;
    while (!matches(TokenType.EOF)) {
      CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
      if ((matchesKeyword(Keyword.IMPORT) || matchesKeyword(Keyword.EXPORT)
          || matchesKeyword(Keyword.LIBRARY) || matchesKeyword(Keyword.PART))
          && !tokenMatches(peek(), TokenType.PERIOD)
          && !tokenMatches(peek(), TokenType.LT)
          && !tokenMatches(peek(), TokenType.OPEN_PAREN)) {
View Full Code Here

   * </pre>
   *
   * @return the normal formal parameter that was parsed
   */
  protected NormalFormalParameter parseNormalFormalParameter() {
    CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
    FinalConstVarOrType holder = parseFinalConstVarOrType(true);
    Token thisKeyword = null;
    Token period = null;
    if (matchesKeyword(Keyword.THIS)) {
      thisKeyword = getAndAdvance();
      period = expect(TokenType.PERIOD);
    }
    SimpleIdentifier identifier = parseSimpleIdentifier();
    if (matches(TokenType.OPEN_PAREN)) {
      FormalParameterList parameters = parseFormalParameterList();
      if (thisKeyword == null) {
        if (holder.getKeyword() != null) {
          reportErrorForToken(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.getKeyword());
        }
        return new FunctionTypedFormalParameter(
            commentAndMetadata.getComment(),
            commentAndMetadata.getMetadata(),
            holder.getType(),
            identifier,
            parameters);
      } else {
        return new FieldFormalParameter(
            commentAndMetadata.getComment(),
            commentAndMetadata.getMetadata(),
            holder.getKeyword(),
            holder.getType(),
            thisKeyword,
            period,
            identifier,
            parameters);
      }
    }
    TypeName type = holder.getType();
    if (type != null) {
      if (tokenMatchesKeyword(type.getName().getBeginToken(), Keyword.VOID)) {
        reportErrorForToken(ParserErrorCode.VOID_PARAMETER, type.getName().getBeginToken());
      } else if (holder.getKeyword() != null
          && tokenMatchesKeyword(holder.getKeyword(), Keyword.VAR)) {
        reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.getKeyword());
      }
    }
    if (thisKeyword != null) {
      return new FieldFormalParameter(
          commentAndMetadata.getComment(),
          commentAndMetadata.getMetadata(),
          holder.getKeyword(),
          holder.getType(),
          thisKeyword,
          period,
          identifier,
          null);
    }
    return new SimpleFormalParameter(
        commentAndMetadata.getComment(),
        commentAndMetadata.getMetadata(),
        holder.getKeyword(),
        holder.getType(),
        identifier);
  }
View Full Code Here

* </pre>
   *
   * @return the type parameter that was parsed
   */
  protected TypeParameter parseTypeParameter() {
    CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
    SimpleIdentifier name = parseSimpleIdentifier();
    if (matchesKeyword(Keyword.EXTENDS)) {
      Token keyword = getAndAdvance();
      TypeName bound = parseTypeName();
      return new TypeParameter(
          commentAndMetadata.getComment(),
          commentAndMetadata.getMetadata(),
          name,
          keyword,
          bound);
    }
    return new TypeParameter(
        commentAndMetadata.getComment(),
        commentAndMetadata.getMetadata(),
        name,
        null,
        null);
  }
View Full Code Here

      Comment optionalComment = parseDocumentationComment();
      if (optionalComment != null) {
        comment = optionalComment;
      }
    }
    return new CommentAndMetadata(comment, metadata);
  }
View Full Code Here

    if (matches(TokenType.SCRIPT_TAG)) {
      scriptTag = new ScriptTag(getAndAdvance());
    }
    List<Directive> directives = new ArrayList<Directive>();
    while (!matches(TokenType.EOF)) {
      CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
      if ((matchesKeyword(Keyword.IMPORT) || matchesKeyword(Keyword.EXPORT)
          || matchesKeyword(Keyword.LIBRARY) || matchesKeyword(Keyword.PART))
          && !tokenMatches(peek(), TokenType.PERIOD)
          && !tokenMatches(peek(), TokenType.LT)
          && !tokenMatches(peek(), TokenType.OPEN_PAREN)) {
View Full Code Here

  private Statement parseEmptyStatement() {
    return new EmptyStatement(getAndAdvance());
  }

  private EnumConstantDeclaration parseEnumConstantDeclaration() {
    CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
    SimpleIdentifier name;
    if (matchesIdentifier()) {
      name = parseSimpleIdentifier();
    } else {
      name = createSyntheticIdentifier();
    }
    return new EnumConstantDeclaration(
        commentAndMetadata.getComment(),
        commentAndMetadata.getMetadata(),
        name);
  }
View Full Code Here

      Token forKeyword = expectKeyword(Keyword.FOR);
      Token leftParenthesis = expect(TokenType.OPEN_PAREN);
      VariableDeclarationList variableList = null;
      Expression initialization = null;
      if (!matches(TokenType.SEMICOLON)) {
        CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
        if (matchesIdentifier() && tokenMatchesKeyword(peek(), Keyword.IN)) {
          List<VariableDeclaration> variables = new ArrayList<VariableDeclaration>();
          SimpleIdentifier variableName = parseSimpleIdentifier();
          variables.add(new VariableDeclaration(null, null, variableName, null, null));
          variableList = new VariableDeclarationList(
              commentAndMetadata.getComment(),
              commentAndMetadata.getMetadata(),
              null,
              null,
              variables);
        } else if (isInitializedVariableDeclaration()) {
          variableList = parseVariableDeclarationListAfterMetadata(commentAndMetadata);
        } else {
          initialization = parseExpression();
        }
        if (matchesKeyword(Keyword.IN)) {
          DeclaredIdentifier loopVariable = null;
          SimpleIdentifier identifier = null;
          if (variableList == null) {
            // We found: <expression> 'in'
            reportErrorForCurrentToken(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH);
          } else {
            NodeList<VariableDeclaration> variables = variableList.getVariables();
            if (variables.size() > 1) {
              reportErrorForCurrentToken(
                  ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH,
                  Integer.toString(variables.size()));
            }
            VariableDeclaration variable = variables.get(0);
            if (variable.getInitializer() != null) {
              reportErrorForCurrentToken(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH);
            }
            Token keyword = variableList.getKeyword();
            TypeName type = variableList.getType();
            if (keyword != null || type != null) {
              loopVariable = new DeclaredIdentifier(
                  commentAndMetadata.getComment(),
                  commentAndMetadata.getMetadata(),
                  keyword,
                  type,
                  variable.getName());
            } else {
              if (!commentAndMetadata.getMetadata().isEmpty()) {
                // TODO(jwren) metadata isn't allowed before the identifier in "identifier in expression",
                // add warning if commentAndMetadata has content
              }
              identifier = variable.getName();
            }
View Full Code Here

   *
   * @return the non-labeled statement that was parsed
   */
  private Statement parseNonLabeledStatement() {
    // TODO(brianwilkerson) Pass the comment and metadata on where appropriate.
    CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
    if (matches(TokenType.OPEN_CURLY_BRACKET)) {
      if (tokenMatches(peek(), TokenType.STRING)) {
        Token afterString = skipStringLiteral(currentToken.getNext());
        if (afterString != null && afterString.getType() == TokenType.COLON) {
          return new ExpressionStatement(parseExpression(), expect(TokenType.SEMICOLON));
View Full Code Here

   * </pre>
   *
   * @return the variable declaration that was parsed
   */
  private VariableDeclaration parseVariableDeclaration() {
    CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
    SimpleIdentifier name = parseSimpleIdentifier();
    Token equals = null;
    Expression initializer = null;
    if (matches(TokenType.EQ)) {
      equals = getAndAdvance();
      initializer = parseExpression();
    }
    return new VariableDeclaration(
        commentAndMetadata.getComment(),
        commentAndMetadata.getMetadata(),
        name,
        equals,
        initializer);
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.internal.parser.CommentAndMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.