Ejemplo n.º 1
0
  public MethodTreeImpl(
      @Nullable TypeTree returnType,
      IdentifierTree simpleName,
      FormalParametersListTreeImpl parameters,
      @Nullable SyntaxToken throwsToken,
      ListTree<TypeTree> throwsClauses,
      @Nullable BlockTree block,
      @Nullable SyntaxToken semicolonToken) {

    super(returnType == null ? Kind.CONSTRUCTOR : Kind.METHOD);

    this.typeParameters = new TypeParameterListTreeImpl();
    this.modifiers = null;
    this.returnType = returnType;
    this.simpleName = Preconditions.checkNotNull(simpleName);
    this.parameters = Preconditions.checkNotNull(parameters);
    this.openParenToken = parameters.openParenToken();
    this.closeParenToken = parameters.closeParenToken();
    this.block = block;
    this.semicolonToken = semicolonToken;
    this.throwsToken = throwsToken;
    this.throwsClauses = Preconditions.checkNotNull(throwsClauses);
    this.defaultToken = null;
    this.defaultValue = null;
  }
Ejemplo n.º 2
0
 public MethodTreeImpl(
     FormalParametersListTreeImpl parameters,
     @Nullable SyntaxToken defaultToken,
     @Nullable ExpressionTree defaultValue) {
   super(Kind.METHOD);
   this.typeParameters = new TypeParameterListTreeImpl();
   this.parameters = parameters;
   this.openParenToken = parameters.openParenToken();
   this.closeParenToken = parameters.closeParenToken();
   this.block = null;
   this.throwsToken = null;
   this.throwsClauses = QualifiedIdentifierListTreeImpl.emptyList();
   this.defaultToken = defaultToken;
   this.defaultValue = defaultValue;
 }
Ejemplo n.º 3
0
 private boolean isParameterStringArray() {
   VariableTree variableTree = parameters.get(0);
   boolean result = false;
   if (variableTree.type().is(Tree.Kind.ARRAY_TYPE)) {
     ArrayTypeTree arrayTypeTree = (ArrayTypeTree) variableTree.type();
     result =
         arrayTypeTree.type().symbolType().isClass()
             && "String".equals(arrayTypeTree.type().symbolType().name());
   }
   return result;
 }
Ejemplo n.º 4
0
 @Override
 public Iterator<Tree> childrenIterator() {
   ImmutableList.Builder<Tree> iteratorBuilder = ImmutableList.builder();
   iteratorBuilder.add(modifiers, typeParameters);
   if (returnType != null) {
     iteratorBuilder.add(returnType);
   }
   iteratorBuilder.add(simpleName, openParenToken);
   iteratorBuilder.addAll(parameters.iterator());
   iteratorBuilder.add(closeParenToken);
   if (throwsToken != null) {
     iteratorBuilder.add(throwsToken);
     iteratorBuilder.add(throwsClauses);
   }
   if (defaultToken != null) {
     iteratorBuilder.add(defaultToken, defaultValue);
   }
   if (block != null) {
     iteratorBuilder.add(block);
   } else {
     iteratorBuilder.add(semicolonToken);
   }
   return iteratorBuilder.build().iterator();
 }
Ejemplo n.º 5
0
 public boolean isToStringMethod() {
   boolean hasToStringSignature = isNamed("toString") && parameters.isEmpty() && returnsString();
   return isPublic() && !isStatic() && hasToStringSignature;
 }
Ejemplo n.º 6
0
 public boolean isHashCodeMethod() {
   boolean hasHashCodeSignature = isNamed("hashCode") && parameters.isEmpty() && returnsInt();
   return isPublic() && !isStatic() && hasHashCodeSignature;
 }
Ejemplo n.º 7
0
 private boolean hasObjectParameter() {
   return parameters.size() == 1 && parameters.get(0).type().symbolType().is("java.lang.Object");
 }
Ejemplo n.º 8
0
 private boolean hasStringArrayParameter() {
   return parameters.size() == 1 && isParameterStringArray();
 }
Ejemplo n.º 9
0
 @Override
 public int getLine() {
   return parameters.openParenToken().getLine();
 }