Package com.google.dart.engine.ast

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


    } finally {
      inFunction = wasInFunction;
    }

    FunctionBody body = node.getBody();
    SimpleIdentifier constructorName = node.getName();
    ConstructorElementImpl element = new ConstructorElementImpl(constructorName);
    if (node.getFactoryKeyword() != null) {
      element.setFactory(true);
    }
    element.setFunctions(holder.getFunctions());
    element.setLabels(holder.getLabels());
    element.setLocalVariables(holder.getLocalVariables());
    element.setParameters(holder.getParameters());
    element.setConst(node.getConstKeyword() != null);
    if (body.isAsynchronous()) {
      element.setAsynchronous(true);
    }
    if (body.isGenerator()) {
      element.setGenerator(true);
    }

    currentHolder.addConstructor(element);
    node.setElement(element);
    if (constructorName == null) {
      Identifier returnType = node.getReturnType();
      if (returnType != null) {
        element.setNameOffset(returnType.getOffset());
      }
    } else {
      constructorName.setStaticElement(element);
    }
    holder.validate();
    return null;
  }
View Full Code Here


    return null;
  }

  @Override
  public Void visitDeclaredIdentifier(DeclaredIdentifier node) {
    SimpleIdentifier variableName = node.getIdentifier();
    Token keyword = node.getKeyword();

    LocalVariableElementImpl element = new LocalVariableElementImpl(variableName);
    ForEachStatement statement = (ForEachStatement) node.getParent();
    int declarationEnd = node.getOffset() + node.getLength();
    int statementEnd = statement.getOffset() + statement.getLength();
    element.setVisibleRange(declarationEnd, statementEnd - declarationEnd - 1);
    element.setConst(matches(keyword, Keyword.CONST));
    element.setFinal(matches(keyword, Keyword.FINAL));

    currentHolder.addLocalVariable(element);
    variableName.setStaticElement(element);
    return super.visitDeclaredIdentifier(node);
  }
View Full Code Here

  @Override
  public Void visitDefaultFormalParameter(DefaultFormalParameter node) {
    ElementHolder holder = new ElementHolder();

    NormalFormalParameter normalParameter = node.getParameter();
    SimpleIdentifier parameterName = normalParameter.getIdentifier();
    ParameterElementImpl parameter;
    if (normalParameter instanceof FieldFormalParameter) {
      parameter = new DefaultFieldFormalParameterElementImpl(parameterName);
      FieldElement field = fieldMap == null ? null : fieldMap.get(parameterName.getName());
      if (field != null) {
        ((DefaultFieldFormalParameterElementImpl) parameter).setField(field);
      }
    } else {
      parameter = new DefaultParameterElementImpl(parameterName);
    }
    parameter.setConst(node.isConst());
    parameter.setFinal(node.isFinal());
    parameter.setParameterKind(node.getKind());

    // set initializer, default value range
    Expression defaultValue = node.getDefaultValue();
    if (defaultValue != null) {
      visit(holder, defaultValue);

      FunctionElementImpl initializer = new FunctionElementImpl(
          defaultValue.getBeginToken().getOffset());
      initializer.setFunctions(holder.getFunctions());
      initializer.setLabels(holder.getLabels());
      initializer.setLocalVariables(holder.getLocalVariables());
      initializer.setParameters(holder.getParameters());
      initializer.setSynthetic(true);

      parameter.setInitializer(initializer);
      parameter.setDefaultValueCode(defaultValue.toSource());
    }

    // visible range
    setParameterVisibleRange(node, parameter);

    currentHolder.addParameter(parameter);
    parameterName.setStaticElement(parameter);
    normalParameter.accept(this);
    holder.validate();
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Void visitEnumDeclaration(EnumDeclaration node) {
    SimpleIdentifier enumName = node.getName();
    ClassElementImpl enumElement = new ClassElementImpl(enumName);
    enumElement.setEnum(true);
    InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement);
    enumElement.setType(enumType);
    currentHolder.addEnum(enumElement);
    enumName.setStaticElement(enumElement);
    return super.visitEnumDeclaration(node);
  }
View Full Code Here

  }

  @Override
  public Void visitFieldFormalParameter(FieldFormalParameter node) {
    if (!(node.getParent() instanceof DefaultFormalParameter)) {
      SimpleIdentifier parameterName = node.getIdentifier();
      FieldElement field = fieldMap == null ? null : fieldMap.get(parameterName.getName());
      FieldFormalParameterElementImpl parameter = new FieldFormalParameterElementImpl(parameterName);
      parameter.setConst(node.isConst());
      parameter.setFinal(node.isFinal());
      parameter.setParameterKind(node.getKind());
      if (field != null) {
        parameter.setField(field);
      }

      currentHolder.addParameter(parameter);
      parameterName.setStaticElement(parameter);
    }
    //
    // The children of this parameter include any parameters defined on the type of this parameter.
    //
    ElementHolder holder = new ElementHolder();
View Full Code Here

      }

      FunctionBody body = expression.getBody();
      Token property = node.getPropertyKeyword();
      if (property == null) {
        SimpleIdentifier functionName = node.getName();
        FunctionElementImpl element = new FunctionElementImpl(functionName);
        element.setFunctions(holder.getFunctions());
        element.setLabels(holder.getLabels());
        element.setLocalVariables(holder.getLocalVariables());
        element.setParameters(holder.getParameters());
        if (body.isAsynchronous()) {
          element.setAsynchronous(true);
        }
        if (body.isGenerator()) {
          element.setGenerator(true);
        }

        if (inFunction) {
          Block enclosingBlock = node.getAncestor(Block.class);
          if (enclosingBlock != null) {
            int functionEnd = node.getOffset() + node.getLength();
            int blockEnd = enclosingBlock.getOffset() + enclosingBlock.getLength();
            element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
          }
        }

        currentHolder.addFunction(element);
        expression.setElement(element);
        functionName.setStaticElement(element);
      } else {
        SimpleIdentifier propertyNameNode = node.getName();
        if (propertyNameNode == null) {
          // TODO(brianwilkerson) Report this internal error.
          return null;
        }
        String propertyName = propertyNameNode.getName();
        TopLevelVariableElementImpl variable = (TopLevelVariableElementImpl) currentHolder.getTopLevelVariable(propertyName);
        if (variable == null) {
          variable = new TopLevelVariableElementImpl(node.getName().getName(), -1);
          variable.setFinal(true);
          variable.setSynthetic(true);

          currentHolder.addTopLevelVariable(variable);
        }
        if (matches(property, Keyword.GET)) {
          PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(propertyNameNode);
          getter.setFunctions(holder.getFunctions());
          getter.setLabels(holder.getLabels());
          getter.setLocalVariables(holder.getLocalVariables());
          if (body.isAsynchronous()) {
            getter.setAsynchronous(true);
          }
          if (body.isGenerator()) {
            getter.setGenerator(true);
          }

          getter.setVariable(variable);
          getter.setGetter(true);
          getter.setStatic(true);
          variable.setGetter(getter);

          currentHolder.addAccessor(getter);
          expression.setElement(getter);
          propertyNameNode.setStaticElement(getter);
        } else {
          PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(propertyNameNode);
          setter.setFunctions(holder.getFunctions());
          setter.setLabels(holder.getLabels());
          setter.setLocalVariables(holder.getLocalVariables());
          setter.setParameters(holder.getParameters());
          if (body.isAsynchronous()) {
            setter.setAsynchronous(true);
          }
          if (body.isGenerator()) {
            setter.setGenerator(true);
          }

          setter.setVariable(variable);
          setter.setSetter(true);
          setter.setStatic(true);
          variable.setSetter(setter);
          variable.setFinal(false);

          currentHolder.addAccessor(setter);
          expression.setElement(setter);
          propertyNameNode.setStaticElement(setter);
        }
      }
      holder.validate();
    }
    return null;
View Full Code Here

  @Override
  public Void visitFunctionTypeAlias(FunctionTypeAlias node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node);

    SimpleIdentifier aliasName = node.getName();
    ParameterElement[] parameters = holder.getParameters();
    TypeParameterElement[] typeParameters = holder.getTypeParameters();
    FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(aliasName);
    element.setParameters(parameters);
    element.setTypeParameters(typeParameters);

    FunctionTypeImpl type = new FunctionTypeImpl(element);
    type.setTypeArguments(createTypeParameterTypes(typeParameters));
    element.setType(type);

    currentHolder.addTypeAlias(element);
    aliasName.setStaticElement(element);
    holder.validate();
    return null;
  }
View Full Code Here

  }

  @Override
  public Void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
    if (!(node.getParent() instanceof DefaultFormalParameter)) {
      SimpleIdentifier parameterName = node.getIdentifier();
      ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
      parameter.setParameterKind(node.getKind());
      setParameterVisibleRange(node, parameter);

      currentHolder.addParameter(parameter);
      parameterName.setStaticElement(parameter);
    }
    //
    // The children of this parameter include any parameters defined on the type of this parameter.
    //
    ElementHolder holder = new ElementHolder();
View Full Code Here

  @Override
  public Void visitLabeledStatement(LabeledStatement node) {
    boolean onSwitchStatement = node.getStatement() instanceof SwitchStatement;
    for (Label label : node.getLabels()) {
      SimpleIdentifier labelName = label.getLabel();
      LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStatement, false);

      currentHolder.addLabel(element);
      labelName.setStaticElement(element);
    }
    return super.visitLabeledStatement(node);
  }
View Full Code Here

      boolean isStatic = node.isStatic();
      Token property = node.getPropertyKeyword();
      FunctionBody body = node.getBody();
      if (property == null) {
        SimpleIdentifier methodName = node.getName();
        String nameOfMethod = methodName.getName();
        if (nameOfMethod.equals(TokenType.MINUS.getLexeme())
            && node.getParameters().getParameters().size() == 0) {
          nameOfMethod = "unary-";
        }
        MethodElementImpl element = new MethodElementImpl(nameOfMethod, methodName.getOffset());
        element.setAbstract(node.isAbstract());
        element.setFunctions(holder.getFunctions());
        element.setLabels(holder.getLabels());
        element.setLocalVariables(holder.getLocalVariables());
        element.setParameters(holder.getParameters());
        element.setStatic(isStatic);
        if (body.isAsynchronous()) {
          element.setAsynchronous(true);
        }
        if (body.isGenerator()) {
          element.setGenerator(true);
        }

        currentHolder.addMethod(element);
        methodName.setStaticElement(element);
      } else {
        SimpleIdentifier propertyNameNode = node.getName();
        String propertyName = propertyNameNode.getName();
        FieldElementImpl field = (FieldElementImpl) currentHolder.getField(propertyName);
        if (field == null) {
          field = new FieldElementImpl(node.getName().getName(), -1);
          field.setFinal(true);
          field.setStatic(isStatic);
          field.setSynthetic(true);

          currentHolder.addField(field);
        }
        if (matches(property, Keyword.GET)) {
          PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(propertyNameNode);
          getter.setFunctions(holder.getFunctions());
          getter.setLabels(holder.getLabels());
          getter.setLocalVariables(holder.getLocalVariables());
          if (body.isAsynchronous()) {
            getter.setAsynchronous(true);
          }
          if (body.isGenerator()) {
            getter.setGenerator(true);
          }

          getter.setVariable(field);
          getter.setAbstract(body instanceof EmptyFunctionBody && node.getExternalKeyword() == null);
          getter.setGetter(true);
          getter.setStatic(isStatic);
          field.setGetter(getter);

          currentHolder.addAccessor(getter);
          propertyNameNode.setStaticElement(getter);
        } else {
          PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(propertyNameNode);
          setter.setFunctions(holder.getFunctions());
          setter.setLabels(holder.getLabels());
          setter.setLocalVariables(holder.getLocalVariables());
          setter.setParameters(holder.getParameters());
          if (body.isAsynchronous()) {
            setter.setAsynchronous(true);
          }
          if (body.isGenerator()) {
            setter.setGenerator(true);
          }

          setter.setVariable(field);
          setter.setAbstract(body instanceof EmptyFunctionBody
              && !matches(node.getExternalKeyword(), Keyword.EXTERNAL));
          setter.setSetter(true);
          setter.setStatic(isStatic);
          field.setSetter(setter);
          field.setFinal(false);

          currentHolder.addAccessor(setter);
          propertyNameNode.setStaticElement(setter);
        }
      }
      holder.validate();
    } catch (Exception ex) {
      if (node.getName().getStaticElement() == null) {
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.