Package com.google.dart.engine.ast

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


              importElement.setCombinators(buildCombinators(importDirective));
              LibraryElement importedLibraryElement = importedLibrary.getLibraryElement();
              if (importedLibraryElement != null) {
                importElement.setImportedLibrary(importedLibraryElement);
              }
              SimpleIdentifier prefixNode = ((ImportDirective) directive).getPrefix();
              if (prefixNode != null) {
                importElement.setPrefixOffset(prefixNode.getOffset());
                String prefixName = prefixNode.getName();
                PrefixElementImpl prefix = nameToPrefixMap.get(prefixName);
                if (prefix == null) {
                  prefix = new PrefixElementImpl(prefixNode);
                  nameToPrefixMap.put(prefixName, prefix);
                }
                importElement.setPrefix(prefix);
                prefixNode.setStaticElement(prefix);
              }
              directive.setElement(importElement);
              imports.add(importElement);

              if (analysisContext.computeKindOf(importedSource) != SourceKind.LIBRARY) {
View Full Code Here


  @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) {
                memberElement = lookUpSetter(
                    prefix,
                    ((ClassElement) element).getType(),
                    name.getName());
              }
            }
            if (memberElement == null) {
//              reportGetterOrSetterNotFound(prefixedIdentifier, name, element.getDisplayName());
            } else {
              name.setStaticElement(memberElement);
            }
          } else {
            // TODO(brianwilkerson) Report this error.
          }
        } else {
          if (element instanceof ClassElement) {
            ConstructorElement constructor = ((ClassElement) element).getNamedConstructor(name.getName());
            if (constructor == null) {
              // TODO(brianwilkerson) Report this error.
            } else {
              name.setStaticElement(constructor);
            }
          } else {
            // TODO(brianwilkerson) Report this error.
          }
        }
View Full Code Here

    return null;
  }

  @Override
  public Void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
    SimpleIdentifier fieldName = node.getFieldName();
    ClassElement enclosingClass = resolver.getEnclosingClass();
    FieldElement fieldElement = enclosingClass.getField(fieldName.getName());
    fieldName.setStaticElement(fieldElement);
    return null;
  }
View Full Code Here

//      }
      return null;
    }
    // look up ConstructorElement
    ConstructorElement constructor;
    SimpleIdentifier name = node.getName();
    InterfaceType interfaceType = (InterfaceType) type;
    if (name == null) {
      constructor = interfaceType.lookUpConstructor(null, definingLibrary);
    } else {
      constructor = interfaceType.lookUpConstructor(name.getName(), definingLibrary);
      name.setStaticElement(constructor);
    }
    node.setStaticElement(constructor);
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitImportDirective(ImportDirective node) {
    SimpleIdentifier prefixNode = node.getPrefix();
    if (prefixNode != null) {
      String prefixName = prefixNode.getName();
      for (PrefixElement prefixElement : definingLibrary.getPrefixes()) {
        if (prefixElement.getDisplayName().equals(prefixName)) {
          prefixNode.setStaticElement(prefixElement);
          break;
        }
      }
    }
    ImportElement importElement = node.getElement();
View Full Code Here

    return null;
  }

  @Override
  public Void visitMethodInvocation(MethodInvocation node) {
    SimpleIdentifier methodName = node.getMethodName();
    //
    // Synthetic identifiers have been already reported during parsing.
    //
    if (methodName.isSynthetic()) {
      return null;
    }
    //
    // We have a method invocation of one of two forms: 'e.m(a1, ..., an)' or 'm(a1, ..., an)'. The
    // first step is to figure out which executable is being invoked, using both the static and the
    // propagated type information.
    //
    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;
    } else if (methodName.getName().equals(FunctionElement.LOAD_LIBRARY_NAME)
        && isDeferredPrefix(target)) {
      LibraryElement importedLibrary = getImportedLibrary(target);
      methodName.setStaticElement(importedLibrary.getLoadLibraryFunction());
      return null;
    } else {
      staticType = getStaticType(target);
      propagatedType = getPropagatedType(target);
      //
      // If this method invocation is of the form 'C.m' where 'C' is a class, then we don't call
      // resolveInvokedElement(..) which walks up the class hierarchy, instead we just look for the
      // member in the type only.
      //
      ClassElementImpl typeReference = getTypeReference(target);
      if (typeReference != null) {
        staticElement = propagatedElement = resolveElement(typeReference, methodName);
      } else {
        staticElement = resolveInvokedElementWithTarget(target, staticType, methodName);
        propagatedElement = resolveInvokedElementWithTarget(target, propagatedType, methodName);
      }
    }
    staticElement = convertSetterToGetter(staticElement);
    propagatedElement = convertSetterToGetter(propagatedElement);
    //
    // Record the results.
    //
    methodName.setStaticElement(staticElement);
    methodName.setPropagatedElement(propagatedElement);
    ArgumentList argumentList = node.getArgumentList();
    if (staticElement != null) {
      ParameterElement[] parameters = computeCorrespondingParameters(argumentList, staticElement);
      if (parameters != null) {
        argumentList.setCorrespondingStaticParameters(parameters);
      }
    }
    if (propagatedElement != null) {
      ParameterElement[] parameters = computeCorrespondingParameters(
          argumentList,
          propagatedElement);
      if (parameters != null) {
        argumentList.setCorrespondingPropagatedParameters(parameters);
      }
    }
    //
    // Then check for error conditions.
    //
    ErrorCode errorCode = checkForInvocationError(target, true, staticElement);
    boolean generatedWithTypePropagation = false;
    if (enableHints && errorCode == null && staticElement == null) {
      // The method lookup may have failed because there were multiple
      // incompatible choices. In this case we don't want to generate a hint.
      if (propagatedElement == null && propagatedType instanceof UnionType) {
        // TODO(collinsn): an improvement here is to make the propagated type of the method call
        // the union of the propagated types of all possible calls.
        if (lookupMethods(target, (UnionType) propagatedType, methodName.getName()).size() > 1) {
          return null;
        }
      }

      errorCode = checkForInvocationError(target, false, propagatedElement);
      if (errorCode == StaticTypeWarningCode.UNDEFINED_METHOD) {
        ClassElement classElementContext = null;
        if (target == null) {
          classElementContext = resolver.getEnclosingClass();
        } else {
          Type type = target.getBestType();
          if (type != null) {
            if (type.getElement() instanceof ClassElement) {
              classElementContext = (ClassElement) type.getElement();
            }
          }
        }
        if (classElementContext != null) {
          subtypeManager.ensureLibraryVisited(definingLibrary);
          HashSet<ClassElement> subtypeElements = subtypeManager.computeAllSubtypes(classElementContext);
          for (ClassElement subtypeElement : subtypeElements) {
            if (subtypeElement.getMethod(methodName.getName()) != null) {
              errorCode = null;
            }
          }
        }
      }
      generatedWithTypePropagation = true;
    }
    if (errorCode == null) {
      return null;
    }
    if (errorCode == StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION) {
      resolver.reportErrorForNode(
          StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION,
          methodName,
          methodName.getName());
    } else if (errorCode == StaticTypeWarningCode.UNDEFINED_FUNCTION) {
      resolver.reportErrorForNode(
          StaticTypeWarningCode.UNDEFINED_FUNCTION,
          methodName,
          methodName.getName());
    } else if (errorCode == StaticTypeWarningCode.UNDEFINED_METHOD) {
      String targetTypeName;
      if (target == null) {
        ClassElement enclosingClass = resolver.getEnclosingClass();
        targetTypeName = enclosingClass.getDisplayName();
        ErrorCode proxyErrorCode = generatedWithTypePropagation ? HintCode.UNDEFINED_METHOD
            : StaticTypeWarningCode.UNDEFINED_METHOD;
        if (doesntHaveProxy(resolver.getEnclosingClass())) {
          resolver.reportErrorForNode(
              proxyErrorCode,
              methodName,
              methodName.getName(),
              targetTypeName);
        }

      } else {
        // ignore Function "call"
        // (if we are about to create a hint using type propagation, then we can use type
        // propagation here as well)
        Type targetType = null;
        if (!generatedWithTypePropagation) {
          targetType = getStaticType(target);
        } else {
          // choose the best type
          targetType = getPropagatedType(target);
          if (targetType == null) {
            targetType = getStaticType(target);
          }
        }
        if (targetType != null && targetType.isDartCoreFunction()
            && methodName.getName().equals(FunctionElement.CALL_METHOD_NAME)) {
          // TODO(brianwilkerson) Can we ever resolve the function being invoked?
          //resolveArgumentsToParameters(node.getArgumentList(), invokedFunction);
          return null;
        }
        targetTypeName = targetType == null ? null : targetType.getDisplayName();
        ErrorCode proxyErrorCode = generatedWithTypePropagation ? HintCode.UNDEFINED_METHOD
            : StaticTypeWarningCode.UNDEFINED_METHOD;
        if (doesntHaveProxy(targetType.getElement())) {
          resolver.reportErrorForNode(
              proxyErrorCode,
              methodName,
              methodName.getName(),
              targetTypeName);
        }
      }
    } else if (errorCode == StaticTypeWarningCode.UNDEFINED_SUPER_METHOD) {
      // Generate the type name.
      // The error code will never be generated via type propagation
      Type targetType = getStaticType(target);
      if (targetType instanceof InterfaceType && !targetType.isObject()) {
        targetType = ((InterfaceType) targetType).getSuperclass();
      }
      String targetTypeName = targetType == null ? null : targetType.getName();
      resolver.reportErrorForNode(
          StaticTypeWarningCode.UNDEFINED_SUPER_METHOD,
          methodName,
          methodName.getName(),
          targetTypeName);
    }
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitPrefixedIdentifier(PrefixedIdentifier node) {
    SimpleIdentifier prefix = node.getPrefix();
    SimpleIdentifier identifier = node.getIdentifier();
    //
    // First, check the "lib.loadLibrary" case
    //
    if (identifier.getName().equals(FunctionElement.LOAD_LIBRARY_NAME) && isDeferredPrefix(prefix)) {
      LibraryElement importedLibrary = getImportedLibrary(prefix);
      identifier.setStaticElement(importedLibrary.getLoadLibraryFunction());
      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);
      }
      if (element == null) {
        if (identifier.inSetterContext()) {
          resolver.reportErrorForNode(
              StaticWarningCode.UNDEFINED_SETTER,
              identifier,
              identifier.getName(),
              prefixElement.getName());
        } else if (node.getParent() instanceof Annotation) {
          Annotation annotation = (Annotation) node.getParent();
          resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, annotation);
          return null;
        } else {
          resolver.reportErrorForNode(
              StaticWarningCode.UNDEFINED_GETTER,
              identifier,
              identifier.getName(),
              prefixElement.getName());
        }
        return null;
      }
      if (element instanceof PropertyAccessorElement && identifier.inSetterContext()) {
        PropertyInducingElement variable = ((PropertyAccessorElement) element).getVariable();
        if (variable != null) {
          PropertyAccessorElement setter = variable.getSetter();
          if (setter != null) {
            element = setter;
          }
        }
      }
      // TODO(brianwilkerson) The prefix needs to be resolved to the element for the import that
      // defines the prefix, not the prefix's element.
      identifier.setStaticElement(element);
      // Validate annotation element.
      if (node.getParent() instanceof Annotation) {
        Annotation annotation = (Annotation) node.getParent();
        resolveAnnotationElement(annotation);
        return null;
View Full Code Here

  public Void visitPropertyAccess(PropertyAccess node) {
    Expression target = node.getRealTarget();
    if (target instanceof SuperExpression && !isSuperInValidContext((SuperExpression) target)) {
      return null;
    }
    SimpleIdentifier propertyName = node.getPropertyName();
    resolvePropertyAccess(target, propertyName);
    return null;
  }
View Full Code Here

    ClassElement enclosingClass = resolver.getEnclosingClass();
    if (enclosingClass == null) {
      // TODO(brianwilkerson) Report this error.
      return null;
    }
    SimpleIdentifier name = node.getConstructorName();
    ConstructorElement element;
    if (name == null) {
      element = enclosingClass.getUnnamedConstructor();
    } else {
      element = enclosingClass.getNamedConstructor(name.getName());
    }
    if (element == null) {
      // TODO(brianwilkerson) Report this error and decide what element to associate with the node.
      return null;
    }
    if (name != null) {
      name.setStaticElement(element);
    }
    node.setStaticElement(element);
    ArgumentList argumentList = node.getArgumentList();
    ParameterElement[] parameters = resolveArgumentsToFunction(false, argumentList, element);
    if (parameters != null) {
View Full Code Here

    InterfaceType superType = enclosingClass.getSupertype();
    if (superType == null) {
      // TODO(brianwilkerson) Report this error.
      return null;
    }
    SimpleIdentifier name = node.getConstructorName();
    String superName = name != null ? name.getName() : null;
    ConstructorElement element = superType.lookUpConstructor(superName, definingLibrary);
    if (element == null) {
      if (name != null) {
        resolver.reportErrorForNode(
            CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER,
            node,
            superType.getDisplayName(),
            name);
      } else {
        resolver.reportErrorForNode(
            CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT,
            node,
            superType.getDisplayName());
      }
      return null;
    } else {
      if (element.isFactory()) {
        resolver.reportErrorForNode(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, element);
      }
    }
    if (name != null) {
      name.setStaticElement(element);
    }
    node.setStaticElement(element);
    ArgumentList argumentList = node.getArgumentList();
    ParameterElement[] parameters = resolveArgumentsToFunction(
        isInConstConstructor(),
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.