List of usage examples for org.aspectj.asm IProgramElement getChildren
public List<IProgramElement> getChildren();
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 w w . j av a2s . 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:org.caesarj.launching.CaesarLaunchShortcut.java
License:Open Source License
/** * If the given java element contains a main type, the return value is the full * qualified type name, otherwise it is null. * //from w w w.j av a2 s . c o m * @param je the java root element to search for a main type * @return the full qualified type name or null */ protected String findRunnableType(IJavaElement je) { IResource res = je.getResource(); if (res == null) { return null; } String filename = res.getLocation().toFile().getAbsolutePath(); IProject project = res.getProject(); ProjectProperties properties = ProjectProperties.create(project); IProgramElement pe = findSourceFileNode(properties.getAsmManager().getHierarchy().getRoot(), filename); Object current = null; CaesarProgramElement currentCe = null; boolean foundRunnable = false; for (Iterator it = pe.getChildren().iterator(); it.hasNext() && !foundRunnable;) { current = it.next(); if (current instanceof CaesarProgramElement) { currentCe = (CaesarProgramElement) current; if (currentCe.getCaesarKind().isType()) { foundRunnable = isTypeNodeRunnable(currentCe); } } } if (foundRunnable) { return currentCe.getPackageName() + "." + currentCe.getName(); } return null; }
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 w w . j av a 2 s . c o m*/ * * @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 .j a v a2 s. co m 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.editor.CaesarOutlineViewContentProvider.java
License:Open Source License
/** * * @param parent * @return */ protected Object[] getChildren(IProgramElement parent) { return parent.getChildren().toArray(); }
From source file:org.caesarj.ui.editor.CaesarOutlineViewContentProvider.java
License:Open Source License
/** * /*from w w w .j av a2 s. com*/ * @param parent * @return */ protected Object[] getChildren(CaesarProgramElement parent) { // Get the parent's kind Kind kind = parent.getCaesarKind(); // Do not get children from packages if (CaesarProgramElement.Kind.PACKAGE == kind) { return new Object[0]; } ArrayList elements = new ArrayList(); // If the element is an import declaration list, get the children, removing java/lang if (CaesarProgramElement.Kind.IMPORTS == kind) { Iterator i = parent.getChildren().iterator(); while (i.hasNext()) { CaesarProgramElement child = (CaesarProgramElement) i.next(); if (child.getName().compareTo("java.lang") != 0) { elements.add(child); } } return elements.toArray(); } // add children // add all children except if child is of Kind ADVICE_REGISTRY, // then add childs children to node Iterator i = parent.getChildren().iterator(); while (i.hasNext()) { IProgramElement childElement = (IProgramElement) i.next(); if (childElement instanceof LinkNode) { // Add if it is a link node elements.add(childElement); } else if (!(childElement instanceof CaesarProgramElement)) { // If it is an aspectj node, add all children elements.addAll(childElement.getChildren()); } else { // Transform to caesar types CaesarProgramElement child = (CaesarProgramElement) childElement; Kind childKind = ((CaesarProgramElement) child).getCaesarKind(); // If it is an ADVICE_REGISTRY, add all its children, but not itself if (CaesarProgramElement.Kind.ADVICE_REGISTRY == childKind) { elements.addAll(child.getChildren()); } else { elements.add(child); } } } return elements.toArray(); }
From source file:org.caesarj.ui.marker.AdviceMarkerGenerator.java
License:Open Source License
/** * Used to add Markers to the editor./* w w w .jav a 2s . c om*/ * @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.caesarj.ui.views.hierarchymodel.HierarchyModelFactory.java
License:Open Source License
/** * Uses the structure model and searches the filename (using the findNode method). Using * this root node, create a list of sources for the hierarchy tree. * //from w w w .j a v a 2 s . co m * @return */ protected Vector getSources() { // Create the list to keep the sources Vector srcs = new Vector(); // Gets the root structure node for the input IProgramElement javaRootNode = findNode(structureModel.getRoot(), filename); // If the root could not be found, return an empty list if (javaRootNode != null) { // Get all children from the root node as an iterator Iterator i = javaRootNode.getChildren().iterator(); // Check which of the children should be a source for us while (i.hasNext()) { Object next = i.next(); // Check that the element is a caesar node if (next instanceof CaesarProgramElement) { // Check if the element is a virtual class or aspect CaesarProgramElement node = (CaesarProgramElement) next; if (node.getCaesarKind() == CaesarProgramElement.Kind.VIRTUAL_CLASS || node.getCaesarKind() == CaesarProgramElement.Kind.ASPECT) { // Get the classname from the node String classname = node.getName(); // Strip the implementation termination if needed if (classname.indexOf(IMPL_EXTENSION) != -1) { classname = classname.substring(0, classname.indexOf(IMPL_EXTENSION)); } // Add to the source list srcs.add(node.getPackageName().replaceAll("\\.", "/") + File.separator + classname); } } } } // Return the vector return srcs; }
From source file:org.caesarj.ui.views.hierarchymodel.HierarchyModelFactory.java
License:Open Source License
/** * Recursive method for finding a node with name "name" between the children of "node". * /*www . j av a 2 s . co m*/ * Used when getting sources (getSources) */ protected IProgramElement findNode(IProgramElement node, String name) { if (node == null || name == null) { return null; } // End of recursion, found the node if (node.getName().equals(name)) { return node; } // Try to find between the children Iterator i = node.getChildren().iterator(); while (i.hasNext()) { IProgramElement rec = findNode((IProgramElement) i.next(), name); if (rec != null) return rec; } // Couldn't find, return null return null; }
From source file:org.eclipse.ajdt.core.codeconversion.AspectsConvertingParser.java
License:Open Source License
/** * @param sb/*from w w w . j av a 2s. com*/ * @param declareElt */ protected void createITITText(StringBuffer sb, IProgramElement declareElt) { sb.append("\n\tstatic class ").append(declareElt.getName()).append(" {\n"); List<IProgramElement> children = declareElt.getChildren(); for (IProgramElement child : children) { sb.append("\t\tpublic static "); sb.append(child.getCorrespondingType(true) + " "); sb.append(child.getName()); if (child.getKind() == IProgramElement.Kind.FIELD) { sb.append(";\n"); } else { sb.append("("); List<String> names = child.getParameterNames(); List<char[]> types = child.getParameterTypes(); if (types != null && names != null) { for (Iterator<?> typeIter = types.iterator(), nameIter = names.iterator(); typeIter .hasNext();) { String paramType = String.valueOf((char[]) typeIter.next()); String paramName = (String) nameIter.next(); sb.append(paramType + " " + paramName); if (typeIter.hasNext()) { sb.append(", "); } } } sb.append(") { }\n"); } } sb.append("\t}\n"); }