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:com.windowtester.eclipse.ui.convert.WTAPIUsage.java
License:Open Source License
/** * Recursively iterate over the specified java element and their children to convert * each compilation to use the new WindowTester API. * //from www . j av a2s.c om * @param elem the java element (not <code>null</code>) * @param monitor the progress monitor (not <code>null</code>) */ private void scanElement(IJavaElement elem, IProgressMonitor monitor) throws JavaModelException { projects.add(elem.getJavaProject()); switch (elem.getElementType()) { case IJavaElement.JAVA_PROJECT: scanProject((IJavaProject) elem, monitor); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: scanPackageRoot((IPackageFragmentRoot) elem, monitor); break; case IJavaElement.PACKAGE_FRAGMENT: scanPackage((IPackageFragment) elem, monitor); break; case IJavaElement.COMPILATION_UNIT: scanCompilationUnit((ICompilationUnit) elem); break; default: break; } }
From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIRefactoring.java
License:Open Source License
/** * Recursively iterate over the specified java element and their children to convert * each compilation to use the new WindowTester API. * /*from ww w . jav a2s . c om*/ * @param elem the java element (not <code>null</code>) * @param monitor the progress monitor (not <code>null</code>) */ private void convertElement(IJavaElement elem, IProgressMonitor monitor) throws JavaModelException { switch (elem.getElementType()) { case IJavaElement.JAVA_PROJECT: convertProject((IJavaProject) elem, monitor); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: convertPackageRoot((IPackageFragmentRoot) elem, monitor); break; case IJavaElement.PACKAGE_FRAGMENT: convertPackage((IPackageFragment) elem, monitor); break; case IJavaElement.COMPILATION_UNIT: convertCompilationUnit((ICompilationUnit) elem, monitor); break; default: break; } }
From source file:com.windowtester.eclipse.ui_tool.WTConvertAPIContextBuilderTool.java
License:Open Source License
/** * Recursively iterate over the specified java element and their children looking for * WindowTester classes and members./* w w w. ja va 2 s .co m*/ * * @param elem the java element (not <code>null</code>) */ private void scanElement(IJavaElement elem) throws JavaModelException { switch (elem.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: scanPackage((IPackageFragment) elem); break; case IJavaElement.COMPILATION_UNIT: scanCompilationUnit((ICompilationUnit) elem); break; default: break; } }
From source file:costabs.utils.SourceUtils.java
License:Open Source License
private static void fileEvaluations(IJavaElement javaFile) throws CostabsException { try {/*from w w w . j av a2s . co m*/ if (javaFile.getElementType() != IJavaElement.COMPILATION_UNIT) { throw new CostabsException("The file must be a Java file"); } ICompilationUnit javaFileComp = (ICompilationUnit) javaFile; if (!javaFile.isStructureKnown()) { throw new CostabsException("The file cannot have errors to analyze it"); } if (!javaFile.getElementName().endsWith(".java")) { throw new CostabsException("The file is not a Java File"); } if (!javaFileComp.isConsistent()) { throw new CostabsException("The file is not consistent, cannot proccess it"); } } catch (JavaModelException e) { throw new CostabsException("Cannot evaluate the file, it may be incorrect"); } }
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;// ww w . java2s .co 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.enough.mepose.core.model.MiDletChangeListener.java
License:Open Source License
protected MidletItem generateMiDLetFromResource(IResource resource) { IJavaElement javaElement = JavaCore.create(resource); if (javaElement == null) { return null; }//from w ww .j ava 2 s.c o m if (javaElement.getElementType() != IJavaElement.COMPILATION_UNIT) { return null; } ICompilationUnit compilationUnit = (ICompilationUnit) javaElement; IType primaryType = compilationUnit.findPrimaryType(); if (primaryType == null) { return null; } int flags; try { flags = primaryType.getFlags(); } catch (JavaModelException exception) { MeposePlugin.log(exception); return null; } if (Flags.isAbstract(flags)) { return null; } ITypeHierarchy supertypeHierarchy; try { supertypeHierarchy = primaryType.newSupertypeHierarchy(new NullProgressMonitor()); } catch (JavaModelException exception) { return null; } IType[] allSuperclasses = supertypeHierarchy.getAllSuperclasses(primaryType); for (int i = 0; i < allSuperclasses.length; i++) { if ("MIDlet".equals(allSuperclasses[i].getElementName())) { MidletItem midletItem = new MidletItem(); midletItem.setResource(resource); midletItem.setClassName(primaryType.getFullyQualifiedName()); midletItem.setName(primaryType.getElementName()); return midletItem; } } return null; }
From source file:de.fu_berlin.inf.jtourbus.view.TourChangeListener.java
License:Open Source License
void visitInternal(IProgressMonitor pm, IJavaElementDelta delta) { IJavaElement elem = delta.getElement(); IJavaElementDelta[] children = delta.getAffectedChildren(); if (pm != null) pm.beginTask("", children.length + 2); if ((delta.getFlags() & IJavaElementDelta.F_CHILDREN) != 0) { if (delta.getKind() != IJavaElementDelta.CHANGED) { throw new RuntimeException("ASSERT: CHILDREN should always be CHANGE"); }/*from w w w.j av a 2s . co m*/ for (int i = 0; i < children.length; i++) { visit(pm, children[i]); } return; } switch (delta.getKind()) { case IJavaElementDelta.ADDED: { if (!((delta.getFlags() & IJavaElementDelta.F_CHILDREN) == 0)) throw new RuntimeException("ASSERT: ADDED has no children"); switch (elem.getElementType()) { case IJavaElement.JAVA_MODEL: throw new RuntimeException("ASSERT: Adding Java Model not possible"); case IJavaElement.JAVA_PROJECT: throw new RuntimeException("ASSERT: Adding Java Project not possible"); case IJavaElement.PACKAGE_FRAGMENT_ROOT: // The user added a source folder for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getResource())) fContentProvider.fTourPlan.add(bs); return; case IJavaElement.PACKAGE_FRAGMENT: // The user inserted a packaged for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getResource())) fContentProvider.fTourPlan.add(bs); return; case IJavaElement.COMPILATION_UNIT: { ICompilationUnit cu = (ICompilationUnit) elem; if (cu.getPrimary().equals(cu)) { for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getResource())) fContentProvider.fTourPlan.add(bs); } return; } default: ICompilationUnit cu = (ICompilationUnit) delta.getElement() .getAncestor(IJavaElement.COMPILATION_UNIT); redoCU(cu, pm); return; } } case IJavaElementDelta.REMOVED: if (!((delta.getFlags() & IJavaElementDelta.F_CHILDREN) == 0)) throw new RuntimeException("REMOVED has children"); switch (elem.getElementType()) { case IJavaElement.JAVA_MODEL: throw new RuntimeException("ASSERT: Java Model not possible"); case IJavaElement.JAVA_PROJECT: fContentProvider.fTourPlan.removeAll(); return; case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: fContentProvider.fTourPlan.removeAll(); for (BusStop bs : Utilities.findJTourBusStops(pm, elem.getJavaProject().getResource())) fContentProvider.fTourPlan.add(bs); return; case IJavaElement.COMPILATION_UNIT: { ICompilationUnit cu = (ICompilationUnit) elem; if (cu.getPrimary().equals(cu)) { fContentProvider.fTourPlan.removeCU(cu); } return; } default: { ICompilationUnit cu = (ICompilationUnit) delta.getElement() .getAncestor(IJavaElement.COMPILATION_UNIT); redoCU(cu, pm); return; } } case IJavaElementDelta.CHANGED: // F_CONTENT && F_FINE_GRAINED if ((delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0 && (delta.getFlags() & IJavaElementDelta.F_FINE_GRAINED) != 0) { ICompilationUnit cu = (ICompilationUnit) delta.getElement() .getAncestor(IJavaElement.COMPILATION_UNIT); redoCU(cu, pm); } // Closing without saving will trigger this event. We thus re-read // the file. if ((delta.getFlags() & IJavaElementDelta.F_PRIMARY_WORKING_COPY) != 0) { ICompilationUnit cu = (ICompilationUnit) delta.getElement(); /* FIXME */ redoCU(cu, pm); } break; } }
From source file:de.loskutov.bco.ui.JdtUtils.java
License:Open Source License
/** * Check if java element is an interface or abstract method or a method from * interface./*from w ww . j a va 2s . co m*/ */ public static boolean isAbstractOrInterface(IJavaElement javaEl) { if (javaEl == null) { return true; } boolean abstractOrInterface = false; try { switch (javaEl.getElementType()) { case IJavaElement.CLASS_FILE: IClassFile classFile = (IClassFile) javaEl; if (isOnClasspath(javaEl)) { abstractOrInterface = classFile.isInterface(); } /*else { this is the case for eclipse-generated class files. if we do not perform the check in if, then we will have java model exception on classFile.isInterface() call. }*/ break; case IJavaElement.COMPILATION_UNIT: ICompilationUnit cUnit = (ICompilationUnit) javaEl; IType type = cUnit.findPrimaryType(); abstractOrInterface = type != null && type.isInterface(); break; case IJavaElement.TYPE: abstractOrInterface = ((IType) javaEl).isInterface(); break; case IJavaElement.METHOD: // test for "abstract" flag on method in a class abstractOrInterface = Flags.isAbstract(((IMethod) javaEl).getFlags()); // "abstract" flags could be not exist on interface methods if (!abstractOrInterface) { IType ancestor = (IType) javaEl.getAncestor(IJavaElement.TYPE); abstractOrInterface = ancestor != null && ancestor.isInterface(); } break; default: IType ancestor1 = (IType) javaEl.getAncestor(IJavaElement.TYPE); abstractOrInterface = ancestor1 != null && ancestor1.isInterface(); break; } } catch (JavaModelException e) { // No point to log it here // BytecodeOutlinePlugin.log(e, IStatus.ERROR); } return abstractOrInterface; }
From source file:de.tobject.findbugs.builder.WorkItem.java
License:Open Source License
public @CheckForNull IResource getCorespondingResource() { if (resource != null) { return resource; }/*from w w w . ja v a2 s. c om*/ try { IResource resource1 = javaElt.getCorrespondingResource(); if (resource1 != null) { return resource1; } IJavaElement ancestor = javaElt.getAncestor(IJavaElement.COMPILATION_UNIT); if (ancestor != null) { return ancestor.getCorrespondingResource(); } } catch (JavaModelException e) { // ignore, just return nothing } return null; }
From source file:dynamicrefactoring.integration.selectionhandler.TreeClassSelectionHandler.java
License:Open Source License
/** * @see ClassSelectionHandler#getMainObject() *//*from w w w.j a va2 s. c o m*/ @Override public ObjectMoon getMainObject() throws ClassNotFoundException, IOException { if (classDef == null) { TreePath path = classSelection.getPaths()[0].getParentPath(); if (path.getLastSegment() instanceof IJavaElement) { IJavaElement element = (IJavaElement) path.getLastSegment(); if (element.getElementType() == IJavaElement.COMPILATION_UNIT) { ICompilationUnit unit = (ICompilationUnit) element; JavaElementProcessor elementProcessor = new JavaClassProcessor((IType) unit.findPrimaryType()); classDef = ModelGenerator.getInstance().getModel() .getClassDef(new JavaName(elementProcessor.getUniqueName())); } } } return classDef; }