Beispiel #1
0
  @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;
  }
Beispiel #2
0
 @Override
 public Void visitMethodDeclaration(MethodDeclaration node) {
   visit(node.getExternalKeyword(), " ");
   visit(node.getModifierKeyword(), " ");
   visit(node.getReturnType(), " ");
   visit(node.getPropertyKeyword(), " ");
   visit(node.getOperatorKeyword(), " ");
   visit(node.getName());
   if (!node.isGetter()) {
     visit(node.getParameters());
   }
   visit(" ", node.getBody());
   return null;
 }