List of usage examples for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT
int COMPILATION_UNIT
To view the source code for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT.
Click Source Link
From source file:rabbit.tracking.internal.trackers.JavaTracker.java
License:Apache License
/** * Gets the actual element that we want before saving. One of the following * types is returned://from w ww. ja v a2s . com * * <ul> * <li>A type that is not anonymous.</li> * <li>A method that is not enclosed in an anonymous type.</li> * <li>An initializer.</li> * <li>A compilation unit.</li> * <li>A class file.</li> * <li>Null</li> * </ul> * * @param element The element to filter. * @return A filtered element, or null if not found. * @throws JavaModelException If this element does not exist or if an * exception occurs while accessing its corresponding resource. */ private IJavaElement filterElement(@Nullable IJavaElement element) throws JavaModelException { if (element == null) { return null; } switch (element.getElementType()) { case IJavaElement.TYPE: if (((IType) element).isAnonymous()) { return filterElement(element.getParent()); } return element; case IJavaElement.METHOD: if (((IType) element.getParent()).isAnonymous()) { return filterElement(element.getParent()); } return element; case IJavaElement.INITIALIZER: case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return element; default: return filterElement(element.getParent()); } }
From source file:scala.tools.eclipse.launching.JUnitPropertyTester.java
License:Open Source License
private boolean canLaunchAsJUnitTest(IJavaElement element) { try {/*from w w w .ja v a2 s .c o m*/ switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: return true; // can run, let test runner detect if there are tests case IJavaElement.PACKAGE_FRAGMENT: return ((IPackageFragment) element).hasChildren(); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: case IJavaElement.TYPE: case IJavaElement.METHOD: return isJUnitTest(element); default: return false; } } catch (JavaModelException e) { return false; } }