if (n1.getModifiers() != n2.getModifiers()) { return Boolean.FALSE; if (n1.getArrayCount() != n2.getArrayCount()) { return Boolean.FALSE; if (!objEquals(n1.getName(), n2.getName())) { return Boolean.FALSE; if (!nodeEquals(n1.getType(), n2.getType())) { return Boolean.FALSE; if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) { return Boolean.FALSE; if (!nodeEquals(n1.getBody(), n2.getBody())) { return Boolean.FALSE; if (!nodesEquals(n1.getParameters(), n2.getParameters())) { return Boolean.FALSE; if (!nodesEquals(n1.getThrows(), n2.getThrows())) { return Boolean.FALSE; if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) { return Boolean.FALSE;
@Override public Node visit(MethodDeclaration _n, Object _arg) { JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg); List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg); List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg); Type type_ = cloneNodes(_n.getType(), _arg); List<Parameter> parameters = visit(_n.getParameters(), _arg); List<NameExpr> throws_ = visit(_n.getThrows(), _arg); BlockStmt block = cloneNodes(_n.getBody(), _arg); Comment comment = cloneNodes(_n.getComment(), _arg); MethodDeclaration r = new MethodDeclaration( _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, typeParameters, type_, _n.getName(), parameters, _n.getArrayCount(), throws_, block ); r.setComment(comment); return r; }
@Override public Node visit(final MethodDeclaration n, final A arg) { if (n.getJavaDoc() != null) { n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); final List<AnnotationExpr> annotations = n.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.size(); i++) { final List<TypeParameter> typeParameters = n.getTypeParameters(); if (typeParameters != null) { for (int i = 0; i < typeParameters.size(); i++) { n.setType((Type) n.getType().accept(this, arg)); final List<Parameter> parameters = n.getParameters(); if (parameters != null) { for (int i = 0; i < parameters.size(); i++) { final List<NameExpr> throwz = n.getThrows(); if (throwz != null) { for (int i = 0; i < throwz.size(); i++) { if (n.getBody() != null) { n.setBody((BlockStmt) n.getBody().accept(this, arg));
public MethodDeclaration(final int modifiers, final List<AnnotationExpr> annotations, final List<TypeParameter> typeParameters, final Type type, final String name, final List<Parameter> parameters, final int arrayCount, final List<NameExpr> throws_, final BlockStmt block) { super(annotations); setModifiers(modifiers); setTypeParameters(typeParameters); setType(type); setName(name); setParameters(parameters); setArrayCount(arrayCount); setThrows(throws_); setBody(block); }
@Override public void visit(MethodDeclaration n, ExecutableElement element) { if (element.getSimpleName().toString().equals(n.getName()) && (n.getParameters() == null ? 0 : n.getParameters().size()) - (element.getParameters() == null ? 0 : element.getParameters().size()) == 0) { if (n.getBody() == null) { this.methodBody = null; } else { this.methodBody = n.getBody().toString(); } } }
/** * Adds the given parameter to the method. The list of parameters will be * initialized if it is <code>null</code>. * * @param method * method * @param parameter * parameter */ public static void addParameter(MethodDeclaration method, Parameter parameter) { List<Parameter> parameters = method.getParameters(); if (parameters == null) { parameters = new ArrayList<Parameter>(); method.setParameters(parameters); } parameters.add(parameter); }
@Override public void visit(final MethodDeclaration n, final A arg) { visitComment(n.getComment(), arg); if (n.getJavaDoc() != null) { n.getJavaDoc().accept(this, arg); } if (n.getAnnotations() != null) { for (final AnnotationExpr a : n.getAnnotations()) { a.accept(this, arg); } } if (n.getTypeParameters() != null) { for (final TypeParameter t : n.getTypeParameters()) { t.accept(this, arg); } } n.getType().accept(this, arg); if (n.getParameters() != null) { for (final Parameter p : n.getParameters()) { p.accept(this, arg); } } if (n.getThrows() != null) { for (final NameExpr name : n.getThrows()) { name.accept(this, arg); } } if (n.getBody() != null) { n.getBody().accept(this, arg); } }
private NodeAndImports<MethodDeclaration> createPrimaryKeyHashCode(Collection<FieldDescriptor> primaryKeyDescriptors) { final MethodDeclaration hashCode = new MethodDeclaration(ModifierSet.PUBLIC, new PrimitiveType(PrimitiveType.Primitive.Int), "hashCode"); hashCode.setAnnotations(Collections.<AnnotationExpr>singletonList(new MarkerAnnotationExpr(new NameExpr("Override")))); final List<Expression> ctorArgs = new ArrayList<Expression>(); ctorArgs.add(new IntegerLiteralExpr("17")); ctorArgs.add(new IntegerLiteralExpr("37")); Expression hashCodeExpr = new ObjectCreationExpr(null, new ClassOrInterfaceType("HashCodeBuilder"), ctorArgs); for (FieldDescriptor f : primaryKeyDescriptors) { final List<Expression> args = new ArrayList<Expression>(); args.add(new FieldAccessExpr(new ThisExpr(), f.getAttributeName())); hashCodeExpr = new MethodCallExpr(hashCodeExpr, "append", args); } hashCodeExpr = new MethodCallExpr(hashCodeExpr, "toHashCode"); final BlockStmt equalsBody = new BlockStmt(Collections.<Statement>singletonList(new ReturnStmt(hashCodeExpr))); hashCode.setBody(equalsBody); return new NodeAndImports<MethodDeclaration>(hashCode, Collections.singleton(new ImportDeclaration(new QualifiedNameExpr(new NameExpr("org.apache.commons.lang.builder"), "HashCodeBuilder"), false, false))); }
@Override public void visit(MethodDeclaration method, A result) { if (CollectionUtils.isEmpty(method.getAnnotations())) { return; } for (AnnotationExpr annotation : method.getAnnotations()) { if (!annotation.getClass().equals(NormalAnnotationExpr.class)) { continue; } NormalAnnotationExpr annot = (NormalAnnotationExpr) annotation; if (annot.getName().toString().equals(SampleCode.class.getSimpleName()) && !CollectionUtils.isEmpty(annot.getPairs())) { for (MemberValuePair pair : annot.getPairs()) { // get the 'api' parameter from the annotation to let us know which api this function belongs to if (StringUtils.equals(pair.getName(), "api") && !StringUtils.isBlank(pair.getValue().toString())) { result.put(getCacheRowKey(type, pair.getValue().toString().replace("\"", "")), stripTestPrefix(method.getName()), stripCurlyBrackets(method.getBody().toString())); return; } } } } } }
if (bodyDeclaration instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration; if (methodDeclaration.getAnnotations() != null) { annotationExprs.addAll(methodDeclaration.getAnnotations()); fieldInfos.add(new FieldInfo(methodDeclaration.getType(), methodDeclaration.getName(), methodDeclaration.getAnnotations(), methodDeclaration)); if (bodyDeclaration instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration; if (methodDeclaration.getName().equals(fieldInfo.getName().replace("get", "set"))) { if (methodDeclaration.getAnnotations() != null) fieldDeclaration.getAnnotations().addAll(methodDeclaration.getAnnotations());
@Override public void visit(MethodDeclaration n, Object arg) { // here you can access the attributes of the method. // this method will be called for all methods in this // CompilationUnit, including inner class methods currentMethod = new CGEntry(TYPE.METHOD, currentClass, currentMethod, n.getName()); if (isDebug()) System.out.println("M:" + currentMethod); list.add(currentMethod); List<AnnotationExpr> annos = n.getAnnotations(); if (annos != null) { for (AnnotationExpr anno : annos) { if (isDebug()) System.out.println("A:" + anno.getName()); currentMethod.addAnnotation(new CGEntry(TYPE.ANNOTATION, currentClass, currentMethod, anno.getName().getName())); } } super.visit(n, arg); if (currentMethod != null) currentMethod = currentMethod.getMethod(); }
public String getName() { return methodDeclaration.getName(); }
@Override public void visit(MethodDeclaration n, List<String> arg) { if (n.getAnnotations() != null) annotationExprs.addAll(n.getAnnotations()); super.visit(n, arg); }
public List<JavaMethodParameter> getParameters() { List<JavaMethodParameter> retValue = new ArrayList<JavaMethodParameter>(); List<Parameter> parameters = methodDeclaration.getParameters(); if (parameters == null) { return retValue; } for (Parameter parameter : parameters) { retValue.add(new ParameterJavaMethodParameter(parameter)); } return retValue; }
fd.getAttributeName()).getSimpleName(); final String attrName = fd.getAttributeName(); final MethodDeclaration getter = new MethodDeclaration(ModifierSet.PUBLIC, new ClassOrInterfaceType(simpleTypeName), "get" + attrName.substring(0, 1).toUpperCase() + attrName.substring(1)); getter.setBody(new BlockStmt(Collections.<Statement>singletonList(new ReturnStmt(new FieldAccessExpr(new ThisExpr(), attrName))))); members.add(getter); final MethodDeclaration setter = new MethodDeclaration(ModifierSet.PUBLIC, new VoidType(), "set" + attrName.substring(0, 1).toUpperCase() + attrName.substring(1), Collections.singletonList(new Parameter(new ClassOrInterfaceType(simpleTypeName), new VariableDeclaratorId(attrName)))); setter.setBody(new BlockStmt(Collections.<Statement>singletonList(new ExpressionStmt( new AssignExpr(new FieldAccessExpr(new ThisExpr(), attrName), new NameExpr(attrName), AssignExpr.Operator.assign))))); members.add(setter);
throw new ParseException(); MethodDeclaration tmp = new MethodDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, typeParameters, type, null, parameters, arrayCount, throws_, block); tmp.setNameExpr(name);
throw new ParseException(); {if (true) return new MethodDeclaration(line, column, token.endLine, token.endColumn,popJavadoc(), modifier.modifiers, modifier.annotations, typeParameters, type, name, parameters, arrayCount, throws_, block);} throw new Error("Missing return statement in function");
public boolean isPublic() { return ModifierSet.isPublic(methodDeclaration.getModifiers()); } }
public String getJavadoc() { JavadocComment javadoc = methodDeclaration.getJavaDoc(); if (javadoc != null) { return javadoc.getContent(); } return null; }
@Override public R visit(final MethodDeclaration n, final A arg) { if (n.getJavaDoc() != null) { R result = n.getJavaDoc().accept(this, arg); if (result != null) { return result; if (n.getAnnotations() != null) { for (final AnnotationExpr a : n.getAnnotations()) { if (n.getTypeParameters() != null) { for (final TypeParameter t : n.getTypeParameters()) { R result = n.getType().accept(this, arg); if (result != null) { return result; if (n.getParameters() != null) { for (final Parameter p : n.getParameters()) { if (n.getThrows() != null) { for (final NameExpr name : n.getThrows()) { if (n.getBody() != null) { R result = n.getBody().accept(this, arg); if (result != null) { return result;