Example usage for org.eclipse.jdt.core IJavaElement exists

List of usage examples for org.eclipse.jdt.core IJavaElement exists

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement exists.

Prototype

boolean exists();

Source Link

Document

Returns whether this Java element exists in the model.

Usage

From source file:org.eclipse.objectteams.otdt.internal.ui.callinmarkers.UpdateRulerAction.java

License:Open Source License

private IAction createOpenEditorAction(String label, final IJavaElement target) {
    Action result = new Action(label) {
        public void run() {
            try {
                IEditorPart part = EditorUtility.openInEditor(target);
                if (target.exists()) // also initializes source positions if necessary
                    EditorUtility.revealInEditor(part, target);
            } catch (PartInitException ex) {
                OTDTUIPlugin.logException("Problems initializing editor", ex); //$NON-NLS-1$
            }/*from   w w  w .j a  v a  2 s . c o  m*/
        }
    };

    return result;
}

From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java

License:Open Source License

protected void assertElementExists(String message, String expected, IJavaElement element) {
    assertElementEquals(message, expected, element);
    if (element != null && !element.exists()) {
        fail(((JavaElement) element).toStringWithAncestors(false/*don't show key*/) + " doesn't exist");
    }/*  w  w w . j  a v a 2  s  .c  om*/
}

From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java

License:Open Source License

/**
 * Ensures the elements are present after creation.
 *///  w  w w.  j  av  a 2  s  . com
public void assertCreation(IJavaElement[] newElements) {
    for (int i = 0; i < newElements.length; i++) {
        IJavaElement newElement = newElements[i];
        assertTrue("Element should be present after creation", newElement.exists());
    }
}

From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java

License:Open Source License

/**
 * Creates an operation to delete the given elements, asserts
 * the operation is successful, and ensures the elements are no
 * longer present in the model.//from  ww w . j  a  v a  2s  .  c  o  m
 */
public void assertDeletion(IJavaElement[] elementsToDelete) throws JavaModelException {
    IJavaElement elementToDelete = null;
    for (int i = 0; i < elementsToDelete.length; i++) {
        elementToDelete = elementsToDelete[i];
        assertTrue("Element must be present to be deleted", elementToDelete.exists());
    }

    getJavaModel().delete(elementsToDelete, false, null);

    for (int i = 0; i < elementsToDelete.length; i++) {
        elementToDelete = elementsToDelete[i];
        assertTrue("Element should not be present after deletion: " + elementToDelete,
                !elementToDelete.exists());
    }
}

From source file:org.eclipse.objectteams.otdt.tests.otmodel.CallinMappingTest.java

License:Open Source License

public void testMapping1FromMemento() throws JavaModelException {
    IRoleType roleOTElem = getRoleOTElem();
    assertNotNull(roleOTElem);/*from www . ja va  2 s . c  om*/
    IMethodMapping[] callinMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLINS);

    IMethodMapping mapping = callinMethodMappings[0];
    assertNotNull(mapping);

    String token = mapping.getHandleIdentifier();

    SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement();
    IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner());

    assertEquals("Elements should be equal", mapping, fromMemento);

    assertTrue("Element should exist", fromMemento.exists());

    assertFalse("Mapping should not have signature", ((IMethodMapping) fromMemento).hasSignature());
}

From source file:org.eclipse.objectteams.otdt.tests.otmodel.CallinMappingTest.java

License:Open Source License

public void testMapping5FromMemento() throws JavaModelException {
    IRoleType roleOTElem = getRoleOTElem();
    assertNotNull(roleOTElem);//from  w w  w  . jav a 2  s.c  om
    IMethodMapping[] callinMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLINS);

    IMethodMapping mapping = callinMethodMappings[4];
    assertNotNull(mapping);

    assertNotNull(mapping);

    String token = mapping.getHandleIdentifier();

    SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement();
    IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner());

    assertEquals("Elements should be equal", mapping, fromMemento);

    assertTrue("Element should exist", fromMemento.exists());

    ICallinMapping callinMapping = (ICallinMapping) fromMemento;
    IMethod[] boundBaseMethods = callinMapping.getBoundBaseMethods();
    assertNotNull(boundBaseMethods);
    assertEquals(2, boundBaseMethods.length);
    assertEquals("baseMethod3", boundBaseMethods[0].getElementName());
    assertEquals("baseMethod4", boundBaseMethods[1].getElementName());
}

From source file:org.eclipse.objectteams.otdt.tests.otmodel.CallinMappingTest.java

License:Open Source License

public void testMapping7FromMemento() throws JavaModelException {
    IRoleType roleOTElem = getRoleOTElem();
    assertNotNull(roleOTElem);/*www.j a  v a2 s . co m*/
    IMethodMapping[] callinMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLINS);

    IMethodMapping mapping = callinMethodMappings[6];
    assertNotNull(mapping);

    String token = mapping.getHandleIdentifier();

    SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement();
    IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner());

    assertEquals("Elements should be equal", mapping, fromMemento);

    assertTrue("Element should exist", fromMemento.exists());

    assertTrue("Mapping should have signature", ((IMethodMapping) fromMemento).hasSignature());
}

From source file:org.eclipse.objectteams.otdt.tests.otmodel.CalloutMappingTest.java

License:Open Source License

public void testMapping1FromMemento() throws JavaModelException {
    IRoleType roleOTElem = getRoleOTElem();
    assertNotNull(roleOTElem);// w  w  w.j av  a 2 s  .  c  om
    IMethodMapping[] calloutMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLOUTS);

    IMethodMapping mapping = calloutMethodMappings[0];
    assertNotNull(mapping);

    String token = mapping.getHandleIdentifier();

    SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement();
    IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner());

    assertEquals("Elements should be equal", mapping, fromMemento);

    assertTrue("Element should exist", fromMemento.exists());

    assertTrue("Mapping should have signature", ((IMethodMapping) fromMemento).hasSignature());
}

From source file:org.eclipse.objectteams.otdt.tests.otmodel.CalloutMappingTest.java

License:Open Source License

public void testMapping2FromMemento() throws JavaModelException {
    IRoleType roleOTElem = getRoleOTElem();
    assertNotNull(roleOTElem);//from  ww  w .  j  av a 2  s.com
    IMethodMapping[] calloutMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLOUTS);

    IMethodMapping mapping = calloutMethodMappings[1];
    assertNotNull(mapping);

    String token = mapping.getHandleIdentifier();

    SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement();
    IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner());

    assertEquals("Elements should be equal", mapping, fromMemento);

    assertTrue("Element should exist", fromMemento.exists());

    assertFalse("Mapping should not have signature", ((IMethodMapping) fromMemento).hasSignature());
}

From source file:org.eclipse.objectteams.otdt.tests.otmodel.CalloutMappingTest.java

License:Open Source License

public void testMapping3FromMemento() throws JavaModelException {
    IRoleType roleOTElem = getRoleOTElem();
    assertNotNull(roleOTElem);/* w  ww.ja  v  a  2s . c  om*/
    IMethodMapping[] calloutMethodMappings = roleOTElem.getMethodMappings(IRoleType.CALLOUTS);

    IMethodMapping mapping = calloutMethodMappings[2];
    assertNotNull(mapping);

    String token = mapping.getHandleIdentifier();

    SourceType sourceType = (SourceType) roleOTElem.getCorrespondingJavaElement();
    IJavaElement fromMemento = JavaCore.create(token, sourceType.getCompilationUnit().getOwner());

    assertEquals("Elements should be equal", mapping, fromMemento);

    assertTrue("Element should exist", fromMemento.exists());

    ICalloutMapping mappingFromMemento = (ICalloutMapping) fromMemento;
    assertTrue("Mapping should have signature", mappingFromMemento.hasSignature());

    assertTrue("Expecting 1 role parameter",
            mappingFromMemento.getRoleMethodHandle().getArgumentTypes().length == 1);
    assertTrue("Expecting 2 base parameters",
            mappingFromMemento.getBaseMethodHandle().getArgumentTypes().length == 2);
}