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:cn.ieclipse.adt.ext.wizards.NewComponentWizardPage.java
License:Apache License
/** * The wizard owning this page is responsible for calling this method with * the current selection. The selection is used to initialize the fields of * the wizard page./*from ww w.ja v a 2 s . c o m*/ * * @param selection * used to initialize the fields */ public void init(IStructuredSelection selection) { IJavaElement jelem = getInitialJavaElement(selection); javaProject = jelem.getJavaProject(); initContainerPage(jelem); initTypePage(jelem); doStatusUpdate(); AndroidManifest manifest = ProjectHelper.getAndroidManifest(jelem); if (manifest != null) { } }
From source file:cn.ieclipse.aorm.eclipse.wizards.EditActivityWizardPage.java
License:Apache License
public void init(IStructuredSelection selection) { IJavaElement ele = ProjectHelper.getInitialJavaElement(selection); if (ele != null) { javaProject = ele.getJavaProject(); }// w w w .j a v a 2s . c o m helper = new IntentReflectionHelper(javaProject); }
From source file:cn.ieclipse.aorm.eclipse.wizards.EditComponentWizard.java
License:Apache License
public void init(IWorkbench workbench, IStructuredSelection selection) { this.selection = selection; IJavaElement jele = ProjectHelper.getInitialJavaElement((IStructuredSelection) selection); jProject = jele.getJavaProject(); if (jele instanceof ICompilationUnit) { ICompilationUnit unit = (ICompilationUnit) jele; Set<String> supers = ProjectHelper.getSuperTypeName(unit, false); if (supers.contains(AdtConstants.ACTIVITY_QNAME)) { nodeName = AdtConstants.ACTIVITY_NODE; } else if (supers.contains(AdtConstants.SERVICE_QNAME)) { nodeName = AdtConstants.SERVICE_NODE; } else if (supers.contains(AdtConstants.RECEIVER_QNAME)) { nodeName = AdtConstants.RECEIVER_NODE; } else if (supers.contains(AdtConstants.PROVIDER_QNAME)) { nodeName = AdtConstants.PROVIDER_NODE; }/*from ww w.j a v a 2 s. c om*/ try { compName = unit.getTypes()[0].getFullyQualifiedName(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } // int pos = compName.indexOf('.'); // compName = compName.substring(0, pos); System.out.println("node:" + nodeName + ",class:" + compName); } }
From source file:coloredide.astview.ASTView.java
License:Open Source License
protected void performCreateBindingFromElement() { InputDialog dialog = new InputDialog(getSite().getShell(), "Create Binding from Java Element", "IJavaElement#getHandleIdentifier():", "", null); if (dialog.open() != Window.OK) return;//from w w w . j a v a 2s. c o m String handleIdentifier = dialog.getValue(); IJavaElement handle = JavaCore.create(handleIdentifier); Object viewerInput = fViewer.getInput(); ASTAttribute item; if (handle == null) { item = new Error(viewerInput, "handleIdentifier not resolved: " + handleIdentifier, null); } else if (!handle.exists()) { item = new Error(viewerInput, "element does not exist: " + handleIdentifier, null); } else if (handle.getJavaProject() == null) { item = new Error(viewerInput, "getJavaProject() is null: " + handleIdentifier, null); } else { IJavaProject project = handle.getJavaProject(); ASTParser parser = ASTParser.newParser(ColoredIDEPlugin.AST_VERSION); parser.setProject(project); IBinding[] bindings = parser.createBindings(new IJavaElement[] { handle }, null); item = new Binding(viewerInput, handleIdentifier, bindings[0], true); } fViewer.add(viewerInput, item); fViewer.setSelection(new StructuredSelection(item), true); }
From source file:com.android.ide.eclipse.adt.internal.launch.junit.AndroidJUnitLaunchConfigurationTab.java
License:Open Source License
private void initializeJavaProject(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { IJavaProject javaProject = javaElement.getJavaProject(); String name = null;/*from w ww . j a v a2 s .c o m*/ if (javaProject != null && javaProject.exists()) { name = javaProject.getElementName(); } config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name); }
From source file:com.android.ide.eclipse.adt.internal.launch.junit.AndroidJUnitLaunchShortcut.java
License:Open Source License
/** * Creates a default Android JUnit launch configuration. Sets the instrumentation runner to the * first instrumentation found in the AndroidManifest. *//* w ww . j a va2s . c o m*/ @Override protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement element) throws CoreException { ILaunchConfigurationWorkingCopy config = super.createLaunchConfiguration(element); // just get first valid instrumentation runner String instrumentation = new InstrumentationRunnerValidator(element.getJavaProject()) .getValidInstrumentationTestRunner(); if (instrumentation != null) { config.setAttribute(AndroidJUnitLaunchConfigDelegate.ATTR_INSTR_NAME, instrumentation); } // if a valid runner is not found, rely on launch delegate to log error. // This method is called without explicit user action to launch Android JUnit, so avoid // logging an error here. AndroidJUnitLaunchConfigDelegate.setJUnitDefaults(config); return config; }
From source file:com.android.ide.eclipse.adt.internal.ui.ResourceExplorerView.java
License:Open Source License
/** * Processes a new selection.// w ww.j ava2 s. c o m */ @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { // first we test if the part is an editor. if (part instanceof IEditorPart) { // if it is, we check if it's a file editor. IEditorInput input = ((IEditorPart) part).getEditorInput(); if (input instanceof IFileEditorInput) { // from the file editor we can get the IFile object, and from it, the IProject. IFile file = ((IFileEditorInput) input).getFile(); // get the file project IProject project = file.getProject(); handleProjectSelection(project); } } else if (selection instanceof IStructuredSelection) { // if it's not an editor, we look for structured selection. for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it.hasNext();) { Object element = it.next(); IProject project = null; // if we are in the navigator or package explorer, the selection could contain a // IResource object. if (element instanceof IResource) { project = ((IResource) element).getProject(); } else if (element instanceof IJavaElement) { // if we are in the package explorer on a java element, we handle that too. IJavaElement javaElement = (IJavaElement) element; IJavaProject javaProject = javaElement.getJavaProject(); if (javaProject != null) { project = javaProject.getProject(); } } else if (element instanceof IAdaptable) { // finally we try to get a project object from IAdaptable. project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); } // if we found a project, handle it, and return. if (project != null) { if (handleProjectSelection(project)) { return; } } } } }
From source file:com.android.ide.eclipse.editors.resources.explorer.ResourceExplorerView.java
License:Open Source License
/** * Processes a new selection./* ww w.ja v a 2 s .c o m*/ */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { // first we test if the part is an editor. if (part instanceof IEditorPart) { // if it is, we check if it's a file editor. IEditorInput input = ((IEditorPart) part).getEditorInput(); if (input instanceof IFileEditorInput) { // from the file editor we can get the IFile object, and from it, the IProject. IFile file = ((IFileEditorInput) input).getFile(); // get the file project IProject project = file.getProject(); handleProjectSelection(project); } } else if (selection instanceof IStructuredSelection) { // if it's not an editor, we look for structured selection. for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it.hasNext();) { Object element = it.next(); IProject project = null; // if we are in the navigator or package explorer, the selection could contain a // IResource object. if (element instanceof IResource) { project = ((IResource) element).getProject(); } else if (element instanceof IJavaElement) { // if we are in the package explorer on a java element, we handle that too. IJavaElement javaElement = (IJavaElement) element; IJavaProject javaProject = javaElement.getJavaProject(); if (javaProject != null) { project = javaProject.getProject(); } } else if (element instanceof IAdaptable) { // finally we try to get a project object from IAdaptable. project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); } // if we found a project, handle it, and return. if (project != null) { if (handleProjectSelection(project)) { return; } } } } }
From source file:com.blackducksoftware.integration.eclipseplugin.internal.listeners.ProjectDependenciesChangedListener.java
License:Apache License
public String getProjectNameFromElement(final IJavaElement el) throws CoreException { final IJavaProject javaProj = el.getJavaProject(); if (javaProj != null) { final IProject proj = javaProj.getProject(); if (proj != null) { final IProjectDescription description = proj.getDescription(); if (description != null) { return description.getName(); }/* w w w . j av a2 s . c om*/ } } return null; }
From source file:com.centurylink.mdw.plugin.WizardPage.java
License:Apache License
/** * Override to prefer non-temp package root. *//*from w w w. j av a2 s . c o m*/ @SuppressWarnings("restriction") @Override protected void initContainerPage(IJavaElement elem) { IPackageFragmentRoot tempRoot = null; // only as fallback IPackageFragmentRoot initRoot = null; if (elem != null) { initRoot = org.eclipse.jdt.internal.corext.util.JavaModelUtil.getPackageFragmentRoot(elem); try { if (initRoot == null || initRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { IJavaProject jproject = elem.getJavaProject(); if (jproject != null) { initRoot = null; if (jproject.exists()) { IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { if (roots[i].getElementName() .equals(MdwPlugin.getSettings().getTempResourceLocation())) { tempRoot = roots[i]; } else { initRoot = roots[i]; break; } } } } if (initRoot == null && tempRoot == null) { initRoot = jproject.getPackageFragmentRoot(jproject.getResource()); } } } } catch (JavaModelException e) { org.eclipse.jdt.internal.ui.JavaPlugin.log(e); } } setPackageFragmentRoot(initRoot == null ? tempRoot : initRoot, true); }