Package com.google.dart.engine.ast

Examples of com.google.dart.engine.ast.SimpleIdentifier


        MethodDeclaration method = (MethodDeclaration) classMember;
        if (method.isStatic()) {
          continue;
        }
        // prepare name
        SimpleIdentifier name = method.getName();
        if (name == null) {
          continue;
        }

        boolean addThisMemberToTheMap = true;

        boolean isGetter = method.isGetter();
        boolean isSetter = method.isSetter();
        boolean isOperator = method.isOperator();
        boolean isMethod = !isGetter && !isSetter && !isOperator;

        // Do lookups in the enclosing class (and the inherited member) if the member is a method or
        // a setter for StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER warning.
        if (isMethod) {
          String setterName = name.getName() + "=";
          Element enclosingElementOfSetter = null;
          ClassMember conflictingSetter = memberHashMap.get(setterName);
          if (conflictingSetter != null) {
            enclosingElementOfSetter = conflictingSetter.getElement().getEnclosingElement();
          } else {
            ExecutableElement elementFromInheritance = inheritanceManager.lookupInheritance(
                enclosingClass,
                setterName);
            if (elementFromInheritance != null) {
              enclosingElementOfSetter = elementFromInheritance.getEnclosingElement();
            }
          }
          if (enclosingElementOfSetter != null) {
            // report problem
            errorReporter.reportErrorForNode(
                StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER,
                name,
                enclosingClass.getDisplayName(),
                name.getName(),
                enclosingElementOfSetter.getDisplayName());
            foundError |= true;
            addThisMemberToTheMap = false;
          }
        } else if (isSetter) {
          String methodName = name.getName();
          ClassMember conflictingMethod = memberHashMap.get(methodName);
          if (conflictingMethod != null && conflictingMethod instanceof MethodDeclaration
              && !((MethodDeclaration) conflictingMethod).isGetter()) {
            // report problem
            errorReporter.reportErrorForNode(
                StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2,
                name,
                enclosingClass.getDisplayName(),
                name.getName());
            foundError |= true;
            addThisMemberToTheMap = false;
          }
        }

        // Finally, add this member into the HashMap.
        if (addThisMemberToTheMap) {
          if (method.isSetter()) {
            memberHashMap.put(name.getName() + "=", method);
          } else {
            memberHashMap.put(name.getName(), method);
          }
        }
      }
    }
    return foundError;
View Full Code Here


  private boolean checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node) {
    if (!node.isStatic()) {
      return false;
    }
    // prepare name
    SimpleIdentifier nameNode = node.getName();
    if (nameNode == null) {
      return false;
    }
    String name = nameNode.getName();
    // prepare enclosing type
    if (enclosingClass == null) {
      return false;
    }
    InterfaceType enclosingType = enclosingClass.getType();
View Full Code Here

  private boolean checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node) {
    if (!node.isStatic()) {
      return false;
    }
    // prepare name
    SimpleIdentifier nameNode = node.getName();
    if (nameNode == null) {
      return false;
    }
    String name = nameNode.getName();
    // prepare enclosing type
    if (enclosingClass == null) {
      return false;
    }
    InterfaceType enclosingType = enclosingClass.getType();
View Full Code Here

   */
  private static ExecutableElement createSyntheticExecutableElement(
      ExecutableElement[] elementArrayToMerge, String name, int numOfRequiredParameters,
      int numOfPositionalParameters, String... namedParameters) {
    DynamicTypeImpl dynamicType = DynamicTypeImpl.getInstance();
    SimpleIdentifier nameIdentifier = new SimpleIdentifier(new StringToken(
        TokenType.IDENTIFIER,
        name,
        0));
    ExecutableElementImpl executable;
    if (elementArrayToMerge[0] instanceof MethodElement) {
View Full Code Here

  @Override
  public Void visitFunctionDeclaration(FunctionDeclaration node) {
    ExecutableElement outerFunction = enclosingFunction;
    try {
      SimpleIdentifier functionName = node.getName();
      enclosingFunction = (ExecutableElement) functionName.getStaticElement();
      super.visitFunctionDeclaration(node);
    } finally {
      enclosingFunction = outerFunction;
    }
    return null;
View Full Code Here

      expression = ((ParenthesizedExpression) expression).getExpression();
    }
    if (!(expression instanceof SimpleIdentifier)) {
      return null;
    }
    SimpleIdentifier identifier = (SimpleIdentifier) expression;
    Element element = identifier.getStaticElement();
    if (!(element instanceof VariableElement)) {
      return null;
    }
    ElementKind kind = element.getKind();
    if (kind == ElementKind.LOCAL_VARIABLE) {
View Full Code Here

    // while visiting the iterator.
    //
    Expression iterator = node.getIterator();
    safelyVisit(iterator);
    DeclaredIdentifier loopVariable = node.getLoopVariable();
    SimpleIdentifier identifier = node.getIdentifier();
    safelyVisit(loopVariable);
    safelyVisit(identifier);
    Statement body = node.getBody();
    if (body != null) {
      overrideManager.enterScope();
      try {
        if (loopVariable != null && iterator != null) {
          LocalVariableElement loopElement = loopVariable.getElement();
          if (loopElement != null) {
            Type iteratorElementType = getIteratorElementType(iterator);
            overrideVariable(loopElement, iteratorElementType, true);
            recordPropagatedType(loopVariable.getIdentifier(), iteratorElementType);
          }
        } else if (identifier != null && iterator != null) {
          Element identifierElement = identifier.getStaticElement();
          if (identifierElement instanceof VariableElement) {
            Type iteratorElementType = getIteratorElementType(iterator);
            overrideVariable((VariableElement) identifierElement, iteratorElementType, true);
            recordPropagatedType(identifier, iteratorElementType);
          }
View Full Code Here

  }

  @Override
  public Void visitCatchClause(CatchClause node) {
    super.visitCatchClause(node);
    SimpleIdentifier exception = node.getExceptionParameter();
    if (exception != null) {
      // If an 'on' clause is provided the type of the exception parameter is the type in the 'on'
      // clause. Otherwise, the type of the exception parameter is 'Object'.
      TypeName exceptionTypeName = node.getExceptionType();
      Type exceptionType;
      if (exceptionTypeName == null) {
        exceptionType = getTypeProvider().getDynamicType();
      } else {
        exceptionType = getType(exceptionTypeName);
      }
      recordType(exception, exceptionType);
      Element element = exception.getStaticElement();
      if (element instanceof VariableElementImpl) {
        ((VariableElementImpl) element).setType(exceptionType);
      } else {
        // TODO(brianwilkerson) Report the internal error
      }
    }
    SimpleIdentifier stackTrace = node.getStackTraceParameter();
    if (stackTrace != null) {
      recordType(stackTrace, getTypeProvider().getStackTraceType());
    }
    return null;
  }
View Full Code Here

      if (typeName instanceof PrefixedIdentifier && parent instanceof ConstructorName
          && argumentList == null) {
        ConstructorName name = (ConstructorName) parent;
        if (name.getName() == null) {
          PrefixedIdentifier prefixedIdentifier = (PrefixedIdentifier) typeName;
          SimpleIdentifier prefix = prefixedIdentifier.getPrefix();
          element = getNameScope().lookup(prefix, getDefiningLibrary());
          if (element instanceof PrefixElement) {
            if (parent.getParent() instanceof InstanceCreationExpression
                && ((InstanceCreationExpression) parent.getParent()).isConst()) {
              // If, if this is a const expression, then generate a
              // CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
              reportErrorForNode(
                  CompileTimeErrorCode.CONST_WITH_NON_TYPE,
                  prefixedIdentifier.getIdentifier(),
                  prefixedIdentifier.getIdentifier().getName());
            } else {
              // Else, if this expression is a new expression, report a NEW_WITH_NON_TYPE warning.
              reportErrorForNode(
                  StaticWarningCode.NEW_WITH_NON_TYPE,
                  prefixedIdentifier.getIdentifier(),
                  prefixedIdentifier.getIdentifier().getName());
            }
            setElement(prefix, element);
            return null;
          } else if (element != null) {
            //
            // Rewrite the constructor name. The parser, when it sees a constructor named "a.b",
            // cannot tell whether "a" is a prefix and "b" is a class name, or whether "a" is a
            // class name and "b" is a constructor name. It arbitrarily chooses the former, but
            // in this case was wrong.
            //
            name.setName(prefixedIdentifier.getIdentifier());
            name.setPeriod(prefixedIdentifier.getPeriod());
            node.setName(prefix);
            typeName = prefix;
          }
        }
      }
    }
    // check element
    boolean elementValid = !(element instanceof MultiplyDefinedElement);
    if (elementValid && !(element instanceof ClassElement)
        && isTypeNameInInstanceCreationExpression(node)) {
      SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
      InstanceCreationExpression creation = (InstanceCreationExpression) node.getParent().getParent();
      if (creation.isConst()) {
        if (element == null) {
          reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, typeName);
        } else {
          reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, typeName);
        }
        elementValid = false;
      } else {
        if (element != null) {
          reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, typeName);
          elementValid = false;
        }
      }
    }
    if (elementValid && element == null) {
      // We couldn't resolve the type name.
      // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE
      // from the ErrorVerifier, so that we don't have two errors on a built in identifier being
      // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifierAsType().
      SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
      RedirectingConstructorKind redirectingConstructorKind;
      if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) {
        reportErrorForNode(
            CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE,
            typeName,
            typeName.getName());
      } else if (typeNameSimple.getName().equals("boolean")) {
        reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple);
      } else if (isTypeNameInCatchClause(node)) {
        reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, typeName.getName());
      } else if (isTypeNameInAsExpression(node)) {
        reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, typeName.getName());
View Full Code Here

      if (typeName instanceof SimpleIdentifier) {
        ((SimpleIdentifier) typeName).setStaticElement(element);
      } else if (typeName instanceof PrefixedIdentifier) {
        PrefixedIdentifier identifier = (PrefixedIdentifier) typeName;
        identifier.getIdentifier().setStaticElement(element);
        SimpleIdentifier prefix = identifier.getPrefix();
        Element prefixElement = getNameScope().lookup(prefix, getDefiningLibrary());
        if (prefixElement != null) {
          prefix.setStaticElement(prefixElement);
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.ast.SimpleIdentifier

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.