List of usage examples for org.eclipse.jdt.core IJavaElement getJavaProject
IJavaProject getJavaProject();
null
if this element is not contained in any Java project (for instance, the IJavaModel
is not contained in any Java project). From source file:com.google.gdt.eclipse.designer.wizards.ui.JUnitWizardPage.java
License:Open Source License
private void handleSelectClassUnderTest(IJavaElement element) { try {/*from w ww .j a v a 2s .co m*/ if (element == null || !element.exists() || element.getJavaProject() == null) { setErrorState(); } else { IJavaProject javaProject = element.getJavaProject(); if (Utils.isGWTProject(javaProject)) { IPackageFragmentRoot testSourceFragmentRoot = handleTestSourceFolder(javaProject); IPackageFragment elementPackage = handleTestPackage(element, testSourceFragmentRoot); // handle class under test IType classUnderTestType = (IType) element.getAncestor(IJavaElement.TYPE); if (classUnderTestType == null) { ICompilationUnit compilationUnit = (ICompilationUnit) element .getAncestor(IJavaElement.COMPILATION_UNIT); if (compilationUnit != null) { classUnderTestType = compilationUnit.findPrimaryType(); } } if (classUnderTestType == null) { setErrorState(); } else { m_classUnderTestField.setText(classUnderTestType.getFullyQualifiedName()); setTypeName(classUnderTestType.getElementName() + "Test", true); m_classUnderTestStatus = new Status(IStatus.OK, Activator.PLUGIN_ID, IStatus.OK, null, null); // ModuleDescription module = Utils.getSingleModule(elementPackage); if (module == null) { setErrorState( "GWT module for " + classUnderTestType.getFullyQualifiedName() + " not found."); } else { m_moduleId = module.getId(); } } } else { setErrorState(); } } } catch (Throwable e) { DesignerPlugin.log(e); setErrorState("InternalError: " + e.getMessage()); } finally { doStatusUpdate(); } }
From source file:com.google.gwt.eclipse.core.launch.GWTJUnitPropertyTester.java
License:Open Source License
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { IJavaElement element = AdapterUtilities.getAdapter(receiver, IJavaElement.class); if (element == null) { return false; }/*from w w w . j a v a 2 s . c o m*/ if (!GWTNature.isGWTProject(element.getJavaProject().getProject())) { // Not a GWT project return false; } if (PROPERTY_IS_GWT_TEST.equals(property)) { IType testType = null; if (element instanceof ICompilationUnit) { testType = (((ICompilationUnit) element)).findPrimaryType(); } else if (element instanceof IClassFile) { testType = (((IClassFile) element)).getType(); } else if (element instanceof IType) { testType = (IType) element; } else if (element instanceof IMember) { testType = ((IMember) element).getDeclaringType(); } return testType != null && isGWTTestCaseOrSuite(testType); } return false; }
From source file:com.google.gwt.eclipse.core.uibinder.model.UiBinderSubtypeToUiXmlIndex.java
License:Open Source License
private static void loadEntry(IMemento memento, UiBinderSubtypeToUiXmlIndex index) throws PersistenceException { String uiXmlPath = memento.getString(KEY_UI_XML_PATH); if (uiXmlPath == null) { throw new PersistenceException("Missing key " + KEY_UI_XML_PATH); }// w w w . j a v a2 s . c om String uiBinderSubtypeKey = memento.getString(KEY_UIBINDER_SUBTYPE); if (uiBinderSubtypeKey == null) { throw new PersistenceException("Missing key " + KEY_UIBINDER_SUBTYPE); } IJavaElement javaElement = JavaCore.create(uiBinderSubtypeKey); if (javaElement == null) { throw new PersistenceException("Could not create Java element with key " + uiBinderSubtypeKey); } if (!(javaElement instanceof IType)) { throw new PersistenceException("Expecting " + javaElement.getElementName() + " to be a type"); } if (!javaElement.getJavaProject().isOpen()) { return; } if (!JavaModelSearch.isValidElement(javaElement)) { throw new PersistenceException( ((IType) javaElement).getFullyQualifiedName() + " is not a valid Java type"); } // Add the subtype + ui.xml pair to the index index.setUiXmlPath((IType) javaElement, new Path(uiXmlPath)); }
From source file:com.google.inject.tools.ideplugin.eclipse.BindingsObjectAction.java
License:Apache License
/** * Eclipse callback to have us run the bindings engine. *///from w ww. java 2 s . c o m public void run(IAction action) { IStructuredSelection selection = (IStructuredSelection) part.getSite().getSelectionProvider() .getSelection(); IJavaElement element = (IJavaElement) selection.getFirstElement(); EclipseJavaElement javaElement = element == null ? null : new EclipseJavaElement(element); if (javaElement != null) { guicePlugin.getBindingsEngine(javaElement, new EclipseJavaProject(element.getJavaProject())); } else { guicePlugin.getMessenger().display(PluginTextValues.SELECTION_NO_BINDINGS); } }
From source file:com.google.inject.tools.ideplugin.eclipse.EclipseJavaElement.java
License:Apache License
/** * Create a JavaElement.//from w w w . j a v a 2s. c om * * @param element the IJavaElement to wrap around */ public EclipseJavaElement(IJavaElement element) { this.element = element; this.name = findName(); this.javaProject = new EclipseJavaProject(element.getJavaProject()); findClassNameAndType(element); }
From source file:com.google.inject.tools.ideplugin.eclipse.EclipseJavaElement.java
License:Apache License
private void findClassNameAndType(IJavaElement element) { try {/* www . jav a 2s . c o m*/ if (element instanceof IMethod) { className = getClassName(element, ((IMethod) element).getSignature()); type = Type.PARAMETER; isConcrete = findIsConcreteClass(((IMethod) element).getSignature()); } else if (element instanceof IField) { className = getClassName(element, ((IField) element).getTypeSignature()); type = Type.FIELD; isConcrete = findIsConcreteClass(((IField) element).getTypeSignature()); } else if (element instanceof ILocalVariable) { className = getClassName(element, ((ILocalVariable) element).getTypeSignature()); type = Type.FIELD; isConcrete = findIsConcreteClass(((ILocalVariable) element).getTypeSignature()); } else if (element instanceof IType) { type = Type.PARAMETER; if (((IType) element).isResolved()) { className = ((IType) element).getFullyQualifiedName(); isConcrete = findIsConcreteClass((IType) element); } else { IType resolvedType = TypeUtil.resolveType(element.getJavaProject(), Signature.createTypeSignature(((IType) element).getFullyQualifiedName(), false)); className = resolvedType.getFullyQualifiedName(); isConcrete = findIsConcreteClass(resolvedType); } } else if (element instanceof ITypeParameter) { IMember member = ((ITypeParameter) element).getDeclaringMember(); findClassNameAndType(member); } else { className = null; type = null; isConcrete = false; } } catch (Throwable e) { className = null; type = null; isConcrete = false; } }
From source file:com.ibm.wala.ide.AbstractJavaAnalysisAction.java
License:Open Source License
/** * Compute an analysis scope for the current selection * /* www .j a va 2 s . com*/ * @param scopeType should analysis use the source files in the Eclipse projects rather than the class files. */ public static AnalysisScope computeScope(final IStructuredSelection selection, final EclipseProjectPath.AnalysisScopeType scopeType) throws IOException { if (selection == null) { throw new IllegalArgumentException("null selection"); } final Collection<EclipseProjectPath> projectPaths = new LinkedList<EclipseProjectPath>(); Job job = new Job("Compute project paths") { @SuppressWarnings("unchecked") @Override protected IStatus run(IProgressMonitor monitor) { for (Iterator it = selection.iterator(); it.hasNext();) { Object object = it.next(); if (object instanceof IJavaElement) { IJavaElement e = (IJavaElement) object; IJavaProject jp = e.getJavaProject(); try { projectPaths.add(JavaEclipseProjectPath.make(jp, scopeType)); } catch (CoreException e1) { e1.printStackTrace(); // skip and continue } catch (IOException e2) { e2.printStackTrace(); return new Status(IStatus.ERROR, "", 0, "", e2); } } else { Assertions.UNREACHABLE(object.getClass()); } } return Status.OK_STATUS; } }; // lock the whole workspace job.setRule(ResourcesPlugin.getWorkspace().getRoot()); job.schedule(); try { job.join(); IStatus result = job.getResult(); if (result.getSeverity() == IStatus.ERROR) { Throwable exception = result.getException(); if (exception instanceof IOException) { throw (IOException) exception; } else if (exception instanceof RuntimeException) { throw (RuntimeException) exception; } } } catch (InterruptedException e) { e.printStackTrace(); assert false; } AnalysisScope scope = mergeProjectPaths(projectPaths); return scope; }
From source file:com.ibm.wala.ide.AbstractJavaAnalysisAction.java
License:Open Source License
/** * compute the java projects represented by the current selection *///w w w . j a v a2 s .c o m @SuppressWarnings("unchecked") protected Collection<IJavaProject> computeJavaProjects() { IStructuredSelection selection = (IStructuredSelection) currentSelection; Collection<IJavaProject> projects = HashSetFactory.make(); for (Iterator it = selection.iterator(); it.hasNext();) { Object object = it.next(); if (object instanceof IJavaElement) { IJavaElement e = (IJavaElement) object; IJavaProject jp = e.getJavaProject(); projects.add(jp); } else { Assertions.UNREACHABLE(object.getClass()); } } return projects; }
From source file:com.idega.eclipse.ejbwizards.BeanCreator.java
License:Open Source License
protected BeanCreator(IResource resource, boolean isLegacyOrSessionBean) { this.isLegacyEntity = isLegacyOrSessionBean; this.isSessionBean = isLegacyOrSessionBean; String resourceName = resource.getName(); IJavaElement javaElement = JavaCore.create(resource); if (javaElement instanceof ICompilationUnit) { String typeName = resourceName.substring(0, resourceName.indexOf(".java")); ICompilationUnit compilationUnit = (ICompilationUnit) javaElement; fillImportMap(compilationUnit);/*from ww w . ja v a 2s. com*/ this.type = compilationUnit.getType(typeName); } Map map = javaElement.getJavaProject().getOptions(false); if (map != null) { String value = (String) map.get("org.eclipse.jdt.core.compiler.compliance"); if (value != null) { float version = Float.parseFloat(value); if (version > 1.4) { this.isJDK1_5 = true; } } } try { generateCode(); } catch (JavaModelException jme) { jme.printStackTrace(System.err); } }
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
private void processDelta(final IJavaElementDelta delta, Set<IJavaProject> remove, Set<IJavaProject> add) throws CoreException { final IJavaElement element = delta.getElement(); final int kind = delta.getKind(); switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: processChangedChildren(delta, remove, add); break;//from w w w. ja v a 2 s . c o m case IJavaElement.JAVA_PROJECT: switch (kind) { case IJavaElementDelta.REMOVED: remove.add((IJavaProject) element); break; case IJavaElementDelta.ADDED: add.add((IJavaProject) element); break; case IJavaElementDelta.CHANGED: switch (delta.getFlags()) { case IJavaElementDelta.F_CLOSED: remove.add((IJavaProject) element); break; case IJavaElementDelta.F_OPENED: add.add((IJavaProject) element); break; } break; } processChangedChildren(delta, remove, add); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: remove.add(element.getJavaProject()); add.add(element.getJavaProject()); break; } }