List of usage examples for org.aspectj.asm IProgramElement getName
public String getName();
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. * //from w ww.j a v a 2s. com * 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
/** * Sets the adviceExecution (before, after, around) for a newly created advice * @param modelAdvice the advice as it appears in the AspectJ/Java Model * @param umlAdvice the advice as it appears in the UML model *//* ww w. j a v a 2 s. com*/ private void setAdviceExecution(IProgramElement modelAdvice, Operation umlAdvice) { Stereotype stereotype = profile.getStereotype("Advice"); String literalName; String adviceType = modelAdvice.getName(); if (adviceType.contains("before")) { literalName = "BeforeAdvice"; } else if (adviceType.contains("after")) { literalName = "AfterAdvice"; } else { literalName = "AroundAdvice"; } EnumerationLiteral literal = profile.getEnumLiteral("AdviceExecutionType", literalName); umlAdvice.setValue(stereotype, "adviceExecution", literal); }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
private Operation createOperation(Class classifier, IProgramElement child) throws JavaModelException { // protected Operation createOperation(Element element, IMethod method) throws JavaModelException // {/* www . j a va 2s . c o m*/ String methodName = child.getName(); Operation operationObject = UMLFactory.eINSTANCE.createOperation(); operationObject.setName(methodName); update(operationObject, child.getRawModifiers()); int flags = child.getRawModifiers(); operationObject.setIsAbstract(Flags.isAbstract(flags)); operationObject.setIsStatic(Flags.isStatic(flags)); attachJavadoc(operationObject, child); createParameters(classifier, operationObject, child); //JWK: For now, I'm assuming that the child will exist and won't be a Constructor of some sort. // if (child.exists() && !child.isConstructor()) // { // TEMP createTemplateParameters(child, operationObject); // String returnTypeSig = child.getReturnType(); // // String returnTypeWithoutArray = Signature.getElementType(returnTypeSig); // String returnTypeName = Signature.toString(Signature.getTypeErasure(returnTypeWithoutArray)); String returnTypeName = child.getCorrespondingType(true); Type returnType = findTemplateParameter(classifier, returnTypeName); if (returnType == null) { returnType = findTemplateParameter(operationObject, returnTypeName); } if (returnType == null) { returnType = findOrCreateType(classifier.getNearestPackage(), returnTypeName); } // Type returnType = findOrCreateType(element.getNearestPackage(), // returnTypeName); if (returnType != null) { operationObject.createReturnResult("return", returnType); } // } return operationObject; }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
private Operation findOperation(StructuredClassifier classifier, IProgramElement child) { // protected Operation findOperation(Classifier classifier, IMethod method) // {//from w ww .j av a 2 s .co m for (Operation op : classifier.getOperations()) { if (op.getOwner().equals(classifier) && op.getName().equals(child.getName())) { // try // { List lParamNames = child.getParameterNames(); // if ((lParamNames == null) || (lParamNames.size() == 1)) // { // if (op.getOwnedParameters().size() == 1) // { // return op; // } // } if (lParamNames == null) { if (op.getOwnedParameters().size() == 0) { return op; } } else if (lParamNames.size() == 1) { if (op.getOwnedParameters().size() == 1) { return op; } } else { Object[] aParamNames = lParamNames.toArray(); int i = 0; int paramCount = 0; for (Parameter param : op.getOwnedParameters()) { if (!param.getName().equals("return")) { if (i < aParamNames.length && param.getName().equals(aParamNames[i].toString())) { paramCount++; } i++; } } if (paramCount == aParamNames.length) { return op; } } // } // catch (JavaModelException e) // { // e.printStackTrace(); // } } } return null; }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
private Property createProperty(Element element, IProgramElement field) throws JavaModelException { String fieldName = field.getName(); // String fieldTypeSig = field.getCorrespondingType(); ////from w w w.j a v a 2s . c o m // String fieldTypeWithoutArray = Signature.getElementType(fieldTypeSig); // String fieldTypeName = Signature.toString(Signature.getTypeErasure(fieldTypeWithoutArray)); String fieldTypeName = field.getCorrespondingType(true); Type fieldType = findTemplateParameter(element, fieldTypeName); if (fieldType == null) { fieldType = findOrCreateType(element.getNearestPackage(), fieldTypeName); } Property propertyObject = UMLFactory.eINSTANCE.createProperty(); // if (isGenericType(fieldType)) // { // // TODO : find the explicit type and define a template parameter // // extractGenericTypesFromCurrentSignature(fieldTypeSig); // } propertyObject.setName(fieldName); if (fieldType != null) { propertyObject.setType(fieldType); } attachJavadoc(propertyObject, field); //BOOKMARK //JWK: I'm hoping that getRawModifiers() = getFlags for IField. update(propertyObject, field.getRawModifiers()); // // No need to check the null (done with instanceof which returns always false) // if (field.getConstant() instanceof String) // { // LiteralString defaultValue = (LiteralString) propertyObject.createDefaultValue("", propertyObject.getType(), UMLFactory.eINSTANCE.createLiteralString().eClass()); // defaultValue.setValue((String) field.getConstant()); // } // else if (field.getConstant() instanceof Integer) // { // LiteralInteger defaultValue = (LiteralInteger) propertyObject.createDefaultValue("", propertyObject.getType(), UMLFactory.eINSTANCE.createLiteralInteger().eClass()); // defaultValue.setValue((Integer) field.getConstant()); // } // else if (field.getConstant() instanceof Boolean) // { // LiteralBoolean defaultValue = (LiteralBoolean) propertyObject.createDefaultValue("", propertyObject.getType(), UMLFactory.eINSTANCE.createLiteralBoolean().eClass()); // defaultValue.setValue((Boolean) field.getConstant()); // } return propertyObject; }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * @param ajElement/* w ww. j av a2s. co 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 w w w . j a v a 2 s . com*/ 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() + ") "); }/*from ww w. ja v a2s. c o m*/ }
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()); }// w ww. ja v a 2 s.c o m } } }
From source file:org.caesarj.ui.marker.AdviceMarkerGenerator.java
License:Open Source License
/** * Used to add Markers to the editor.//ww w . j a v 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$ } } }