Exemplo n.º 1
0
  @Override
  public Void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
    SimpleIdentifier parameterName = node.getIdentifier();
    ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
    parameter.setParameterKind(node.getKind());

    currentHolder.addParameter(parameter);
    parameterName.setElement(parameter);
    return null;
  }
Exemplo n.º 2
0
  @Override
  public Void visitSimpleFormalParameter(SimpleFormalParameter node) {
    SimpleIdentifier parameterName = node.getIdentifier();
    ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
    parameter.setConst(node.isConst());
    parameter.setFinal(node.isFinal());
    parameter.setParameterKind(node.getKind());

    currentHolder.addParameter(parameter);
    parameterName.setElement(parameter);
    return null;
  }
Exemplo n.º 3
0
  @Override
  public Void visitSimpleFormalParameter(SimpleFormalParameter node) {
    if (!(node.getParent() instanceof DefaultFormalParameter)) {
      SimpleIdentifier parameterName = node.getIdentifier();
      ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
      parameter.setConst(node.isConst());
      parameter.setFinal(node.isFinal());
      parameter.setParameterKind(node.getKind());
      setParameterVisibleRange(node, parameter);

      currentHolder.addParameter(parameter);
      parameterName.setStaticElement(parameter);
    }
    return super.visitSimpleFormalParameter(node);
  }
Exemplo n.º 4
0
  @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();
    visitChildren(holder, node);
    ((ParameterElementImpl) node.getElement()).setParameters(holder.getParameters());
    holder.validate();
    return null;
  }
Exemplo n.º 5
0
  @Override
  public Void visitDefaultFormalParameter(DefaultFormalParameter node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node.getDefaultValue());

    FunctionElementImpl initializer = new FunctionElementImpl();
    initializer.setFunctions(holder.getFunctions());
    initializer.setLabels(holder.getLabels());
    initializer.setLocalVariables(holder.getVariables());
    initializer.setParameters(holder.getParameters());

    SimpleIdentifier parameterName = node.getParameter().getIdentifier();
    ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
    parameter.setConst(node.isConst());
    parameter.setFinal(node.isFinal());
    parameter.setInitializer(initializer);
    parameter.setParameterKind(node.getKind());

    currentHolder.addParameter(parameter);
    parameterName.setElement(parameter);
    return null;
  }
Exemplo n.º 6
0
  @Override
  public Void visitDefaultFormalParameter(DefaultFormalParameter node) {
    ElementHolder holder = new ElementHolder();

    SimpleIdentifier parameterName = node.getParameter().getIdentifier();
    ParameterElementImpl parameter;
    if (node.getParameter() instanceof FieldFormalParameter) {
      parameter = new DefaultFieldFormalParameterElementImpl(parameterName);
    } 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.setDefaultValueRange(defaultValue.getOffset(), defaultValue.getLength());
    }

    // visible range
    setParameterVisibleRange(node, parameter);

    currentHolder.addParameter(parameter);
    parameterName.setStaticElement(parameter);
    node.getParameter().accept(this);
    holder.validate();
    return null;
  }
Exemplo n.º 7
0
 /** Sets the visible source range for formal parameter. */
 private void setParameterVisibleRange(FormalParameter node, ParameterElementImpl element) {
   FunctionBody body = getFunctionBody(node);
   if (body != null) {
     element.setVisibleRange(body.getOffset(), body.getLength());
   }
 }
Exemplo n.º 8
0
  @Override
  public Void visitVariableDeclaration(VariableDeclaration node) {
    Token keyword = ((VariableDeclarationList) node.getParent()).getKeyword();
    boolean isConst = matches(keyword, Keyword.CONST);
    boolean isFinal = matches(keyword, Keyword.FINAL);
    boolean hasInitializer = node.getInitializer() != null;

    VariableElementImpl element;
    if (inFieldContext) {
      SimpleIdentifier fieldName = node.getName();
      FieldElementImpl field;
      if (isConst && hasInitializer) {
        field = new ConstFieldElementImpl(fieldName);
      } else {
        field = new FieldElementImpl(fieldName);
      }
      element = field;

      currentHolder.addField(field);
      fieldName.setStaticElement(field);
    } else if (inFunction) {
      SimpleIdentifier variableName = node.getName();
      LocalVariableElementImpl variable;
      if (isConst && hasInitializer) {
        variable = new ConstLocalVariableElementImpl(variableName);
      } else {
        variable = new LocalVariableElementImpl(variableName);
      }
      element = variable;
      Block enclosingBlock = node.getAncestor(Block.class);
      int functionEnd = node.getOffset() + node.getLength();
      int blockEnd = enclosingBlock.getOffset() + enclosingBlock.getLength();
      // TODO(brianwilkerson) This isn't right for variables declared in a for loop.
      variable.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);

      currentHolder.addLocalVariable(variable);
      variableName.setStaticElement(element);
    } else {
      SimpleIdentifier variableName = node.getName();
      TopLevelVariableElementImpl variable;
      if (isConst && hasInitializer) {
        variable = new ConstTopLevelVariableElementImpl(variableName);
      } else {
        variable = new TopLevelVariableElementImpl(variableName);
      }
      element = variable;

      currentHolder.addTopLevelVariable(variable);
      variableName.setStaticElement(element);
    }

    element.setConst(isConst);
    element.setFinal(isFinal);
    if (hasInitializer) {
      ElementHolder holder = new ElementHolder();
      boolean wasInFieldContext = inFieldContext;
      inFieldContext = false;
      try {
        visit(holder, node.getInitializer());
      } finally {
        inFieldContext = wasInFieldContext;
      }
      FunctionElementImpl initializer =
          new FunctionElementImpl(node.getInitializer().getBeginToken().getOffset());
      initializer.setFunctions(holder.getFunctions());
      initializer.setLabels(holder.getLabels());
      initializer.setLocalVariables(holder.getLocalVariables());
      initializer.setSynthetic(true);
      element.setInitializer(initializer);
      holder.validate();
    }
    if (element instanceof PropertyInducingElementImpl) {
      PropertyInducingElementImpl variable = (PropertyInducingElementImpl) element;

      if (inFieldContext) {
        ((FieldElementImpl) variable)
            .setStatic(
                matches(
                    ((FieldDeclaration) node.getParent().getParent()).getStaticKeyword(),
                    Keyword.STATIC));
      }

      PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(variable);
      getter.setGetter(true);
      getter.setStatic(variable.isStatic());

      currentHolder.addAccessor(getter);
      variable.setGetter(getter);

      if (!isFinal) {
        PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(variable);
        setter.setSetter(true);
        setter.setStatic(variable.isStatic());
        ParameterElementImpl parameter =
            new ParameterElementImpl("_" + variable.getName(), variable.getNameOffset());
        parameter.setSynthetic(true);
        parameter.setParameterKind(ParameterKind.REQUIRED);
        setter.setParameters(new ParameterElement[] {parameter});

        currentHolder.addAccessor(setter);
        variable.setSetter(setter);
      }
    }
    return null;
  }