List of usage examples for org.aspectj.asm IProgramElement getParentTypes
public List<String> getParentTypes();
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 w ww . ja va 2 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 }; }
From source file:org.eclipse.ajdt.core.javaelements.DeclareElement.java
License:Open Source License
protected Object createElementInfo() { try {//from w w w .jav a2s .c o m IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForJavaElement(this) .javaElementToProgramElement(this); DeclareElementInfo elementInfo = new DeclareElementInfo(); if (ipe != IHierarchy.NO_STRUCTURE) { elementInfo.setSourceRangeStart(ipe.getSourceLocation().getOffset()); elementInfo.setName(name.toCharArray()); elementInfo.setAJKind(getKindForString(name)); List<String> types = ipe.getParentTypes(); if (types != null) { List<String> typesConverted = new ArrayList<String>(types.size()); for (String parentTypeName : types) { parentTypeName = parentTypeName.replaceAll("\\$", "\\."); typesConverted.add(parentTypeName); } elementInfo.setTypes((String[]) typesConverted.toArray(new String[typesConverted.size()])); } elementInfo.setAnnotationRemover(ipe.isAnnotationRemover()); } return elementInfo; } catch (Exception e) { // can fail for any of a number of reasons. // return null so that we can try again later. return null; } }
From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java
License:Open Source License
private boolean isClass(IProgramElement elt) throws JavaModelException { List<String> parentTypes = elt.getParentTypes(); if (parentTypes != null && parentTypes.size() > 0) { for (String parentTypeName : parentTypes) { int genericsIndex = parentTypeName.indexOf("<"); if (genericsIndex > 0) { parentTypeName = parentTypeName.substring(0, genericsIndex); }/*from w ww . j a v a 2 s .c o m*/ IType parentType = unit.getJavaProject().findType(parentTypeName, (IProgressMonitor) null); if (parentType != null) { return parentType.isClass(); } } } // don't really know return false; }
From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java
License:Open Source License
private void addSuperClass(IProgramElement ipe, TypeDeclaration decl) { List<String> types = ipe.getParentTypes(); if (types == null || types.size() < 1) return;/*from ww w.j a v a2 s . co m*/ String typeName = types.get(0); addSuperClass(typeName, decl); }
From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java
License:Open Source License
private void addSuperInterfaces(IProgramElement ipe, TypeDeclaration decl) { List<String> newInterfaces = ipe.getParentTypes(); if (newInterfaces != null) { List<String> copy = new ArrayList<String>(newInterfaces.size()); for (String newInterface : newInterfaces) { copy.add(newInterface.replace('$', '.')); }//w ww. j ava 2 s . c o m addSuperInterfaces(newInterfaces, decl); } }
From source file:org.eclipse.ajdt.internal.ui.refactoring.PushInRefactoring.java
License:Open Source License
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor) throws CoreException, OperationCanceledException { final RefactoringStatus status = new RefactoringStatus(); try {//ww w .j a v a2 s . c o m monitor.beginTask("Checking final conditions...", 2); allChanges = new LinkedHashMap<ICompilationUnit, Change>(); // map from AJCUs to contained ITDs that will be pushed in Map<ICompilationUnit, List<IMember>> unitToITDs = new HashMap<ICompilationUnit, List<IMember>>(); Map<ICompilationUnit, PerUnitInformation> importsMap = new HashMap<ICompilationUnit, PerUnitInformation>(); for (IMember itd : itds) { if (itd instanceof IAspectJElement && ((IAspectJElement) itd).getAJKind() == Kind.DECLARE_PARENTS) { AJProjectModelFacade model = getModel(itd); // rememebr the types pushed in and associate them with the target types List<IJavaElement> elts = model.getRelationshipsForElement(itd, AJRelationshipManager.DECLARED_ON); IProgramElement ipe = model.javaElementToProgramElement(itd); List<String> parentTypes = ipe.getParentTypes(); for (IJavaElement elt : elts) { if (elt.getElementType() == IJavaElement.TYPE) { IType type = (IType) elt; ICompilationUnit owningUnit = type.getCompilationUnit(); PerUnitInformation holder = importsMap.get(owningUnit); if (holder == null) { holder = new PerUnitInformation(owningUnit); importsMap.put(owningUnit, holder); } holder.addDeclarParents(type, parentTypes); } } } // remember the ITDs per compilation unit so that we can remove them later ICompilationUnit unit = itd.getCompilationUnit(); List<IMember> itdList = unitToITDs.get(unit); if (itdList == null) { itdList = new LinkedList<IMember>(); unitToITDs.put(unit, itdList); } itdList.add(itd); } // now do the work ITDs and declare annotation for (Map.Entry<ICompilationUnit, List<IMember>> entry : unitToITDs.entrySet()) { status.merge(checkFinalConditionsForITD(entry.getKey(), entry.getValue(), importsMap, monitor)); } // now go through and create the import edits for (PerUnitInformation holder : importsMap.values()) { holder.rewriteImports(); } } finally { allLookups.clear(); allModels.clear(); monitor.done(); } return status; }