List of usage examples for org.eclipse.jdt.core IJavaElement getHandleIdentifier
String getHandleIdentifier();
From source file:org.eclipse.ajdt.core.tests.codeselect.AbstractITDAwareCodeSelectionTests.java
License:Open Source License
protected void validateCodeSelect(ICompilationUnit unit, IRegion region, String expectedSrcFile, String expectedSignature) throws Exception { IJavaElement[] result = unit.codeSelect(region.getOffset(), region.getLength()); assertEquals("Should have found exactly one hyperlink", 1, result.length); IJavaElement elt = result[0]; assertTrue("Java element " + elt.getHandleIdentifier() + " should exist", elt.exists()); String actualSrcFile = elt.getResource().getFullPath().toString(); assertTrue("Element found is in the wrong source file:\n" + " expected: " + expectedSrcFile + "\n" + " found: " + actualSrcFile, actualSrcFile.endsWith(expectedSrcFile)); assertEquals("Element found has wrong signature", expectedSignature, getSignature(elt)); }
From source file:org.eclipse.ajdt.core.tests.model.AbstractModelTest.java
License:Open Source License
private Collection<String> walk(IJavaElement elt, AJProjectModelFacade model) throws Exception { final List<String> accumulatedErrors = new ArrayList<String>(); accumulatedErrors.addAll(HandleTestUtils.checkJavaHandle(elt.getHandleIdentifier(), model)); if (elt instanceof IParent) { IParent parent = (IParent) elt;//w w w . j a v a2s . c o m IJavaElement[] children = parent.getChildren(); for (int i = 0; i < children.length; i++) { accumulatedErrors.addAll(walk(children[i], model)); } } return accumulatedErrors; }
From source file:org.eclipse.ajdt.core.tests.model.BinaryWeavingSupportTest.java
License:Open Source License
public void testBug160236() throws Exception { IProject project = createPredefinedProject("bug160236"); //$NON-NLS-1$ AJProjectModelFacade model = AJProjectModelFactory.getInstance().getModelForProject(project); AJRelationshipType[] rels = new AJRelationshipType[] { AJRelationshipManager.ADVISED_BY }; List allRels = model.getRelationshipsForProject(rels); boolean found1 = false; boolean found2 = false; boolean found3 = false; for (Iterator iter = allRels.iterator(); iter.hasNext();) { IRelationship rel = (IRelationship) iter.next(); String sourceName = model.programElementToJavaElement(rel.getSourceHandle()).getElementName(); if (sourceName.equals("Sample")) { //$NON-NLS-1$ for (Iterator targetIter = rel.getTargets().iterator(); targetIter.hasNext();) { IJavaElement targetElt = model.programElementToJavaElement((String) targetIter.next()); if ((targetElt.getElementName().equals("afterReturning")) //$NON-NLS-1$ && (targetElt.getParent().getElementName().equals("AbstractBeanConfigurerAspect"))) { //$NON-NLS-1$ found1 = true;/*from ww w . ja v a2 s . c o m*/ } else if ((targetElt.getElementName().equals("before")) //$NON-NLS-1$ && (targetElt.getParent().getElementName().equals("AbstractBeanConfigurerAspect"))) { //$NON-NLS-1$ found2 = true; } else { fail("Unexpected target found: " + targetElt.getHandleIdentifier()); //$NON-NLS-1$ } } } else if (sourceName.equals("main")) { //$NON-NLS-1$ for (Iterator targetIter = rel.getTargets().iterator(); targetIter.hasNext();) { IJavaElement targetElt = model.programElementToJavaElement((String) targetIter.next()); if ((targetElt.getElementName().equals("before")) //$NON-NLS-1$ && (targetElt.getParent().getElementName().equals("AnnotationBeanConfigurerAspect"))) { //$NON-NLS-1$ found3 = true; } else { fail("Unexpected target found: " + targetElt.getHandleIdentifier()); //$NON-NLS-1$ } } } } assertTrue("Didn't find Sample advised by afterReturning() binary aspect relationship", found1); //$NON-NLS-1$ assertTrue("Didn't find Sample advised by before() binary aspect relationship", found2); //$NON-NLS-1$ assertTrue("Didn't find main advised by before() binary aspect relationship", found3); //$NON-NLS-1$ }
From source file:org.eclipse.ajdt.core.tests.model.InpathRelationshipsTests.java
License:Open Source License
public void testInPathRelationshipsNonDefault() throws Exception { IFile file = target.getFile("src/snippet/AdvisesLinked.aj"); AJCompilationUnit unit = (AJCompilationUnit) AspectJCore.create(file); Set /*IType*/ targetTypes = gatherTargetTypesNonDefault(); Map relationships = model.getRelationshipsForFile(unit); assertEquals("Should have found 15 relationships in the compilation unit", 15, relationships.size()); for (Iterator allRelsIter = relationships.values().iterator(); allRelsIter.hasNext();) { List rels = (List) allRelsIter.next(); for (Iterator relsIter = rels.iterator(); relsIter.hasNext();) { IRelationship rel = (IRelationship) relsIter.next(); for (Iterator targetIter = rel.getTargets().iterator(); targetIter.hasNext();) { String targetHandle = (String) targetIter.next(); IJavaElement elt = model.programElementToJavaElement(targetHandle); assertTrue("Java element should exist: " + elt.getHandleIdentifier(), elt.exists()); targetTypes.remove(elt); }/*from ww w . ja v a 2 s.co m*/ } } assertTrue("The following types should have been a target of an ITD:\n" + printTargetTypes(targetTypes), targetTypes.size() == 0); }
From source file:org.eclipse.ajdt.core.tests.model.InpathRelationshipsTests.java
License:Open Source License
public void testInPathRelationshipsDefault() throws Exception { IFile file = target.getFile("src/AdvisesLinkedDefault.aj"); AJCompilationUnit unit = (AJCompilationUnit) AspectJCore.create(file); Set /*IType*/ targetTypes = gatherTargetTypesDefault(); Map relationships = model.getRelationshipsForFile(unit); assertEquals("Should have found 15 relationships in the compilation unit", 15, relationships.size()); for (Iterator allRelsIter = relationships.values().iterator(); allRelsIter.hasNext();) { List rels = (List) allRelsIter.next(); for (Iterator relsIter = rels.iterator(); relsIter.hasNext();) { IRelationship rel = (IRelationship) relsIter.next(); for (Iterator targetIter = rel.getTargets().iterator(); targetIter.hasNext();) { String targetHandle = (String) targetIter.next(); IJavaElement elt = model.programElementToJavaElement(targetHandle); assertTrue("Java element should exist: " + elt.getHandleIdentifier(), elt.exists()); targetTypes.remove(elt); }/*ww w .ja v a 2s.c o m*/ } } assertTrue("The following types should have been a target of an ITD:\n" + printTargetTypes(targetTypes), targetTypes.size() == 0); }
From source file:org.eclipse.ajdt.core.tests.model.MultipleProjectModelTests.java
License:Open Source License
private void roundTripCheck(IType otherType, IJavaElement orig) throws JavaModelException { assertTrue("Should exist: " + orig.getHandleIdentifier(), orig.exists()); assertEquals(otherType, orig.getParent()); assertTrue("" + orig + " should be a child of " + otherType, isAChildOf(otherType, orig)); IProgramElement ipe = model.javaElementToProgramElement(orig); assertNotSame(IHierarchy.NO_STRUCTURE, ipe); orig = model.programElementToJavaElement(ipe); assertTrue("Should exist: " + orig.getHandleIdentifier(), orig.exists()); assertEquals(otherType, orig.getParent()); assertTrue("" + orig + " should be a child of " + otherType, isAChildOf(otherType, orig)); }
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"); }/*from w w w. j a va2 s.c o m*/ 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"); }/* w ww . j a v a2 s.c o m*/ 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 w w w . j a v a 2 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(); }
From source file:org.eclipse.ajdt.mylyn.ui.AspectJStructureBridge.java
License:Open Source License
@Override public String getHandleForOffsetInObject(Object object, int offset) { IMarker marker;/*from w w w . j a va 2s .com*/ int charStart = 0; if (object instanceof ConcreteMarker) { marker = ((ConcreteMarker) object).getMarker(); } else if (object instanceof IMarker) { marker = (IMarker) object; } else { return null; } Object attribute = marker.getAttribute(IMarker.CHAR_START, 0); if (attribute instanceof Integer) { charStart = ((Integer) attribute).intValue(); } try { ICompilationUnit compilationUnit = null; IResource resource = marker.getResource(); if (resource instanceof IFile) { IFile file = (IFile) resource; // TODO: get rid of file extension check if (file.getFileExtension().equals("aj")) { compilationUnit = JavaCore.createCompilationUnitFrom(file); } else { return null; } } if (compilationUnit != null) { IJavaElement javaElement = compilationUnit.getElementAt(charStart); if (javaElement != null) { if (javaElement instanceof IImportDeclaration) javaElement = javaElement.getParent().getParent(); return javaElement.getHandleIdentifier(); } else { return null; } } else { return null; } } catch (JavaModelException ex) { if (!ex.isDoesNotExist()) ExceptionHandler.handle(ex, "error", "could not find java element"); //$NON-NLS-2$ //$NON-NLS-1$ return null; } catch (Throwable t) { StatusHandler.log(new Status(IStatus.ERROR, AspectJStructureBridgePlugin.PLUGIN_ID, "Could not find element for: " + marker, t)); return null; } }