List of usage examples for org.aspectj.asm IProgramElement getHandleIdentifier
public String getHandleIdentifier();
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
/** * @param ajElement/*from w ww .j a v a 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>) *//*w w w . j av a2s. 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 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()); }/* ww w .j av a2 s .com*/ } } }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
public IJavaElement programElementToJavaElement(IProgramElement ipe) { return programElementToJavaElement(ipe.getHandleIdentifier()); }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
/** * useful for testing/*www. j ava 2 s . c o m*/ */ public static String printHierarchy(IHierarchy h) { final StringBuffer sb = new StringBuffer(); HierarchyWalker walker = new HierarchyWalker() { int depth = 0; protected void preProcess(IProgramElement node) { sb.append(spaces(depth)); sb.append(node.getHandleIdentifier()); sb.append("\n"); depth += 2; } protected void postProcess(IProgramElement node) { depth -= 2; } String spaces(int depth) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < depth; i++) { sb.append(" "); } return sb.toString(); } }; h.getRoot().walk(walker); return sb.toString(); }
From source file:org.eclipse.ajdt.core.tests.model.AbstractModelTest.java
License:Open Source License
protected void checkHandles(IJavaProject jProject) throws Exception { final AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForJavaElement(jProject); final List<String> accumulatedErrors = new ArrayList<String>(); // check all the java handles IPackageFragment[] frags = jProject.getPackageFragments(); for (int i = 0; i < frags.length; i++) { ICompilationUnit[] units = frags[i].getCompilationUnits(); for (int j = 0; j < units.length; j++) { accumulatedErrors.addAll(walk(units[j], model)); }/*from w w w. ja va 2s .c o m*/ } // now check all the aj handles AsmManager asm = AspectJPlugin.getDefault().getCompilerFactory() .getCompilerForProject(jProject.getProject()).getModel(); IHierarchy hierarchy = asm.getHierarchy(); hierarchy.getRoot().walk(new HierarchyWalker() { protected void preProcess(IProgramElement node) { try { HandleTestUtils.checkAJHandle(node.getHandleIdentifier(), model); } catch (JavaModelException e) { throw new RuntimeException(e); } } }); if (accumulatedErrors.size() > 0) { StringBuffer sb = new StringBuffer(); sb.append("Found errors in comparing elements:\n"); for (String msg : accumulatedErrors) { sb.append(msg + "\n"); } fail(sb.toString()); } }
From source file:org.eclipse.ajdt.core.tests.model.AJCodeElementTest.java
License:Open Source License
/** * @param model//from ww w . ja v a 2 s .c om * @return */ private AJCodeElement[] createAJCodeElements(Map annotationsMap) { AJCodeElement[] arrayOfajce = new AJCodeElement[2]; Set keys = annotationsMap.keySet(); for (Iterator it = keys.iterator(); it.hasNext();) { Object key = it.next(); List annotations = (List) annotationsMap.get(key); for (Iterator it2 = annotations.iterator(); it2.hasNext();) { IProgramElement node = (IProgramElement) it2.next(); if (node.getHandleIdentifier().equals( "=AJProject83082/src<wpstest.aspectj{Main.java[Main~main~\\[QString;?method-call(void java.io.PrintStream.println(java.lang.String))") //$NON-NLS-1$ ) { IJavaElement ije = model.programElementToJavaElement(node); if (ije instanceof AJCodeElement) { arrayOfajce[0] = (AJCodeElement) ije; } } else if (node.getHandleIdentifier().equals( "=AJProject83082/src<wpstest.aspectj{Main.java[Main~main~\\[QString;?method-call(void java.io.PrintStream.println(java.lang.String))!2") //$NON-NLS-1$ ) { IJavaElement ije = model.programElementToJavaElement(node); if (ije instanceof AJCodeElement) { arrayOfajce[1] = (AJCodeElement) ije; } } } } return arrayOfajce; }
From source file:org.eclipse.ajdt.core.tests.newbuildconfig.BuildConfigurationTest.java
License:Open Source License
private void checkModel(IFile file) throws Exception { AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForProject(project); IJavaElement unit = JavaCore.create(file); if (model.hasProgramElement(unit)) { List accumulatedErrors = Collections.emptyList(); HandleTestUtils.checkJavaHandle(unit.getHandleIdentifier(), model); IProgramElement ipe = model.javaElementToProgramElement(unit); HandleTestUtils.checkAJHandle(ipe.getHandleIdentifier(), model); if (accumulatedErrors.size() > 0) { StringBuffer sb = new StringBuffer(); sb.append("Found errors in comparing elements:\n"); for (Iterator iterator = accumulatedErrors.iterator(); iterator.hasNext();) { String msg = (String) iterator.next(); sb.append(msg + "\n"); }//ww w. ja va 2 s. com fail(sb.toString()); } } }
From source file:org.eclipse.ajdt.core.tests.newbuildconfig.BuildConfigurationTest2.java
License:Open Source License
private void checkModel(IFile file) throws Exception { AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForProject(file.getProject()); IJavaElement unit = JavaCore.create(file); if (model.hasProgramElement(unit)) { List accumulatedErrors = HandleTestUtils.checkJavaHandle(unit.getHandleIdentifier(), model); IProgramElement ipe = model.javaElementToProgramElement(unit); HandleTestUtils.checkAJHandle(ipe.getHandleIdentifier(), model); if (accumulatedErrors.size() > 0) { StringBuffer sb = new StringBuffer(); sb.append("Found errors in comparing elements:\n"); for (Iterator iterator = accumulatedErrors.iterator(); iterator.hasNext();) { String msg = (String) iterator.next(); sb.append(msg + "\n"); }//from w ww .ja va 2 s.com fail(sb.toString()); } } }
From source file:org.eclipse.ajdt.internal.ui.visualiser.AJDTMarkupProvider.java
License:Open Source License
private void updateModel() { if (ProviderManager.getContentProvider() instanceof AJDTContentProvider) { IJavaProject jp = ((AJDTContentProvider) ProviderManager.getContentProvider()).getCurrentProject(); if (jp != null) { AJProjectModelFacade model = AJProjectModelFactory.getInstance() .getModelForProject(jp.getProject()); Collection<IRelationship> allRelationships = model .getRelationshipsForProject(new AJRelationshipType[] { AJRelationshipManager.ADVISED_BY, AJRelationshipManager.ANNOTATED_BY, AJRelationshipManager.ASPECT_DECLARATIONS, AJRelationshipManager.MATCHES_DECLARE }); if (allRelationships != null) { for (IRelationship relationship : allRelationships) { List<IMarkupKind> kinds = new ArrayList<IMarkupKind>(); IProgramElement sourceIpe = model.getProgramElement(relationship.getSourceHandle()); if (sourceIpe != null) { List<String> targets = relationship.getTargets(); for (String targetStr : targets) { IJavaElement target = model.programElementToJavaElement(targetStr); String simpleName; String qualifiedName; if (!(target instanceof IAJCodeElement)) { IJavaElement enclosingType = target.getAncestor(IJavaElement.TYPE); if (enclosingType == null) { // Bug 324706 I don't know why the sloc is null. Log the bug and // continue on. VisualiserPlugin.log(IStatus.WARNING, "Bug 324706: null containing type found for " + target.getElementName() + "\nHandle identifier is: " + target.getHandleIdentifier()); // avoid an npe continue; }//from www.j a v a2 s. c om simpleName = enclosingType.getElementName(); qualifiedName = ((IType) enclosingType).getFullyQualifiedName('.'); } else { // It's an injar aspect so we wno't be able to find the parents qualifiedName = target.getElementName(); String[] parts = qualifiedName.split(" "); //$NON-NLS-1$ String aNameWithExtension = parts[parts.length - 1]; if (aNameWithExtension.indexOf('.') != -1) { // $NON-NLS-1$ simpleName = aNameWithExtension.substring(0, aNameWithExtension.lastIndexOf('.')); // $NON-NLS-1$ } else { simpleName = aNameWithExtension; } } if (sourceIpe.getSourceLocation() == null) { // Bug 324706 I don't know why the sloc is null. Log the bug and // continue on. VisualiserPlugin.log(IStatus.WARNING, "Bug 324706: Warning, null source location found in " + sourceIpe.getName() + "\nHandle identifier is: " + sourceIpe.getHandleIdentifier()); // avoid an npe continue; } int lineNum = sourceIpe.getSourceLocation().getLine(); IJavaElement sourceJe = model .programElementToJavaElement(relationship.getSourceHandle()); if (sourceJe != null) { IJavaElement compilationUnitAncestor = sourceJe .getAncestor(IJavaElement.COMPILATION_UNIT); if (compilationUnitAncestor != null) { String memberName = compilationUnitAncestor.getElementName(); memberName = memberName.substring(0, memberName.lastIndexOf(".")); //$NON-NLS-1$ String packageName = sourceJe.getAncestor(IJavaElement.PACKAGE_FRAGMENT) .getElementName(); if (!(packageName.equals(""))) { //$NON-NLS-1$ memberName = packageName + "." + memberName; //$NON-NLS-1$ } IMarkupKind markupKind = null; if (kindMap == null) { kindMap = new HashMap<String, IMarkupKind>(); } if (relationship.getName() .equals(AJRelationshipManager.MATCHES_DECLARE.getDisplayName())) { String sourceName = target.getElementName(); boolean errorKind = sourceName.startsWith(aspectJErrorKind); if (kindMap.get( sourceName + ":::" + qualifiedName) instanceof IMarkupKind) { //$NON-NLS-1$ markupKind = kindMap.get(sourceName + ":::" + qualifiedName); //$NON-NLS-1$ } else { markupKind = new ErrorOrWarningMarkupKind( sourceName + ":::" + simpleName, errorKind); //$NON-NLS-1$ kindMap.put(sourceName + ":::" + qualifiedName, markupKind); //$NON-NLS-1$ } } else { if (kindMap.get(qualifiedName) instanceof IMarkupKind) { markupKind = kindMap.get(qualifiedName); } else { markupKind = new SimpleMarkupKind(simpleName, qualifiedName); kindMap.put(qualifiedName, markupKind); } } kinds.add(markupKind); Stripe stripe = new Stripe(kinds, lineNum, 1); addMarkup(memberName, stripe); } } } } } } } } processMarkups(); }