// }
// return (IProgramElement) stack.peek();
// }
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
IProgramElement peNode = null;
// For intertype decls, use the modifiers from the original signature,
// not the generated method
if (methodDeclaration instanceof InterTypeDeclaration) {
InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration;
ResolvedMember sig = itd.getSignature();
peNode = new ProgramElement(activeStructureModel, null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration),
(sig != null ? sig.getModifiers() : 0), null, null);
} else {
peNode = new ProgramElement(activeStructureModel, null, IProgramElement.Kind.ERROR, makeLocation(methodDeclaration),
methodDeclaration.modifiers, null, null);
}
formatter.genLabelAndKind(methodDeclaration, peNode); // will set the
// name
genBytecodeInfo(methodDeclaration, peNode);
List namedPointcuts = genNamedPointcuts(methodDeclaration);
// if (shouldAddUsesPointcut)
// addUsesPointcutRelationsForNode(peNode, namedPointcuts, methodDeclaration);
if (methodDeclaration instanceof DeclareDeclaration) {
DeclareDeclaration dDeclaration = (DeclareDeclaration) methodDeclaration;
Declare decl = dDeclaration.declareDecl;
if (decl instanceof DeclareParents) {
TypePatternList tpl = ((DeclareParents) decl).getParents();
List<String> parents = new ArrayList<String>();
for (int i = 0; i < tpl.size(); i++) {
parents.add(tpl.get(i).getExactType().getName().replaceAll("\\$", "."));
}
peNode.setParentTypes(parents);
}
if (decl instanceof DeclareAnnotation) {
DeclareAnnotation da = (DeclareAnnotation) decl;
ResolvedType annotationType = da.getAnnotationType();
if (annotationType == null) {
String s = ((DeclareAnnotation) decl).getAnnotationString();
if (s != null && s.length() > 0) {
s = s.substring(1);
}
peNode.setAnnotationType(s);
} else {
peNode.setAnnotationType(annotationType.getName());
}
if (da.isRemover()) {
peNode.setAnnotationRemover(true);
}
}
}
if (methodDeclaration.returnType != null) {
// if we don't make the distinction between ITD fields and other
// methods, then we loose the type, for example int, for the field
// and instead get "void".
if (peNode.getKind().equals(IProgramElement.Kind.INTER_TYPE_FIELD)) {
InterTypeFieldDeclaration itfd = (InterTypeFieldDeclaration) methodDeclaration;
if (itfd.getRealFieldType() != null) {
peNode.setCorrespondingType(new String(itfd.getRealFieldType().readableName()));
} else {
peNode.setCorrespondingType(null);
}
// was peNode.setCorrespondingType(methodDeclaration.returnType.toString());
} else {
if (methodDeclaration.returnType.resolvedType != null) {
peNode.setCorrespondingType(new String(methodDeclaration.returnType.resolvedType.readableName()));
} else {
peNode.setCorrespondingType(null);
}
}
} else {
peNode.setCorrespondingType(null);
}
peNode.setSourceSignature(genSourceSignature(methodDeclaration));
peNode.setFormalComment(generateJavadocComment(methodDeclaration));
// TODO: add return type test
if (peNode.getKind().equals(IProgramElement.Kind.METHOD)) {
if ((peNode.getName().charAt(0) == 'm')
&& (peNode.toLabelString().equals("main(String[])") || peNode.toLabelString()
.equals("main(java.lang.String[])"))
&& peNode.getModifiers().contains(IProgramElement.Modifiers.STATIC)
&& peNode.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC)) {
((IProgramElement) stack.peek()).setRunnable(true);
}
}
stack.push(peNode);