List of usage examples for org.aspectj.asm IProgramElement getKind
public IProgramElement.Kind getKind();
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * Initialise the created types and populated them with operation properties and inner types. * // w ww .j a v a 2 s . co m * This code modifies Java2UMLConverter.initializeTypes() to handle AspectJ elements. */ @Override protected void initializeTypes(Package packageObject, IPackageFragment fragment) throws JavaModelException { ajModel = AJProjectModelFactory.getInstance().getModelForJavaElement(fragment); for (IJavaElement javaElement : fragment.getChildren()) { if (javaElement instanceof ICompilationUnit) { ICompilationUnit unit = (ICompilationUnit) javaElement; // AJParseTree tree = new AJParseTree(unit); for (IType type : unit.getAllTypes()) { String typeName = type.getElementName(); NamedElement element = packageObject.getOwnedMember(typeName); if (element == null && type.getParent() != null) { element = findInnerType(packageObject, type, typeName); } if (element instanceof Interface) { Interface interfaceObject = (Interface) element; // Super interfaces for (String interfaceName : type.getSuperInterfaceNames()) { Type interfaceType = findType(packageObject, interfaceName); if (interfaceType == null && type.getParent() != null) { interfaceType = findInnerType(packageObject, type, typeName); } if (interfaceType != null && interfaceType instanceof Classifier) { interfaceObject.createGeneralization((Classifier) interfaceType); } } // Inner objects createProperties(type, interfaceObject); createOperations(type, interfaceObject); } else if (element instanceof Enumeration) { Enumeration enumeration = (Enumeration) element; for (String interfaceName : type.getSuperInterfaceNames()) { Type interfaceType = findType(packageObject, interfaceName); if (interfaceType == null) { interfaceType = findGenericType(packageObject, interfaceName); } if (interfaceType == null && type.getParent() != null) { interfaceType = findInnerType(packageObject, type, typeName); } if (interfaceType != null && interfaceType instanceof Interface) { Classifier classifier = (Classifier) interfaceType; if (enumeration.getGeneralization(classifier) == null) { enumeration.createGeneralization(classifier); } } } // Inner objects createProperties(type, enumeration); createOperations(type, enumeration); } else if (element instanceof Class) { Class classObject = (Class) element; // Super Interfaces for (String interfaceName : type.getSuperInterfaceNames()) { Type interfaceType = findType(packageObject, interfaceName); if (interfaceType == null) { interfaceType = findGenericType(packageObject, interfaceName); } if (interfaceType == null && type.getParent() != null) { interfaceType = findInnerType(packageObject, type, typeName); } if (interfaceType != null && interfaceType instanceof Interface) { Interface interf = (Interface) interfaceType; if (classObject.getInterfaceRealization(interfaceName, interf) == null) { classObject.createInterfaceRealization(interfaceName, interf); } } } // Generalization String superClassName = type.getSuperclassName(); Type classType = findType(packageObject, superClassName); if (classType == null && type.getParent() != null) { classType = findInnerType(packageObject, type, typeName); } if (classType == null) { classType = findOrCreateType(packageObject, superClassName); } if (classType != null && classType instanceof Classifier) { Classifier classifier = (Classifier) classType; // Create generalization only if it is needed if (classObject.getGeneralization(classifier) == null) { classObject.createGeneralization(classifier); } } /* * Eventually, here's what I need to do. I need to find the * ProgramElement that corresponds to the class; if it's an * Aspect, then plug in the Aspect stereotype. (For now, I'll * hand-wave it by sticking in a comment to syserr.) * * Don't know if I'll try to handle the intertype stuff here, * or if I'll push that down into createProperties/createOperations. * Probably the former, which means I wouldn't call createProperties * or createOperations at all for Aspects. */ IProgramElement ajElement = javaElementToProgramElement(type); if (ajElement.getKind().toString().equals("aspect")) { System.err.println("aspect found: javaElement " + typeName + " (handle " + type.getHandleIdentifier() + "), programElement " + ajElement.getName() + ", UML object = " + classObject.getQualifiedName()); Stereotype aspectST = profile.getStereotype("Aspect"); try { classObject.applyStereotype(aspectST); } catch (Exception e) { System.err.println( "Exception attempting to apply Aspect stereotype to " + typeName + ":"); e.printStackTrace(); } //Extract elements from the Program Element createAjFeatures(type, ajElement, classObject); } else { // Inner objects createProperties(type, classObject); createOperations(type, classObject); } } } } } addAspectRelationships(ajModel, packageObject, fragment); }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * Creates the features (StaticCrossCuttingFeatures, Advices, and PointCuts) for * the aspect. /*from w ww .j a va 2s . c o m*/ * @param jType Java Model node for the aspect. * @param ajElement ProgramElement for the aspect. * @param classifier UML node for the aspect * @throws JavaModelException */ private void createAjFeatures(IType jType, IProgramElement ajElement, Class classifier) throws JavaModelException { List children = ajElement.getChildren(); for (Object object : children) { if (object instanceof IProgramElement) { IProgramElement child = (IProgramElement) object; printChildInfo(ajElement, child); String childType = child.getKind().toString(); if ((childType.equals("inter-type field")) || (childType.equals("inter-type constructor"))) { Property intertypeField = addAspectProperty(classifier, child); applyStereotype(intertypeField, "StaticCrossCuttingFeature"); } else if (childType.equals("inter-type method")) { Operation intertypeMethod = addAspectOperation(classifier, child); applyStereotype(intertypeMethod, "StaticCrossCuttingFeature"); } else if (childType.equals("inter-type parent")) { //TODO handle inter-type parent } else if (childType.equals("pointcut")) { /* * Evermann defines Pointcut as an abstract stereotype * that's extended by specific pointcut types * (AdviceExecutionPointCut, OperationPointCut, * PointCutPointCut, etc). IProgramElement doesn't * specific pointcut types, so for now I'm making Pointcut * non-abstract and lumping all pointcuts under that * stereotype. */ Property pointcutProperty = addAspectProperty(classifier, child); applyStereotype(pointcutProperty, "PointCut"); } else if (childType.equals("advice")) { /* * Advice is a behavioral feature (Operation in our case). */ Operation adviceOp = addAspectOperation(classifier, child); applyStereotype(adviceOp, "Advice"); //Now set adviceExecution: before/after/around setAdviceExecution(child, adviceOp); } } } }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * @param ajElement//from w ww .j ava 2 s . c o m * @param child */ private void printChildInfo(IProgramElement ajElement, IProgramElement child) { String childType = child.getKind().toString(); String childHandle = child.getHandleIdentifier(); IJavaElement jChild = programElementToJavaElement(child); String jChildHandle = jChild.getHandleIdentifier(); //BEGIN TEMPORARY STUFF System.err.println(ajElement.getName() + " " + childType + " " + child.getName()); // System.out.println(" bytecode name:" + child.getBytecodeName()); // System.out.println(" bytecode sig:" + child.getBytecodeSignature()); // System.out.println(" corresponding type:" + child.getCorrespondingType(false)); // System.out.println(" fully qual'd corresponding type:" + child.getCorrespondingType(true)); // System.out.println(" declaring type:" + child.getDeclaringType()); // System.out.println(" details:" + child.getDetails()); // System.out.println(" formal comment:" + child.getFormalComment()); System.err.println(" Program Element handle:" + childHandle); System.err.println(" Java Element handle:" + jChildHandle); // System.out.println(" package name:" + child.getPackageName()); // System.out.println(" raw modifiers:" + child.getRawModifiers()); // System.out.println(" source signature:" + child.getSourceSignature()); // printList(child.getParameterNames(), "parm names"); // printList(child.getParameterSignatures(), "parm sigs"); // printList(child.getParameterSignaturesSourceRefs(), "parm sig source refs"); // printList(child.getParameterTypes(), "parm types"); // printList(child.getChildren(), "children"); //END TEMPORARY STUFF }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * Returns the name and type of an IJavaElement. * @param element IJavaElement being examined * @return <i>element-name</i>(<i>element-type</i>) *///from www . ja v a 2 s .c o m private String printNameTypeOf(IProgramElement element) { return element.getName() + "(" + element.getKind().toString() + ")[" + element.getHandleIdentifier() + "]"; }
From source file:org.caesarj.compiler.asm.StructureModelDump.java
License:Open Source License
protected void printNodeHeader(PrintStream outArg, IProgramElement node) { outArg.print("[" + node.getKind() + "] " + node.getName()); ISourceLocation srcLoc = node.getSourceLocation(); if (srcLoc != null) { outArg.print("(L " + srcLoc.getLine() + ") "); }// w w w. j a v a 2 s . c om }
From source file:org.caesarj.compiler.asm.StructureModelDump.java
License:Open Source License
protected void printRelationshipMap(CaesarJAsmManager asmManager) { System.out.println("Dumping Relationship Map"); IHierarchy hierarchy = asmManager.getHierarchy(); IRelationshipMap map = asmManager.getRelationshipMap(); Set entries = map.getEntries(); Iterator i = entries.iterator(); while (i.hasNext()) { List relationships = map.get((String) i.next()); Iterator j = relationships.iterator(); while (j.hasNext()) { IRelationship relationship = (IRelationship) j.next(); System.out.println("Relationship '" + relationship.getName() + "' of kind '" + relationship.getKind() + "' has " + relationship.getTargets().size() + " target(s) "); System.out.println(" source handle -->" + relationship.getSourceHandle()); Iterator k = relationship.getTargets().iterator(); while (k.hasNext()) { IProgramElement element = hierarchy.findElementForHandle((String) k.next()); System.out.println(" -> '" + element.getName() + "' of kind '" + element.getKind() + "' with handle " + element.getHandleIdentifier()); }//from w w w . j a v a 2s . c om } } }
From source file:org.caesarj.launching.CaesarLaunchShortcut.java
License:Open Source License
/** * Finds the source file node for the given filename in the structuremodel with * given root element./*from w ww .j a v a 2s.c om*/ * * @param root * @param filename absolute filename * @return */ protected IProgramElement findSourceFileNode(IProgramElement root, String filename) { if (root == null) { return null; } if (filename == null) { return null; } if (root.getKind() != null && root.getKind().isSourceFile()) { if (root.getSourceLocation().getSourceFile().getAbsolutePath().equals(filename)) { return root; } else { return null; } } else { IProgramElement res = null; for (Iterator it = root.getChildren().iterator(); it.hasNext() && res == null;) { res = findSourceFileNode((IProgramElement) it.next(), filename); } return res; } }
From source file:org.caesarj.ui.editor.CaesarJContentOutlinePage.java
License:Open Source License
protected IProgramElement getInput(IProgramElement node) { String filename = null;//from ww w . ja v a2s. c om IEditorInput editorInput = this.caesarEditor.getEditorInput(); if (editorInput instanceof IPathEditorInput) { filename = ((IPathEditorInput) editorInput).getPath().toFile().getAbsolutePath(); } if (node == null) { return null; } if (filename == null) { return null; } IProgramElement r = null; //if (node.getName().equals(this.caesarEditor.getEditorInput().getName())) { if (node.getKind() != null && node.getKind().isSourceFile() && node.getSourceLocation().getSourceFile().getAbsolutePath().equals(filename)) { r = node; } else { IProgramElement res = null; for (Iterator it = node.getChildren().iterator(); it.hasNext() && res == null;) { res = getInput((IProgramElement) it.next()); } r = res; } return r; }
From source file:org.caesarj.ui.marker.AdviceMarkerGenerator.java
License:Open Source License
/** * Used to add Markers to the editor.// w w w . ja v a2 s . co m * @param node - CaesarProgramElement representing the Position where to add the Marker * @param relation - defines the Marker */ private void setMarkers(IProgramElement parent) { Logger.getLogger(this.getClass()).info("setMarkers() for relation node"); String messageLocal = ""; HashMap args = new HashMap(); List lElems = new ArrayList(); Iterator i = parent.getChildren().iterator(); while (i.hasNext()) { IProgramElement elem = (IProgramElement) i.next(); if (elem instanceof LinkNode) { // Add if it is a link node LinkNode node = (LinkNode) elem; Iterator i2 = node.getChildren().iterator(); while (i2.hasNext()) { IProgramElement elem2 = (IProgramElement) i2.next(); if (elem2 instanceof LinkNode) { // Add if it is a link node IProgramElement target = ((LinkNode) elem2).getTargetElement(); //if (!lElems.contains(target)) { if (target.getKind().equals(IProgramElement.Kind.ADVICE)) { args.put(AdviceMarker.ID, "AdviceLink"); } else { args.put(AdviceMarker.ID, "MethodeLink"); } if (!messageLocal.equals("")) { messageLocal += ", "; } if (target.getParent() != null) { String parentName = target.getParent().getName(); parentName = parentName.replaceAll("_Impl.*", ""); messageLocal += parentName + "." + target.getName(); } else { messageLocal += target.getName(); } lElems.add(target); //} } } } } if (!lElems.isEmpty()) { IResource resource = ProjectProperties .findResource(parent.getSourceLocation().getSourceFile().getAbsolutePath(), project); args.put(IMarker.LINE_NUMBER, new Integer(parent.getSourceLocation().getLine())); args.put(IMarker.MESSAGE, messageLocal); args.put(AdviceMarker.LINKS, lElems.toArray(new IProgramElement[0])); try { IMarker marker = resource.createMarker(AdviceMarker.ADVICEMARKER); marker.setAttributes(args); } catch (CoreException e) { Logger.getLogger(this.getClass()).error("FEHLER BEIM MARKER ERZEUGEN", e); //$NON-NLS-1$ } } }
From source file:org.eclipse.ajdt.core.codeconversion.AspectsConvertingParser.java
License:Open Source License
/** * @param type type to look for declare extends on * @return list of all declare extends that apply to this type * in fully qualified strings//from ww w. j a v a2 s . c o m */ protected List<String>[] getDeclareExtendsImplements(IType type) { List<String> declareExtends = new ArrayList<String>(); List<String> declareImplements = new ArrayList<String>(); if (type != null && type.exists()) { AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForJavaElement(type); if (model.hasModel()) { List<IJavaElement> rels = model.getRelationshipsForElement(type, AJRelationshipManager.ASPECT_DECLARATIONS); for (IJavaElement je : rels) { IProgramElement pe = model.javaElementToProgramElement(je); List<String> parentTypes = null; if (pe.getKind() == IProgramElement.Kind.DECLARE_PARENTS) { parentTypes = pe.getParentTypes(); } else if (pe.getKind() == IProgramElement.Kind.ASPECT) { // could be a concrete aspect that instantiates a declare parents relationship from an abstact aspect Map<String, List<String>> parents = pe.getDeclareParentsMap(); if (parents != null) { parentTypes = parents.get(type.getFullyQualifiedName()); } } if (parentTypes != null) { IJavaProject project = type.getJavaProject(); // bug 273914---must determine if these are interfaces or classes for (String parentType : parentTypes) { IType parentTypeElt; try { parentTypeElt = project.findType(parentType); } catch (JavaModelException e) { parentTypeElt = null; } boolean parentIsClass; boolean typeIsClass; try { parentIsClass = parentTypeElt == null || parentTypeElt.isClass(); typeIsClass = type.isClass(); } catch (JavaModelException e) { parentIsClass = true; typeIsClass = true; } if (parentIsClass && typeIsClass) { declareExtends.add(parentType); } else if (!parentIsClass && typeIsClass) { declareImplements.add(parentType); } else if (!parentIsClass && !typeIsClass) { declareExtends.add(parentType); } else if (parentIsClass && !typeIsClass) { // error, but handle gracefully declareExtends.add(parentType); } } } } } } return new List[] { declareExtends, declareImplements }; }