List of usage examples for org.aspectj.asm IProgramElement getDeclareParentsMap
public Map<String, List<String>> getDeclareParentsMap();
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// ww w. ja v a2s .co 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 }; }
From source file:org.eclipse.ajdt.core.javaelements.ITDAwareSourceTypeInfo.java
License:Open Source License
private List<IJavaElement> getITDs(SourceType type) throws JavaModelException { AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForJavaElement(type); if (model.hasModel()) { List<IJavaElement> itds = new ArrayList<IJavaElement>(); List<IJavaElement> rels = model.getRelationshipsForElement(type, AJRelationshipManager.ASPECT_DECLARATIONS); List<IMethod> childMethods = null; for (IJavaElement ije : rels) { if (ije instanceof IntertypeElement) { IntertypeElement elt = (IntertypeElement) ije; IMember member = elt.createMockDeclaration(type); // null if the ITD doesn't exist in the AspectJ hierarchy // will happen if the Java side has partial compilation // and aspectj side does not if (member != null) { // should not add this ITD if it is a duplicate // of another ITD if (!isAlreadyAnITD(itds, member)) { continue; }// w ww. ja v a 2 s . co m itds.add(member); // additional processing for interfaces if (handle.isInterface()) { if (member.getElementType() == IJavaElement.FIELD) { // Bug 262969 // Interfaces can't have fields, so ignore // Reconciling errors occur if an ITD field is // referenced outside of the aspect that declares them, // but only if the declared type of the object is an interface. itds.remove(member); } else if (member.getElementType() == IJavaElement.METHOD) { // now look to see if this ITD a method that provides // a default implementation for an interface method // use IMethod.isSimilar if (childMethods == null) { childMethods = (List<IMethod>) type.getChildrenOfType(IJavaElement.METHOD); } for (IMethod method : childMethods) { if (method.isSimilar((IMethod) member)) { itds.remove(member); break; } } } } } } else if (ije instanceof DeclareElement) { DeclareElement elt = (DeclareElement) ije; // use createElementInfo, not getElementInfo because // we don't want it cached DeclareElementInfo info = (DeclareElementInfo) elt.createElementInfo(); if (info == null || info.getAJKind() != Kind.DECLARE_PARENTS) { continue; } char[][] newSupers = info.getTypes(); augmentHierarchy(newSupers); } else if (ije instanceof AspectElement || ije instanceof BinaryAspectElement) { // likely a declare parents instantiated in a concrete aspect, but declared in a super aspect IProgramElement ipe = model.javaElementToProgramElement(ije); Map<String, List<String>> declareParentsMap = ipe.getDeclareParentsMap(); if (declareParentsMap != null) { augmentHierarchy(declareParentsMap.get(type.getFullyQualifiedName())); } } else if (ije instanceof IType) { // an ITIT itds.add(new ITIT(type, (IType) ije, model.javaElementToProgramElement(ije))); } } return itds; } return new LinkedList<IJavaElement>(); }
From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java
License:Open Source License
/** * augments a type with ITD info/*from w w w . j a v a 2 s .c o m*/ */ private void augmentType(TypeDeclaration type) { OrigContents orig = new OrigContents(); orig.methods = type.methods; orig.fields = type.fields; orig.superClass = type.superclass; orig.superInterfaces = type.superInterfaces; orig.memberTypes = type.memberTypes; try { List<FieldDeclaration> itdFields = new LinkedList<FieldDeclaration>(); List<AbstractMethodDeclaration> itdMethods = new LinkedList<AbstractMethodDeclaration>(); List<TypeDeclaration> itits = new LinkedList<TypeDeclaration>(); IType handle = getHandle(type); List<IProgramElement> ipes = getITDs(handle); for (IProgramElement elt : ipes) { if (elt.getKind() == IProgramElement.Kind.INTER_TYPE_METHOD) { // ignore if type is an interface. // assumption is that this ITD is an implementation of an interface method // adding it here would cause a duplicate method error. // These are added to the first class that instantiates this interface // See bug 257437 if (TypeDeclaration.kind(type.modifiers) == TypeDeclaration.CLASS_DECL) { if (elt.getAccessibility() != IProgramElement.Accessibility.PRIVATE) { itdMethods.add(createMethod(elt, type, handle)); } } } else if (elt.getKind() == IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR) { if (elt.getAccessibility() != IProgramElement.Accessibility.PRIVATE) { itdMethods.add(createConstructor(elt, type)); } } else if (elt.getKind() == IProgramElement.Kind.INTER_TYPE_FIELD) { // XXX hmmmm..should I also skip this if the type is an interface??? if (elt.getAccessibility() != IProgramElement.Accessibility.PRIVATE) { itdFields.add(createField(elt, type)); } } else if (elt.getKind() == IProgramElement.Kind.DECLARE_PARENTS) { boolean isClass = isClass(elt); if (isClass && TypeDeclaration.kind(type.modifiers) == TypeDeclaration.CLASS_DECL) { addSuperClass(elt, type); } else { addSuperInterfaces(elt, type); } } else if (elt.getKind() == IProgramElement.Kind.CLASS) { // this is an ITIT - intertype inner type TypeDeclaration ititAST = createITIT(elt.getName(), type); if (ititAST != null) { // add children, etc populateITIT(ititAST, elt); itits.add(ititAST); } } else if (elt.getKind() == IProgramElement.Kind.ASPECT) { // probably an instantiation of a declare parents relationship from an abstact aspect Map<String, List<String>> parentsMap = elt.getDeclareParentsMap(); if (parentsMap != null && type.binding != null && type.binding.compoundName != null) { List<String> parents = parentsMap .get(String.valueOf(CharOperation.concatWith(type.binding.compoundName, '.'))); List<String> interfacesToAdd = new LinkedList<String>(); for (String parent : parents) { try { IType parentElt = unit.getJavaProject().findType(parent, (IProgressMonitor) null); if (parentElt != null && parentElt.isClass()) { addSuperClass(parent, type); } else if (parentElt != null && parentElt.isInterface()) { interfacesToAdd.add(parent); } } catch (JavaModelException e) { } } addSuperInterfaces(interfacesToAdd, type); } } } if (ipes.size() > 0) { origMap.put(type, orig); // now add the ITDs into the declaration if (itdFields.size() > 0) { int numFields = type.fields == null ? 0 : type.fields.length; FieldDeclaration[] fields = new FieldDeclaration[numFields + itdFields.size()]; if (numFields > 0) { System.arraycopy(type.fields, 0, fields, 0, numFields); } for (int i = 0; i < itdFields.size(); i++) { fields[i + numFields] = itdFields.get(i); } type.fields = fields; } if (itdMethods.size() > 0) { int numMethods = type.methods == null ? 0 : type.methods.length; AbstractMethodDeclaration[] methods = new AbstractMethodDeclaration[numMethods + itdMethods.size()]; if (numMethods > 0) { System.arraycopy(type.methods, 0, methods, 0, numMethods); } for (int i = 0; i < itdMethods.size(); i++) { methods[i + numMethods] = itdMethods.get(i); } type.methods = methods; } if (itits.size() > 0) { int numInners = type.memberTypes == null ? 0 : type.memberTypes.length; TypeDeclaration[] inners = new TypeDeclaration[numInners + itits.size()]; if (numInners > 0) { System.arraycopy(type.memberTypes, 0, inners, 0, numInners); } for (int i = 0; i < itits.size(); i++) { inners[i + numInners] = itits.get(i); } type.memberTypes = inners; } } } catch (Exception e) { // back out what we have done origMap.remove(type); revertType(type, orig); } }
From source file:org.eclipse.ajdt.internal.ui.editor.AdviceActionDelegate.java
License:Open Source License
/** * // w ww .jav a2 s . c om * @param javaElements * @param manager * @param addedSeparator * @param relationshipType * @return */ private boolean createMenuForRelationshipType(List<IJavaElement> javaElements, IMenuManager manager, boolean addedMenu, AJRelationshipType relationshipType, AJProjectModelFacade model) { boolean menuInitialized = false; MenuManager menu = null; for (IJavaElement element : javaElements) { List<IJavaElement> relationships = model.getRelationshipsForElement(element, relationshipType); if (relationships != null) { addedMenu = true; for (IJavaElement el : relationships) { if (!menuInitialized) { menu = new MenuManager(relationshipType.getMenuName()); manager.add(menu); menuInitialized = true; } // link might be in a different project String linkName = model.getJavaElementLinkName(el); String extra = ""; // might be a declare parents instantiated in a concrete aspect if (relationshipType == AJRelationshipManager.ASPECT_DECLARATIONS && el instanceof AspectElement && element instanceof IType) { IProgramElement ipe = model.javaElementToProgramElement(el); Map<String, List<String>> parentsMap = ipe.getDeclareParentsMap(); if (parentsMap != null) { List<String> parents = parentsMap.get(((IType) element).getFullyQualifiedName()); if (parents != null && parents.size() > 0) { extra = "declare parents: "; for (String parent : parents) { extra += parent; extra += ", "; } extra += "instantiated in "; } } } linkName = extra + linkName; menu.add(new MenuAction(el, linkName)); } } } return addedMenu; }