List of usage examples for org.aspectj.asm IProgramElement toLabelString
public String toLabelString(boolean getFullyQualifiedArgTypes);
From source file:org.eclipse.ajdt.core.tests.model.AJModelTest.java
License:Open Source License
private void mappingTestForFile(IProject project, String filename, String[][] results) { IFile file = (IFile) project.findMember(filename); if (file == null) fail("Required file not found: " + filename); //$NON-NLS-1$ String path = file.getRawLocation().toOSString(); AsmManager asm = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project.getProject()) .getModel();//w ww. j a v a 2s . c o m Map annotationsMap = asm.getInlineAnnotations(path, true, true); assertNotNull("Didn't get annotations map for file: " + path, annotationsMap); //$NON-NLS-1$ ICompilationUnit unit = AJCompilationUnitManager.INSTANCE.getAJCompilationUnit(file); if (unit == null) { unit = JavaCore.createCompilationUnitFrom(file); } assertNotNull("Didn't get a compilation unit from file: " + path, unit); //$NON-NLS-1$ List toFind = new ArrayList(); List toMatch = new ArrayList(); for (int i = 0; i < results.length; i++) { toFind.add(results[i][0].intern()); toMatch.add(results[i][1].intern()); } AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForProject(project); 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(); String peName = node.toLabelString(false).intern(); IJavaElement je = model.programElementToJavaElement(node); if (je == null) { System.out.println("je is null"); //$NON-NLS-1$ continue; } String jaName = je.getElementName().intern(); int index = toFind.indexOf(peName); if (index == -1) { fail("Unexpected additional IProgramElement name found: " + peName); //$NON-NLS-1$ } else { String expected = (String) toMatch.get(index); if (expected.equals(jaName)) { toFind.remove(index); toMatch.remove(index); } else { fail("Incorrect corresponding Java element. Found: " + jaName + " Expected: " + expected); //$NON-NLS-1$ //$NON-NLS-2$ } } } } // check that we found everything we were looking for if (toFind.size() > 0) { String missing = ""; //$NON-NLS-1$ for (int j = 0; j < toFind.size(); j++) { missing += System.getProperty("line.separator"); //$NON-NLS-1$ missing += (String) toFind.get(j); } fail("Did not find all expected IProgramElement names. Missing: " + missing); //$NON-NLS-1$ } }
From source file:org.eclipse.ajdt.core.tests.model.AJModelTest3.java
License:Open Source License
private void mappingTestForFile(IProject project, String filename, String[][] results) { IFile file = (IFile) project.findMember(filename); if (file == null) fail("Required file not found: " + filename); //$NON-NLS-1$ String path = file.getRawLocation().toOSString(); AsmManager asm = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project.getProject()) .getModel();// w w w.j a v a 2s.c o m Map annotationsMap = asm.getInlineAnnotations(path, true, true); AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForProject(project); assertNotNull("Didn't get annotations map for file: " + path, annotationsMap); //$NON-NLS-1$ ICompilationUnit unit = AJCompilationUnitManager.INSTANCE.getAJCompilationUnit(file); if (unit == null) { unit = JavaCore.createCompilationUnitFrom(file); } assertNotNull("Didn't get a compilation unit from file: " + path, unit); //$NON-NLS-1$ List toFind = new ArrayList(); List toMatch = new ArrayList(); for (int i = 0; i < results.length; i++) { toFind.add(results[i][0].intern()); toMatch.add(results[i][1].intern()); } 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 pe = (IProgramElement) it2.next(); String peName = pe.toLabelString(false).intern(); IJavaElement je = model.programElementToJavaElement(pe); if (je == null) { fail("je is null"); //$NON-NLS-1$ } String jaName = je.getElementName(); int index = toFind.indexOf(peName); if (index == -1) { fail("Unexpected additional IProgramElement name found: " + peName); //$NON-NLS-1$ } else { String expected = (String) toMatch.get(index); if (expected.equals(jaName)) { toFind.remove(index); toMatch.remove(index); } else { fail("Incorrect corresponding Java element. Found: " + jaName + " Expected: " + expected); //$NON-NLS-1$ //$NON-NLS-2$ } } } } // check that we found everything we were looking for if (toFind.size() > 0) { String missing = ""; //$NON-NLS-1$ for (int j = 0; j < toFind.size(); j++) { missing += System.getProperty("line.separator"); //$NON-NLS-1$ missing += (String) toFind.get(j); } fail("Did not find all expected IProgramElement names. Missing: " + missing); //$NON-NLS-1$ } }