Package com.google.dart.engine.element

Examples of com.google.dart.engine.element.Element


  @Override
  public Void visitCommentReference(CommentReference node) {
    Identifier identifier = node.getIdentifier();
    if (identifier instanceof SimpleIdentifier) {
      SimpleIdentifier simpleIdentifier = (SimpleIdentifier) identifier;
      Element element = resolveSimpleIdentifier(simpleIdentifier);
      if (element == null) {
        //
        // This might be a reference to an imported name that is missing the prefix.
        //
        element = findImportWithoutPrefix(simpleIdentifier);
        if (element instanceof MultiplyDefinedElement) {
          // TODO(brianwilkerson) Report this error?
          element = null;
        }
      }
      if (element == null) {
        // TODO(brianwilkerson) Report this error?
//        resolver.reportError(
//            StaticWarningCode.UNDEFINED_IDENTIFIER,
//            simpleIdentifier,
//            simpleIdentifier.getName());
      } else {
        if (element.getLibrary() == null || !element.getLibrary().equals(definingLibrary)) {
          // TODO(brianwilkerson) Report this error?
        }
        simpleIdentifier.setStaticElement(element);
        if (node.getNewKeyword() != null) {
          if (element instanceof ClassElement) {
            ConstructorElement constructor = ((ClassElement) element).getUnnamedConstructor();
            if (constructor == null) {
              // TODO(brianwilkerson) Report this error.
            } else {
              simpleIdentifier.setStaticElement(constructor);
            }
          } else {
            // TODO(brianwilkerson) Report this error.
          }
        }
      }
    } else if (identifier instanceof PrefixedIdentifier) {
      PrefixedIdentifier prefixedIdentifier = (PrefixedIdentifier) identifier;
      SimpleIdentifier prefix = prefixedIdentifier.getPrefix();
      SimpleIdentifier name = prefixedIdentifier.getIdentifier();
      Element element = resolveSimpleIdentifier(prefix);
      if (element == null) {
//        resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, prefix, prefix.getName());
      } else {
        if (element instanceof PrefixElement) {
          prefix.setStaticElement(element);
          // TODO(brianwilkerson) The prefix needs to be resolved to the element for the import that
          // defines the prefix, not the prefix's element.

          // TODO(brianwilkerson) Report this error?
          element = resolver.getNameScope().lookup(identifier, definingLibrary);
          name.setStaticElement(element);
          return null;
        }
        LibraryElement library = element.getLibrary();
        if (library == null) {
          // TODO(brianwilkerson) We need to understand how the library could ever be null.
          AnalysisEngine.getInstance().getLogger().logError(
              "Found element with null library: " + element.getName());
        } else if (!library.equals(definingLibrary)) {
          // TODO(brianwilkerson) Report this error.
        }
        name.setStaticElement(element);
        if (node.getNewKeyword() == null) {
          if (element instanceof ClassElement) {
            Element memberElement = lookupGetterOrMethod(
                ((ClassElement) element).getType(),
                name.getName());
            if (memberElement == null) {
              memberElement = ((ClassElement) element).getNamedConstructor(name.getName());
              if (memberElement == null) {
View Full Code Here


    //
    Expression target = node.getRealTarget();
    if (target instanceof SuperExpression && !isSuperInValidContext((SuperExpression) target)) {
      return null;
    }
    Element staticElement;
    Element propagatedElement;
    Type staticType = null;
    Type propagatedType = null;
    if (target == null) {
      staticElement = resolveInvokedElement(methodName);
      propagatedElement = null;
View Full Code Here

      return null;
    }
    //
    // Check to see whether the prefix is really a prefix.
    //
    Element prefixElement = prefix.getStaticElement();
    if (prefixElement instanceof PrefixElement) {
      Element element = resolver.getNameScope().lookup(node, definingLibrary);
      if (element == null && identifier.inSetterContext()) {
        element = resolver.getNameScope().lookup(
            new SyntheticIdentifier(node.getName() + "="),
            definingLibrary);
      }
View Full Code Here

      return null;
    }
    //
    // Otherwise, the node should be resolved.
    //
    Element element = resolveSimpleIdentifier(node);
    ClassElement enclosingClass = resolver.getEnclosingClass();
    if (isFactoryConstructorReturnType(node) && element != enclosingClass) {
      resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS, node);
    } else if (isConstructorReturnType(node) && element != enclosingClass) {
      resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node);
View Full Code Here

  private void addAnnotations(ArrayList<ElementAnnotationImpl> annotationList,
      NodeList<Annotation> annotations) {
    int annotationCount = annotations.size();
    for (int i = 0; i < annotationCount; i++) {
      Annotation annotation = annotations.get(i);
      Element resolvedElement = annotation.getElement();
      if (resolvedElement != null) {
        ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(resolvedElement);
        annotation.setElementAnnotation(elementAnnotation);
        annotationList.add(elementAnnotation);
      }
View Full Code Here

   *
   * @param identifier the identifier that might have been imported using a prefix
   * @return the element that was found
   */
  private Element findImportWithoutPrefix(SimpleIdentifier identifier) {
    Element element = null;
    Scope nameScope = resolver.getNameScope();
    for (ImportElement importElement : definingLibrary.getImports()) {
      PrefixElement prefixElement = importElement.getPrefix();
      if (prefixElement != null) {
        Identifier prefixedIdentifier = new SyntheticIdentifier(prefixElement.getName() + "."
            + identifier.getName());
        Element importedElement = nameScope.lookup(prefixedIdentifier, definingLibrary);
        if (importedElement != null) {
          if (element == null) {
            element = importedElement;
          } else {
            element = MultiplyDefinedElementImpl.fromElements(
View Full Code Here

   */
  private boolean isDeferredPrefix(Expression expression) {
    if (!(expression instanceof SimpleIdentifier)) {
      return false;
    }
    Element element = ((SimpleIdentifier) expression).getStaticElement();
    if (!(element instanceof PrefixElement)) {
      return false;
    }
    PrefixElement prefixElement = (PrefixElement) element;
    ImportElement[] imports = prefixElement.getEnclosingElement().getImportsWithPrefix(
View Full Code Here

    ConstructorElement constructor = null;
    //
    // CONST or Class(args)
    //
    if (nameNode1 != null && nameNode2 == null && nameNode3 == null) {
      Element element1 = nameNode1.getStaticElement();
      // CONST
      if (element1 instanceof PropertyAccessorElement) {
        resolveAnnotationElementGetter(annotation, (PropertyAccessorElement) element1);
        return;
      }
      // Class(args)
      if (element1 instanceof ClassElement) {
        ClassElement classElement = (ClassElement) element1;
        constructor = new InterfaceTypeImpl(classElement).lookUpConstructor(null, definingLibrary);
      }
    }
    //
    // prefix.CONST or prefix.Class() or Class.CONST or Class.constructor(args)
    //
    if (nameNode1 != null && nameNode2 != null && nameNode3 == null) {
      Element element1 = nameNode1.getStaticElement();
      Element element2 = nameNode2.getStaticElement();
      // Class.CONST - not resolved yet
      if (element1 instanceof ClassElement) {
        ClassElement classElement = (ClassElement) element1;
        element2 = classElement.lookUpGetter(nameNode2.getName(), definingLibrary);
      }
      // prefix.CONST or Class.CONST
      if (element2 instanceof PropertyAccessorElement) {
        nameNode2.setStaticElement(element2);
        annotation.setElement(element2);
        resolveAnnotationElementGetter(annotation, (PropertyAccessorElement) element2);
        return;
      }
      // prefix.Class()
      if (element2 instanceof ClassElement) {
        ClassElement classElement = (ClassElement) element2;
        constructor = classElement.getUnnamedConstructor();
      }
      // Class.constructor(args)
      if (element1 instanceof ClassElement) {
        ClassElement classElement = (ClassElement) element1;
        constructor = new InterfaceTypeImpl(classElement).lookUpConstructor(
            nameNode2.getName(),
            definingLibrary);
        nameNode2.setStaticElement(constructor);
      }
    }
    //
    // prefix.Class.CONST or prefix.Class.constructor(args)
    //
    if (nameNode1 != null && nameNode2 != null && nameNode3 != null) {
      Element element2 = nameNode2.getStaticElement();
      // element2 should be ClassElement
      if (element2 instanceof ClassElement) {
        ClassElement classElement = (ClassElement) element2;
        String name3 = nameNode3.getName();
        // prefix.Class.CONST
View Full Code Here

      } else {
        names = ((ShowCombinator) combinator).getShownNames();
      }
      for (SimpleIdentifier name : names) {
        String nameStr = name.getName();
        Element element = namespace.get(nameStr);
        if (element == null) {
          element = namespace.get(nameStr + "=");
        }
        if (element != null) {
          // Ensure that the name always resolves to a top-level variable
View Full Code Here

   * @param classElement the class element
   * @param nameNode the member name node
   */
  private Element resolveElement(ClassElementImpl classElement, SimpleIdentifier nameNode) {
    String name = nameNode.getName();
    Element element = classElement.getMethod(name);
    if (element == null && nameNode.inSetterContext()) {
      element = classElement.getSetter(name);
    }
    if (element == null && nameNode.inGetterContext()) {
      element = classElement.getGetter(name);
    }
    if (element != null && element.isAccessibleIn(definingLibrary)) {
      return element;
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.element.Element

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.