Browse Source

refactoring

tags/V1_6_12M1
aclement 13 years ago
parent
commit
dce63a197f
1 changed files with 27 additions and 36 deletions
  1. 27
    36
      weaver/src/org/aspectj/weaver/model/AsmRelationshipProvider.java

+ 27
- 36
weaver/src/org/aspectj/weaver/model/AsmRelationshipProvider.java View File

IProgramElement root = model.getHierarchy().getRoot(); IProgramElement root = model.getHierarchy().getRoot();
IProgramElement binaries = model.getHierarchy().findElementForLabel(root, IProgramElement.Kind.SOURCE_FOLDER, "binaries"); IProgramElement binaries = model.getHierarchy().findElementForLabel(root, IProgramElement.Kind.SOURCE_FOLDER, "binaries");
if (binaries == null) { if (binaries == null) {
binaries = new ProgramElement(model, "binaries", IProgramElement.Kind.SOURCE_FOLDER, new ArrayList());
binaries = new ProgramElement(model, "binaries", IProgramElement.Kind.SOURCE_FOLDER, new ArrayList<IProgramElement>());
root.addChild(binaries); root.addChild(binaries);
} }
// if (aspect.getPackageName() != null) { // if (aspect.getPackageName() != null) {
IProgramElement pkgNode = model.getHierarchy().findElementForLabel(binaries, IProgramElement.Kind.PACKAGE, packagename); IProgramElement pkgNode = model.getHierarchy().findElementForLabel(binaries, IProgramElement.Kind.PACKAGE, packagename);
// note packages themselves have no source location // note packages themselves have no source location
if (pkgNode == null) { if (pkgNode == null) {
pkgNode = new ProgramElement(model, packagename, IProgramElement.Kind.PACKAGE, new ArrayList());
pkgNode = new ProgramElement(model, packagename, IProgramElement.Kind.PACKAGE, new ArrayList<IProgramElement>());
binaries.addChild(pkgNode); binaries.addChild(pkgNode);
pkgNode.addChild(classFileNode); pkgNode.addChild(classFileNode);
} else { } else {
// may not be generated correctly if it uses information from // may not be generated correctly if it uses information from
// it's parent node // it's parent node
pkgNode.addChild(classFileNode); pkgNode.addChild(classFileNode);
for (Iterator iter = pkgNode.getChildren().iterator(); iter.hasNext();) {
IProgramElement element = (IProgramElement) iter.next();
for (IProgramElement element: pkgNode.getChildren()) {
if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) { if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) {
// already added the classfile so have already // already added the classfile so have already
// added the structure for this aspect // added the structure for this aspect


IProgramElement sourceFileNode = asm.getHierarchy().findElementForSourceLine(munger.getSourceLocation()); IProgramElement sourceFileNode = asm.getHierarchy().findElementForSourceLine(munger.getSourceLocation());
// the call to findElementForSourceLine(ISourceLocation) returns a file // the call to findElementForSourceLine(ISourceLocation) returns a file
// node
// if it can't find a node in the hierarchy for the given
// sourcelocation.
// node if it can't find a node in the hierarchy for the given sourcelocation.
// Therefore, if this is returned, we know we can't find one and have to // Therefore, if this is returned, we know we can't find one and have to
// continue to fault in the model. // continue to fault in the model.
if (!sourceFileNode.getKind().equals(IProgramElement.Kind.FILE_JAVA)) { if (!sourceFileNode.getKind().equals(IProgramElement.Kind.FILE_JAVA)) {
IProgramElement root = asm.getHierarchy().getRoot(); IProgramElement root = asm.getHierarchy().getRoot();
IProgramElement binaries = asm.getHierarchy().findElementForLabel(root, IProgramElement.Kind.SOURCE_FOLDER, "binaries"); IProgramElement binaries = asm.getHierarchy().findElementForLabel(root, IProgramElement.Kind.SOURCE_FOLDER, "binaries");
if (binaries == null) { if (binaries == null) {
binaries = new ProgramElement(asm, "binaries", IProgramElement.Kind.SOURCE_FOLDER, new ArrayList());
binaries = new ProgramElement(asm, "binaries", IProgramElement.Kind.SOURCE_FOLDER, new ArrayList<IProgramElement>());
root.addChild(binaries); root.addChild(binaries);
} }
// if (aspect.getPackageName() != null) { // if (aspect.getPackageName() != null) {
IProgramElement pkgNode = asm.getHierarchy().findElementForLabel(binaries, IProgramElement.Kind.PACKAGE, packagename); IProgramElement pkgNode = asm.getHierarchy().findElementForLabel(binaries, IProgramElement.Kind.PACKAGE, packagename);
// note packages themselves have no source location // note packages themselves have no source location
if (pkgNode == null) { if (pkgNode == null) {
pkgNode = new ProgramElement(asm, packagename, IProgramElement.Kind.PACKAGE, new ArrayList());
pkgNode = new ProgramElement(asm, packagename, IProgramElement.Kind.PACKAGE, new ArrayList<IProgramElement>());
binaries.addChild(pkgNode); binaries.addChild(pkgNode);
pkgNode.addChild(classFileNode); pkgNode.addChild(classFileNode);
} else { } else {
// may not be generated correctly if it uses information from // may not be generated correctly if it uses information from
// it's parent node // it's parent node
pkgNode.addChild(classFileNode); pkgNode.addChild(classFileNode);
for (Iterator iter = pkgNode.getChildren().iterator(); iter.hasNext();) {
IProgramElement element = (IProgramElement) iter.next();
for (IProgramElement element: pkgNode.getChildren()) {
if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) { if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) {
// already added the classfile so have already // already added the classfile so have already
// added the structure for this aspect // added the structure for this aspect
} }
ISourceLocation pointcutLocation = (sLoc == null ? null : createSourceLocation(sourcefilename, aspect, sLoc)); ISourceLocation pointcutLocation = (sLoc == null ? null : createSourceLocation(sourcefilename, aspect, sLoc));
ProgramElement pointcutElement = new ProgramElement(model, pointcut.getName(), IProgramElement.Kind.POINTCUT, ProgramElement pointcutElement = new ProgramElement(model, pointcut.getName(), IProgramElement.Kind.POINTCUT,
pointcutLocation, pointcut.getModifiers(), NO_COMMENT, Collections.EMPTY_LIST);
pointcutLocation, pointcut.getModifiers(), NO_COMMENT, Collections.<IProgramElement>emptyList());
containingAspect.addChild(pointcutElement); containingAspect.addChild(pointcutElement);
} }
} }
sLoc = rpcd.getSourceLocation(); sLoc = rpcd.getSourceLocation();
} }
parent.addChild(new ProgramElement(asm, pcd.getName(), IProgramElement.Kind.POINTCUT, getBinarySourceLocation( parent.addChild(new ProgramElement(asm, pcd.getName(), IProgramElement.Kind.POINTCUT, getBinarySourceLocation(
aspect, sLoc), pcd.getModifiers(), null, Collections.EMPTY_LIST));
aspect, sLoc), pcd.getModifiers(), null, Collections.<IProgramElement>emptyList()));
} }
} }
} }


private static void addChildNodes(AsmManager asm, ResolvedType aspect, IProgramElement parent, Collection children) {
private static void addChildNodes(AsmManager asm, ResolvedType aspect, IProgramElement parent, Collection<?> children) {
int deCtr = 1; int deCtr = 1;
int dwCtr = 1; int dwCtr = 1;
for (Iterator iter = children.iterator(); iter.hasNext();) {
Object element = iter.next();
for (Object element: children) {
if (element instanceof DeclareErrorOrWarning) { if (element instanceof DeclareErrorOrWarning) {
DeclareErrorOrWarning decl = (DeclareErrorOrWarning) element; DeclareErrorOrWarning decl = (DeclareErrorOrWarning) element;
int counter = 0; int counter = 0;
private static IProgramElement createAdviceChild(AsmManager model, Advice advice) { private static IProgramElement createAdviceChild(AsmManager model, Advice advice) {
IProgramElement adviceNode = new ProgramElement(model, advice.getKind().getName(), IProgramElement.Kind.ADVICE, IProgramElement adviceNode = new ProgramElement(model, advice.getKind().getName(), IProgramElement.Kind.ADVICE,
advice.getBinarySourceLocation(advice.getSourceLocation()), advice.getSignature().getModifiers(), null, advice.getBinarySourceLocation(advice.getSourceLocation()), advice.getSignature().getModifiers(), null,
Collections.EMPTY_LIST);
Collections.<IProgramElement>emptyList());
adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut())); adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut()));
adviceNode.setBytecodeName(advice.getSignature().getName()); adviceNode.setBytecodeName(advice.getSignature().getName());
return adviceNode; return adviceNode;
name = name.substring(name.indexOf("$") + 1); name = name.substring(name.indexOf("$") + 1);
} }
IProgramElement pe = new ProgramElement(model, name, IProgramElement.Kind.INTER_TYPE_FIELD, getBinarySourceLocation( IProgramElement pe = new ProgramElement(model, name, IProgramElement.Kind.INTER_TYPE_FIELD, getBinarySourceLocation(
aspect, itd.getSourceLocation()), rtMunger.getSignature().getModifiers(), null, Collections.EMPTY_LIST);
aspect, itd.getSourceLocation()), rtMunger.getSignature().getModifiers(), null, Collections.<IProgramElement>emptyList());
pe.setCorrespondingType(sig.getReturnType().getName()); pe.setCorrespondingType(sig.getReturnType().getName());
return pe; return pe;
} else if (kind == ResolvedTypeMunger.Method) { // ITD } else if (kind == ResolvedTypeMunger.Method) { // ITD
name = name.substring(name.indexOf("$") + 1); name = name.substring(name.indexOf("$") + 1);
} }
IProgramElement pe = new ProgramElement(model, name, IProgramElement.Kind.INTER_TYPE_METHOD, getBinarySourceLocation( IProgramElement pe = new ProgramElement(model, name, IProgramElement.Kind.INTER_TYPE_METHOD, getBinarySourceLocation(
aspect, itd.getSourceLocation()), rtMunger.getSignature().getModifiers(), null, Collections.EMPTY_LIST);
aspect, itd.getSourceLocation()), rtMunger.getSignature().getModifiers(), null, Collections.<IProgramElement>emptyList());
setParams(pe, sig); setParams(pe, sig);
return pe; return pe;
} else if (kind == ResolvedTypeMunger.Constructor) { } else if (kind == ResolvedTypeMunger.Constructor) {
} }
IProgramElement pe = new ProgramElement(model, name, IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR, IProgramElement pe = new ProgramElement(model, name, IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR,
getBinarySourceLocation(aspect, itd.getSourceLocation()), rtMunger.getSignature().getModifiers(), null, getBinarySourceLocation(aspect, itd.getSourceLocation()), rtMunger.getSignature().getModifiers(), null,
Collections.EMPTY_LIST);
Collections.<IProgramElement>emptyList());
setParams(pe, sig); setParams(pe, sig);
return pe; return pe;
// } else if (kind == ResolvedTypeMunger.MethodDelegate2) { // } else if (kind == ResolvedTypeMunger.MethodDelegate2) {
private static void setParams(IProgramElement pe, ResolvedMember sig) { private static void setParams(IProgramElement pe, ResolvedMember sig) {
// do it for itds too // do it for itds too
UnresolvedType[] ts = sig.getParameterTypes(); UnresolvedType[] ts = sig.getParameterTypes();
pe.setParameterNames(Collections.EMPTY_LIST);
// String[] pnames = sig.getParameterNames();
pe.setParameterNames(Collections.<String>emptyList());
// TODO should be doing param names?
if (ts == null) { if (ts == null) {
pe.setParameterSignatures(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
pe.setParameterSignatures(Collections.<char[]>emptyList(), Collections.<String>emptyList());
} else { } else {
List paramSigs = new ArrayList();
// List paramNames = new ArrayList();
List<char[]> paramSigs = new ArrayList<char[]>();
for (int i = 0; i < ts.length; i++) { for (int i = 0; i < ts.length; i++) {
paramSigs.add(ts[i].getSignature().toCharArray()); paramSigs.add(ts[i].getSignature().toCharArray());
// paramNames.add(pnames[i]);
} }
pe.setParameterSignatures(paramSigs, Collections.EMPTY_LIST);
// pe.setParameterNames(paramNames);
pe.setParameterSignatures(paramSigs, Collections.<String>emptyList());
} }
pe.setCorrespondingType(sig.getReturnType().getName()); pe.setCorrespondingType(sig.getReturnType().getName());
} }
private static IProgramElement createDeclareParentsChild(AsmManager model, DeclareParents decp) { private static IProgramElement createDeclareParentsChild(AsmManager model, DeclareParents decp) {
IProgramElement decpElement = new ProgramElement(model, "declare parents", IProgramElement.Kind.DECLARE_PARENTS, IProgramElement decpElement = new ProgramElement(model, "declare parents", IProgramElement.Kind.DECLARE_PARENTS,
getBinarySourceLocation(decp.getDeclaringType(), decp.getSourceLocation()), Modifier.PUBLIC, null, getBinarySourceLocation(decp.getDeclaringType(), decp.getSourceLocation()), Modifier.PUBLIC, null,
Collections.EMPTY_LIST);
Collections.<IProgramElement>emptyList());
setParentTypesOnDeclareParentsNode(decp, decpElement); setParentTypesOnDeclareParentsNode(decp, decpElement);
return decpElement; return decpElement;
} }
// otherwise // otherwise
// we wont get unique handles // we wont get unique handles
int numberOfChildrenWithThisName = 0; int numberOfChildrenWithThisName = 0;
for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext();) {
IProgramElement child = (IProgramElement) it.next();
for (IProgramElement child: enclosingNode.getChildren()) {
if (child.getName().equals(shadow.toString())) { if (child.getName().equals(shadow.toString())) {
numberOfChildrenWithThisName++; numberOfChildrenWithThisName++;
} }
if (typeElem == null) { if (typeElem == null) {
return; return;
} }
if (!typeElem.getKind().isType()) {
throw new IllegalStateException("Did not find a type element, found a "+typeElem.getKind()+" element");
}


StringBuffer parmString = new StringBuffer("(");
StringBuilder parmString = new StringBuilder("(");
UnresolvedType[] args = affectedMethod.getParameterTypes(); UnresolvedType[] args = affectedMethod.getParameterTypes();
// Type[] args = method.getArgumentTypes();
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
String s = args[i].getName();// Utility.signatureToString(args[i].
// getName()getSignature(), false);
parmString.append(s);
parmString.append(args[i].getName());
if ((i + 1) < args.length) { if ((i + 1) < args.length) {
parmString.append(","); parmString.append(",");
} }

Loading…
Cancel
Save