コード例 #1
0
ファイル: ElementBuilder.java プロジェクト: aam/dartdev
  @Override
  public Void visitVariableDeclaration(VariableDeclaration node) {
    VariableElementImpl element;
    if (inFieldContext) {
      SimpleIdentifier fieldName = node.getName();
      element = new FieldElementImpl(fieldName);

      currentHolder.addField((FieldElementImpl) element);
      fieldName.setElement(element);
    } else {
      SimpleIdentifier variableName = node.getName();
      element = new VariableElementImpl(variableName);

      currentHolder.addVariable(element);
      variableName.setElement(element);
    }

    Token keyword = ((VariableDeclarationList) node.getParent()).getKeyword();
    boolean isFinal = matches(keyword, Keyword.FINAL);
    element.setConst(matches(keyword, Keyword.CONST));
    element.setFinal(isFinal);
    if (node.getInitializer() != null) {
      ElementHolder holder = new ElementHolder();
      boolean wasInFieldContext = inFieldContext;
      inFieldContext = false;
      try {
        visitChildren(holder, node.getInitializer());
      } finally {
        inFieldContext = wasInFieldContext;
      }
      FunctionElementImpl initializer = new FunctionElementImpl();
      initializer.setFunctions(holder.getFunctions());
      initializer.setLabels(holder.getLabels());
      initializer.setLocalVariables(holder.getVariables());
      initializer.setSynthetic(true);
      element.setInitializer(initializer);
    }
    if (inFieldContext) {
      FieldElementImpl field = (FieldElementImpl) element;
      PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(field);
      getter.setGetter(true);
      field.setGetter(getter);

      if (!isFinal) {
        PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(field);
        setter.setSetter(true);
        field.setSetter(setter);
      }

      field.setStatic(
          matches(((FieldDeclaration) node.getParent().getParent()).getKeyword(), Keyword.STATIC));
    }
    return null;
  }
コード例 #2
0
ファイル: ElementBuilder.java プロジェクト: aam/dartdev
  @Override
  public Void visitMethodDeclaration(MethodDeclaration node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node);

    Token property = node.getPropertyKeyword();
    if (property == null) {
      Identifier methodName = node.getName();
      MethodElementImpl element = new MethodElementImpl(methodName);
      Token keyword = node.getModifierKeyword();
      element.setAbstract(matches(keyword, Keyword.ABSTRACT));
      element.setFunctions(holder.getFunctions());
      element.setLabels(holder.getLabels());
      element.setLocalVariables(holder.getVariables());
      element.setParameters(holder.getParameters());
      element.setStatic(matches(keyword, Keyword.STATIC));

      currentHolder.addMethod(element);
      methodName.setElement(element);
    } else {
      Identifier propertyNameNode = node.getName();
      String propertyName = propertyNameNode.getName();
      FieldElementImpl field = (FieldElementImpl) currentHolder.getField(propertyName);
      if (field == null) {
        field = new FieldElementImpl(node.getName().getName());
        field.setFinal(true);
        field.setStatic(matches(node.getModifierKeyword(), Keyword.STATIC));

        currentHolder.addField(field);
      }
      if (matches(property, Keyword.GET)) {
        PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(propertyNameNode);
        getter.setField(field);
        getter.setGetter(true);
        field.setGetter(getter);

        currentHolder.addAccessor(getter);
        propertyNameNode.setElement(getter);
      } else {
        PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(propertyNameNode);
        setter.setField(field);
        setter.setSetter(true);
        field.setSetter(setter);
        field.setFinal(false);

        currentHolder.addAccessor(setter);
        propertyNameNode.setElement(setter);
      }
    }
    return null;
  }
コード例 #3
0
  @Override
  public Void visitMethodDeclaration(MethodDeclaration node) {
    ElementHolder holder = new ElementHolder();
    boolean wasInFunction = inFunction;
    inFunction = true;
    try {
      visitChildren(holder, node);
    } finally {
      inFunction = wasInFunction;
    }

    boolean isStatic = node.isStatic();
    Token property = node.getPropertyKeyword();
    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);

      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());
        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());

        getter.setVariable(field);
        getter.setAbstract(
            node.getBody() 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());

        setter.setVariable(field);
        setter.setAbstract(
            node.getBody() 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();
    return null;
  }