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

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

Introduction

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

Prototype

IJavaElement getAncestor(int ancestorType);

Source Link

Document

Returns this Java element or the first ancestor of this element that has the given type.

Usage

From source file:com.siteview.mde.internal.ui.refactoring.ManifestTypeMoveParticipant.java

License:Open Source License

protected boolean isInterestingForExtensions() {
    Object dest = getArguments().getDestination();
    if (dest instanceof IJavaElement) {
        IJavaElement destination = (IJavaElement) dest;
        IJavaProject jProject = (IJavaProject) destination.getAncestor(IJavaElement.JAVA_PROJECT);
        return jProject.getProject().equals(fProject);
    }/*w  w w  . j  ava  2  s.  co m*/
    return false;
}

From source file:com.versant.core.jdo.tools.plugins.eclipse.popup.actions.AddPersistentClass.java

License:Open Source License

public void setISelection(ISelection iSelection) {
    className = null;//from ww w.  j av a2s . c om
    iProject = null;
    IProject proj = null;
    if (iSelection instanceof StructuredSelection) {
        StructuredSelection sS = (StructuredSelection) iSelection;
        Object el = sS.getFirstElement();
        if (el instanceof IJavaElement) {
            IJavaElement javaElement = ((IJavaElement) el);
            proj = javaElement.getJavaProject().getProject();
            IType selectedClass = (IType) javaElement.getAncestor(IJavaElement.TYPE);
            if (selectedClass != null) {
                className = selectedClass.getFullyQualifiedName();
            }
        }
    }
    if (proj != null) {
        iProject = proj;
    }
}

From source file:com.versant.core.jdo.tools.plugins.eclipse.popup.actions.TogglePersistentField.java

License:Open Source License

public void setISelection(ISelection iSelection) {
    fieldName = null;/*from   w  w  w.  ja  v  a2 s  .c  om*/
    className = null;
    iProject = null;
    IProject proj = null;
    if (iSelection instanceof StructuredSelection) {
        StructuredSelection sS = (StructuredSelection) iSelection;
        Object el = sS.getFirstElement();
        if (el instanceof IJavaElement) {
            IJavaElement javaElement = ((IJavaElement) el);
            proj = javaElement.getJavaProject().getProject();
            IType selectedClass = (IType) javaElement.getAncestor(IJavaElement.TYPE);
            if (selectedClass != null) {
                className = selectedClass.getFullyQualifiedName();
            }
            IField selectedField = (IField) javaElement.getAncestor(IJavaElement.FIELD);
            if (selectedField != null) {
                fieldName = selectedField.getElementName();
            }
        }
    }
    if (proj != null) {
        iProject = proj;
    }
}

From source file:com.versant.core.jdo.tools.plugins.eclipse.VOAProjectControler.java

License:Open Source License

public String getClassName(ISelection iSelection) {
    if (iSelection instanceof StructuredSelection) {
        StructuredSelection sS = (StructuredSelection) iSelection;
        Object el = sS.getFirstElement();
        if (el instanceof IJavaElement) {
            IJavaElement javaElement = ((IJavaElement) el);
            IType type = (IType) javaElement.getAncestor(IJavaElement.TYPE);
            if (type != null) {
                return type.getFullyQualifiedName();
            }//from  w  w w .  j a  v a 2s. co m
        }
    }
    return null;
}

From source file:com.versant.core.jdo.tools.plugins.eclipse.VOAProjectControler.java

License:Open Source License

public String getFieldName(ISelection iSelection) {
    if (iSelection instanceof StructuredSelection) {
        StructuredSelection sS = (StructuredSelection) iSelection;
        Object el = sS.getFirstElement();
        if (el instanceof IJavaElement) {
            IJavaElement javaElement = ((IJavaElement) el);
            IType type = (IType) javaElement.getAncestor(IJavaElement.FIELD);
            if (type != null) {
                return type.getFullyQualifiedName();
            }/*from  w w w .  j a  v a  2  s  . c  om*/
        }
    }
    return null;
}

From source file:de.devboost.eclipse.junitloop.UpdateTestSuiteJob.java

License:Open Source License

private void addElementIfTest(ITestCollector testCollector, IJavaElement javaElement)
        throws JavaModelException {
    if (javaElement == null) {
        return;/*from w ww  .j  a  va 2s .c  o m*/
    }
    IJavaElement compilationUnit = javaElement.getAncestor(IJavaElement.COMPILATION_UNIT);
    if (compilationUnit == null) {
        return;
    }
    if (compilationUnit instanceof ICompilationUnit) {
        ICompilationUnit iCompilationUnit = (ICompilationUnit) compilationUnit;
        IType[] types = iCompilationUnit.getTypes();
        for (IType type : types) {
            if (new TestCaseChecker().isTestCase(type)) {
                IResource correspondingResource = type.getResource();
                if (correspondingResource != null) {
                    IProject correspondingProject = correspondingResource.getProject();
                    if (correspondingProject != null) {
                        String projectName = correspondingProject.getName();
                        String qualifiedClassName = type.getFullyQualifiedName();
                        // found a test
                        TestClass testClass = new TestClass(projectName, qualifiedClassName);
                        testCollector.addTestClass(testClass);
                    }
                }
            }
        }
    }
}

From source file:de.loskutov.bco.ui.actions.BytecodeAction.java

License:Open Source License

protected TypedElement createTypedElement(IJavaElement javaElement, BitSet modes) {
    String name;/*  w w  w  .j a  va2s. co  m*/
    IClassFile classFile = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE);
    // existing read-only class files
    if (classFile != null) {
        name = classFile.getPath().toOSString();
        if (!name.endsWith(".class")) { //$NON-NLS-1$
            name += '/' + JdtUtils.getFullBytecodeName(classFile);
        }
    } else {
        // usual eclipse - generated bytecode
        name = JdtUtils.getByteCodePath(javaElement);
    }
    String methodName = null;
    if (javaElement.getElementType() == IJavaElement.METHOD
            || javaElement.getElementType() == IJavaElement.INITIALIZER) {
        methodName = JdtUtils.getMethodSignature(javaElement);
        if (methodName != null) {
            name += ":" + methodName;
        }
    }
    return new TypedElement(name, methodName, TypedElement.TYPE_BYTECODE, javaElement, modes);
}

From source file:de.loskutov.bco.ui.EclipseUtils.java

License:Open Source License

/**
 * @param resource/*  w w  w  . ja v a2s. com*/
 * @return full package name in default java notation (with dots)
 */
public static String getJavaPackageName(IJavaElement resource) {
    String name;
    if (resource == null) {
        return "";
    }
    name = resource.getElementName();
    if (name == null) {
        return "";
    }
    int type = resource.getElementType();
    if (type == IJavaElement.PACKAGE_FRAGMENT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
        return name;
    }
    IJavaElement ancestor = resource.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
    if (ancestor != null) {
        return ancestor.getElementName();
    }
    return ""; //$NON-NLS-1$
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param childEl may be null/*from  w w  w. j a  v  a 2  s  . co m*/
 * @return first ancestor with IJavaElement.TYPE element type, or null
 */
public static IType getEnclosingType(IJavaElement childEl) {
    if (childEl == null) {
        return null;
    }
    return (IType) childEl.getAncestor(IJavaElement.TYPE);
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param javaElement/*from  ww  w . ja  v  a2 s. c  o m*/
 * @return null, if javaElement is top level class
 */
private static IType getFirstAncestor(IJavaElement javaElement) {
    IJavaElement parent = javaElement;
    if (javaElement.getElementType() == IJavaElement.TYPE) {
        parent = javaElement.getParent();
    }
    if (parent != null) {
        return (IType) parent.getAncestor(IJavaElement.TYPE);
    }
    return null;
}