Package com.google.dart.engine.element

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


   * @return {@code true} if and only if a hint code is generated on the passed node
   * @see HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE
   */
  @SuppressWarnings("unused")
  private boolean checkForOverrideEqualsButNotHashCode(ClassDeclaration node) {
    ClassElement classElement = node.getElement();
    if (classElement == null) {
      return false;
    }
    MethodElement equalsOperatorMethodElement = classElement.getMethod(TokenType.EQ_EQ.getLexeme());
    if (equalsOperatorMethodElement != null) {
      PropertyAccessorElement hashCodeElement = classElement.getGetter(HASHCODE_GETTER_NAME);
      if (hashCodeElement == null) {
        errorReporter.reportErrorForNode(
            HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE,
            node.getName(),
            classElement.getDisplayName());
        return true;
      }
    }
    return false;
  }
View Full Code Here


   * @see #computeLongestInheritancePathToObject(Type)
   * @see #getLeastUpperBound(Type)
   */
  private static int computeLongestInheritancePathToObject(InterfaceType type, int depth,
      HashSet<ClassElement> visitedClasses) {
    ClassElement classElement = type.getElement();
    // Object case
    if (classElement.getSupertype() == null || visitedClasses.contains(classElement)) {
      return depth;
    }
    int longestPath = 1;
    try {
      visitedClasses.add(classElement);
      InterfaceType[] superinterfaces = classElement.getInterfaces();
      int pathLength;
      if (superinterfaces.length > 0) {
        // loop through each of the superinterfaces recursively calling this method and keeping track
        // of the longest path to return
        for (InterfaceType superinterface : superinterfaces) {
          pathLength = computeLongestInheritancePathToObject(
              superinterface,
              depth + 1,
              visitedClasses);
          if (pathLength > longestPath) {
            longestPath = pathLength;
          }
        }
      }
      // finally, perform this same check on the super type
      // TODO(brianwilkerson) Does this also need to add in the number of mixin classes?
      InterfaceType supertype = classElement.getSupertype();
      pathLength = computeLongestInheritancePathToObject(supertype, depth + 1, visitedClasses);
      if (pathLength > longestPath) {
        longestPath = pathLength;
      }
    } finally {
View Full Code Here

    return super.visitBinaryExpression(node);
  }

  @Override
  public Void visitClassDeclaration(ClassDeclaration node) {
    ClassElement element = node.getElement();
    enterScope(element);
    try {
      recordElementDefinition(element, IndexConstants.DEFINES_CLASS);
      {
        ExtendsClause extendsClause = node.getExtendsClause();
        if (extendsClause != null) {
          TypeName superclassNode = extendsClause.getSuperclass();
          recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY);
        } else {
          InterfaceType superType = element.getSupertype();
          if (superType != null) {
            ClassElement objectElement = superType.getElement();
            recordRelationship(
                objectElement,
                IndexConstants.IS_EXTENDED_BY,
                createLocationFromOffset(node.getName().getOffset(), 0));
          }
View Full Code Here

    }
  }

  @Override
  public Void visitClassTypeAlias(ClassTypeAlias node) {
    ClassElement element = node.getElement();
    enterScope(element);
    try {
      recordElementDefinition(element, IndexConstants.DEFINES_CLASS_ALIAS);
      {
        TypeName superclassNode = node.getSuperclass();
View Full Code Here

        this);
  }

  @Override
  public InterfaceType[] getInterfaces() {
    ClassElement classElement = getElement();
    InterfaceType[] interfaces = classElement.getInterfaces();
    TypeParameterElement[] typeParameters = classElement.getTypeParameters();
    Type[] parameterTypes = classElement.getType().getTypeArguments();
    if (typeParameters.length == 0) {
      return interfaces;
    }
    int count = interfaces.length;
    InterfaceType[] typedInterfaces = new InterfaceType[count];
View Full Code Here

    return members;
  }

  @Override
  public InterfaceType[] getMixins() {
    ClassElement classElement = getElement();
    InterfaceType[] mixins = classElement.getMixins();
    TypeParameterElement[] typeParameters = classElement.getTypeParameters();
    Type[] parameterTypes = classElement.getType().getTypeArguments();
    if (typeParameters.length == 0) {
      return mixins;
    }
    int count = mixins.length;
    InterfaceType[] typedMixins = new InterfaceType[count];
View Full Code Here

        this);
  }

  @Override
  public InterfaceType getSuperclass() {
    ClassElement classElement = getElement();
    InterfaceType supertype = classElement.getSupertype();
    if (supertype == null) {
      return null;
    }
    Type[] typeParameters = classElement.getType().getTypeArguments();
    if (typeArguments.length == 0 || typeArguments.length != typeParameters.length) {
      return supertype;
    }
    return supertype.substitute(typeArguments, typeParameters);
  }
View Full Code Here

    return getElement().getTypeParameters();
  }

  @Override
  public int hashCode() {
    ClassElement element = getElement();
    if (element == null) {
      return 0;
    }
    return element.hashCode();
  }
View Full Code Here

    return element.hashCode();
  }

  @Override
  public boolean isDartCoreFunction() {
    ClassElement element = getElement();
    if (element == null) {
      return false;
    }
    return element.getName().equals("Function") && element.getLibrary().isDartCore();
  }
View Full Code Here

  @Override
  public boolean isDirectSupertypeOf(InterfaceType type) {
    InterfaceType i = this;
    InterfaceType j = type;
    ClassElement jElement = j.getElement();
    InterfaceType supertype = jElement.getSupertype();
    //
    // If J has no direct supertype then it is Object, and Object has no direct supertypes.
    //
    if (supertype == null) {
      return false;
    }
    //
    // I is listed in the extends clause of J.
    //
    Type[] jArgs = j.getTypeArguments();
    Type[] jVars = jElement.getType().getTypeArguments();
    supertype = supertype.substitute(jArgs, jVars);
    if (supertype.equals(i)) {
      return true;
    }
    //
    // I is listed in the implements clause of J.
    //
    for (InterfaceType interfaceType : jElement.getInterfaces()) {
      interfaceType = interfaceType.substitute(jArgs, jVars);
      if (interfaceType.equals(i)) {
        return true;
      }
    }
    //
    // I is listed in the with clause of J.
    //
    for (InterfaceType mixinType : jElement.getMixins()) {
      mixinType = mixinType.substitute(jArgs, jVars);
      if (mixinType.equals(i)) {
        return true;
      }
    }
View Full Code Here

TOP

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

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.