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; }
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; }
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; }
@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(); }
public boolean isToStringMethod() { boolean hasToStringSignature = isNamed("toString") && parameters.isEmpty() && returnsString(); return isPublic() && !isStatic() && hasToStringSignature; }
public boolean isHashCodeMethod() { boolean hasHashCodeSignature = isNamed("hashCode") && parameters.isEmpty() && returnsInt(); return isPublic() && !isStatic() && hasHashCodeSignature; }
private boolean hasObjectParameter() { return parameters.size() == 1 && parameters.get(0).type().symbolType().is("java.lang.Object"); }
private boolean hasStringArrayParameter() { return parameters.size() == 1 && isParameterStringArray(); }
@Override public int getLine() { return parameters.openParenToken().getLine(); }