List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessingState.java
License:Open Source License
public synchronized HashSet getOldJavaProjecNames() { if (this.javaProjectNamesCache == null) { HashSet result = new HashSet(); IJavaProject[] projects;/*from w ww. j a va2 s .c o m*/ try { projects = manager.getJavaModel().getJavaProjects(); } catch (JavaModelException e) { return this.javaProjectNamesCache; } for (int i = 0, length = projects.length; i < length; i++) { IJavaProject project = projects[i]; result.add(project.getElementName()); } return this.javaProjectNamesCache = result; } return this.javaProjectNamesCache; }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaModelStatus.java
License:Open Source License
/** * Returns the message that is relevant to the code of this status. */// w ww. ja va 2 s. c o m public String getMessage() { Throwable exception = getException(); if (exception == null) { switch (getCode()) { case CORE_EXCEPTION: return Messages.status_coreException; case BUILDER_INITIALIZATION_ERROR: return Messages.build_initializationError; case BUILDER_SERIALIZATION_ERROR: return Messages.build_serializationError; case DEVICE_PATH: return Messages.bind(Messages.status_cannotUseDeviceOnPath, getPath().toString()); case DOM_EXCEPTION: return Messages.status_JDOMError; case ELEMENT_DOES_NOT_EXIST: return Messages.bind(Messages.element_doesNotExist, ((JavaElement) this.elements[0]).toStringWithAncestors()); case ELEMENT_NOT_ON_CLASSPATH: return Messages.bind(Messages.element_notOnClasspath, ((JavaElement) this.elements[0]).toStringWithAncestors()); case EVALUATION_ERROR: return Messages.bind(Messages.status_evaluationError, this.string); case INDEX_OUT_OF_BOUNDS: return Messages.status_indexOutOfBounds; case INVALID_CONTENTS: return Messages.status_invalidContents; case INVALID_DESTINATION: return Messages.bind(Messages.status_invalidDestination, ((JavaElement) this.elements[0]).toStringWithAncestors()); case INVALID_ELEMENT_TYPES: StringBuffer buff = new StringBuffer(Messages.operation_notSupported); for (int i = 0; i < this.elements.length; i++) { if (i > 0) { buff.append(", "); //$NON-NLS-1$ } buff.append(((JavaElement) this.elements[i]).toStringWithAncestors()); } return buff.toString(); case INVALID_NAME: return Messages.bind(Messages.status_invalidName, this.string); case INVALID_PACKAGE: return Messages.bind(Messages.status_invalidPackage, this.string); case INVALID_PATH: if (this.string != null) { return this.string; } else { return Messages.bind(Messages.status_invalidPath, new String[] { getPath() == null ? "null" : getPath().toString() } //$NON-NLS-1$ ); } case INVALID_PROJECT: return Messages.bind(Messages.status_invalidProject, this.string); case INVALID_RESOURCE: return Messages.bind(Messages.status_invalidResource, this.string); case INVALID_RESOURCE_TYPE: return Messages.bind(Messages.status_invalidResourceType, this.string); case INVALID_SIBLING: if (this.string != null) { return Messages.bind(Messages.status_invalidSibling, this.string); } else { return Messages.bind(Messages.status_invalidSibling, ((JavaElement) this.elements[0]).toStringWithAncestors()); } case IO_EXCEPTION: return Messages.status_IOException; case NAME_COLLISION: if (this.elements != null && this.elements.length > 0) { IJavaElement element = this.elements[0]; if (element instanceof org.eclipse.jdt.internal.core.PackageFragment && ((PackageFragment) element).isDefaultPackage()) { return Messages.operation_cannotRenameDefaultPackage; } } if (this.string != null) { return this.string; } else { return Messages.bind(Messages.status_nameCollision, ""); //$NON-NLS-1$ } case NO_ELEMENTS_TO_PROCESS: return Messages.operation_needElements; case NULL_NAME: return Messages.operation_needName; case NULL_PATH: return Messages.operation_needPath; case NULL_STRING: return Messages.operation_needString; case PATH_OUTSIDE_PROJECT: return Messages.bind(Messages.operation_pathOutsideProject, new String[] { this.string, ((JavaElement) this.elements[0]).toStringWithAncestors() }); case READ_ONLY: IJavaElement element = this.elements[0]; String name = element.getElementName(); if (element instanceof IPackageFragment && name.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) { return Messages.status_defaultPackageReadOnly; } return Messages.bind(Messages.status_readOnly, name); case RELATIVE_PATH: return Messages.bind(Messages.operation_needAbsolutePath, getPath().toString()); case TARGET_EXCEPTION: return Messages.status_targetException; case UPDATE_CONFLICT: return Messages.status_updateConflict; case NO_LOCAL_CONTENTS: return Messages.bind(Messages.status_noLocalContents, getPath().toString()); case CP_CONTAINER_PATH_UNBOUND: IJavaProject javaProject = (IJavaProject) this.elements[0]; ClasspathContainerInitializer initializer = JavaCore .getClasspathContainerInitializer(this.path.segment(0)); String description = null; if (initializer != null) description = initializer.getDescription(this.path, javaProject); if (description == null) description = this.path.makeRelative().toString(); return Messages.bind(Messages.classpath_unboundContainerPath, new String[] { description, javaProject.getElementName() }); case INVALID_CP_CONTAINER_ENTRY: javaProject = (IJavaProject) this.elements[0]; IClasspathContainer container = null; description = null; try { container = JavaCore.getClasspathContainer(this.path, javaProject); } catch (JavaModelException e) { // project doesn't exist: ignore } if (container == null) { initializer = JavaCore.getClasspathContainerInitializer(this.path.segment(0)); if (initializer != null) description = initializer.getDescription(this.path, javaProject); } else { description = container.getDescription(); } if (description == null) description = this.path.makeRelative().toString(); return Messages.bind(Messages.classpath_invalidContainer, new String[] { description, javaProject.getElementName() }); case CP_VARIABLE_PATH_UNBOUND: javaProject = (IJavaProject) this.elements[0]; return Messages.bind(Messages.classpath_unboundVariablePath, new String[] { this.path.makeRelative().toString(), javaProject.getElementName() }); case CLASSPATH_CYCLE: javaProject = (IJavaProject) this.elements[0]; return Messages.bind(Messages.classpath_cycle, new String[] { javaProject.getElementName(), this.string }); case DISABLED_CP_EXCLUSION_PATTERNS: javaProject = (IJavaProject) this.elements[0]; String projectName = javaProject.getElementName(); IPath newPath = this.path; if (this.path.segment(0).toString().equals(projectName)) { newPath = this.path.removeFirstSegments(1); } return Messages.bind(Messages.classpath_disabledInclusionExclusionPatterns, new String[] { newPath.makeRelative().toString(), projectName }); case DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS: javaProject = (IJavaProject) this.elements[0]; projectName = javaProject.getElementName(); newPath = this.path; if (this.path.segment(0).toString().equals(projectName)) { newPath = this.path.removeFirstSegments(1); } return Messages.bind(Messages.classpath_disabledMultipleOutputLocations, new String[] { newPath.makeRelative().toString(), projectName }); case CANNOT_RETRIEVE_ATTACHED_JAVADOC: if (this.elements != null && this.elements.length == 1) { if (this.string != null) { return Messages.bind(Messages.status_cannot_retrieve_attached_javadoc, ((JavaElement) this.elements[0]).toStringWithAncestors(), this.string); } return Messages.bind(Messages.status_cannot_retrieve_attached_javadoc, ((JavaElement) this.elements[0]).toStringWithAncestors(), ""); //$NON-NLS-1$ } if (this.string != null) { return Messages.bind(Messages.status_cannot_retrieve_attached_javadoc, this.string, "");//$NON-NLS-1$ } break; case CANNOT_RETRIEVE_ATTACHED_JAVADOC_TIMEOUT: if (this.elements != null && this.elements.length == 1) { if (this.string != null) { return Messages.bind(Messages.status_timeout_javadoc, ((JavaElement) this.elements[0]).toStringWithAncestors(), this.string); } return Messages.bind(Messages.status_timeout_javadoc, ((JavaElement) this.elements[0]).toStringWithAncestors(), ""); //$NON-NLS-1$ } if (this.string != null) { return Messages.bind(Messages.status_timeout_javadoc, this.string, "");//$NON-NLS-1$ } break; case UNKNOWN_JAVADOC_FORMAT: return Messages.bind(Messages.status_unknown_javadoc_format, ((JavaElement) this.elements[0]).toStringWithAncestors()); case DEPRECATED_VARIABLE: javaProject = (IJavaProject) this.elements[0]; return Messages.bind(Messages.classpath_deprecated_variable, new String[] { this.path.segment(0).toString(), javaProject.getElementName(), this.string }); } if (this.string != null) { return this.string; } else { return ""; //$NON-NLS-1$ } } else { String message = exception.getMessage(); if (message != null) { return message; } else { return exception.toString(); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
private IType findSecondaryType(String packageName, String typeName, IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor) { // JavaModelManager manager = JavaModelManager.getJavaModelManager(); try {/*from w ww . j a va 2s.c o m*/ IJavaProject javaProject = project; Map secondaryTypePaths = manager.secondaryTypes(javaProject, waitForIndexes, monitor); if (secondaryTypePaths.size() > 0) { Map types = (Map) secondaryTypePaths.get(packageName == null ? "" : packageName); //$NON-NLS-1$ if (types != null && types.size() > 0) { IType type = (IType) types.get(typeName); if (type != null) { if (JavaModelManager.VERBOSE) { Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$ Util.verbose(" -> pkg name: " + packageName); //$NON-NLS-1$ Util.verbose(" -> type name: " + typeName); //$NON-NLS-1$ Util.verbose(" -> project: " + project.getElementName()); //$NON-NLS-1$ Util.verbose(" -> type: " + type.getElementName()); //$NON-NLS-1$ } return type; } } } } catch (JavaModelException jme) { // give up } return null; }
From source file:com.feup.contribution.druid.DruidPlugin.java
License:Open Source License
public DruidProject getProject(IJavaProject iProject) { if (projects.containsKey(iProject.getElementName())) return projects.get(iProject.getElementName()); DruidProject project = new DruidProject(iProject); projects.put(iProject.getElementName(), project); for (ProjectListener listener : listeners) { project.addProjectListener(listener); }//from ww w. j a v a 2 s . c om return project; }
From source file:com.flamefire.importsmalinames.handlers.RenameVariablesHandler.java
License:Open Source License
private void doRename(Shell shell, ICompilationUnit cu) { IJavaProject proj = getProject(cu); String cClassName = null;//from ww w . j a va 2 s .c om String pName = null; try { cClassName = cu.getCorrespondingResource().getName(); if (proj != null) pName = proj.getElementName(); } catch (JavaModelException e) { e.printStackTrace(); } if (cClassName == null || pName == null || cClassName.length() == 0 || pName.length() == 0) { MessageDialog.openError(shell, "Error", "Could not access project and class names"); return; } boolean classOnly = MessageDialog.openQuestion(shell, "Apply smali names only to current class?", "Do you want to apply the names only to current java file (" + cClassName + ") ->YES\n" + "Or to the whole project (" + pName + ") -> NO"); String lastFolder = null; IResource res = null; try { res = proj.getCorrespondingResource(); lastFolder = com.flamefire.importsmalinames.utils.Util.getPersistentProperty(res, LASTFOLDER); } catch (JavaModelException e) { } JFileChooser j = new JFileChooser(); j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); j.setDialogTitle("Select smali directory"); if (lastFolder != null) j.setSelectedFile(new File(lastFolder)); if (j.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) return; com.flamefire.importsmalinames.utils.Util.setPersistentProperty(res, LASTFOLDER, j.getSelectedFile().getAbsolutePath()); File smaliFolder = j.getSelectedFile(); RefactoringController controller = new RefactoringController(); if (!controller.init(smaliFolder)) { MessageDialog.openError(shell, "Error", "Could not parse smali classes"); return; } if (classOnly) { if (!controller.renameVariablesInFile(cu)) { MessageDialog.openError(shell, "Error", "Initializing the changes failed. Please check output."); return; } } else { try { IPackageFragment[] packages = proj.getPackageFragments(); for (IPackageFragment mypackage : packages) { if (mypackage.getKind() != IPackageFragmentRoot.K_SOURCE) continue; for (ICompilationUnit unit : mypackage.getCompilationUnits()) { if (!controller.renameVariablesInFile(unit)) { if (!MessageDialog.openConfirm(shell, "Error in " + unit.getCorrespondingResource().getName(), "Initializing the changes to " + unit.getCorrespondingResource().getName() + " failed. Please check output.\n\nContinue?")) return; } } } } catch (JavaModelException e) { e.printStackTrace(); } } String msg = "This will apply the smali names to the "; if (classOnly) msg += "java file " + cClassName; else msg += "whole project " + pName; msg += "\n\nPlease note that you HAVE to check the changes without a preview and it is better to apply this to the decompiled source before you do any changes yourself."; msg += "\nThis might fail under certain circumstances e.g. with nested classes and certain name combinations."; msg += "\n\nProceed?"; if (!MessageDialog.openConfirm(shell, "Apply smali names", msg)) return; if (controller.applyRenamings(shell)) MessageDialog.openInformation(shell, "Success", "Names were changed. Please have a look at the output in the console for warnings and errors"); else MessageDialog.openInformation(shell, "Error", "There were erros changing the names. Some may have been changed. Please have a look at the output in the console for warnings and errors"); }
From source file:com.github.ajaxsys.jdtx.utils.JDTUtils.java
License:Open Source License
public static String getProjectName(IJavaProject javaProject) { if (javaProject == null) { throw new IllegalArgumentException("javaProject is null"); }/*from w w w . ja v a 2 s. c o m*/ return javaProject.getElementName(); }
From source file:com.google.appengine.eclipse.core.deploy.ui.DeployProjectDialog.java
License:Open Source License
private void addEventHandlers() { projectText.addModifyListener(listener); chooseProjectButton.addSelectionListener(new SelectionAdapter() { @Override/*from w ww.ja va 2 s. c o m*/ public void widgetSelected(SelectionEvent e) { IJavaProject selectedProject = chooseProject(); if (selectedProject != null) { projectText.setText(selectedProject.getElementName()); } } }); projectPropertiesLink.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { assert (project != null); PreferenceDialog page = PreferencesUtil.createPropertyDialogOn(DeployProjectDialog.this.getShell(), project, GaeProjectPropertyPage.ID, new String[] { GaeProjectPropertyPage.ID }, null); if (Window.OK == page.open()) { // Invalidate cached app id and version GaeProject gaeProject = GaeProject.create(project); assert (gaeProject != null); appId = gaeProject.getAppId(); appVersion = gaeProject.getAppVersion(); // Refresh to pick up settings changes fieldChanged(); } } }); moreInfoLink.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { BrowserUtilities .launchBrowserAndHandleExceptions("http://code.google.com/appengine/docs/java/backends"); } }); }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.ConfigureRPCServiceLayerWizardPage.java
License:Open Source License
private void initializeContainerText(Text targetText) { String text = ""; //$NON-NLS-1$ if (project != null && project.isAccessible()) { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { try { IPackageFragmentRoot srcPackage = JavaUtils.getSourcePackageFragmentRoot(javaProject); if (srcPackage != null) { text = javaProject.getElementName() + "/" + srcPackage.getElementName(); //$NON-NLS-1$ }//from w w w .j a v a 2s. c o m } catch (JavaModelException e) { AppEngineRPCPlugin.log(e); } } } targetText.setText(text); }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.ConfigureRPCServiceLayerWizardPage.java
License:Open Source License
private void initializeTypeText(Text typeText) { String text = ""; //$NON-NLS-1$ IJavaProject javaProject = getJavaProject(); if (javaProject != null) { text = RequestFactoryUtils.creatServiceNameProposal(javaProject.getElementName()); }/*w w w .j av a 2 s. c o m*/ typeText.setText(text); }
From source file:com.google.gdt.eclipse.core.ProcessUtilities.java
License:Open Source License
/** * Computes the fully qualified path to the java executable for the JRE/JDK used by this project. * * @param javaProject/* www . ja v a 2s.c o m*/ * @return the path to the JRE/JDK java (executable) used on this project * @throws CoreException */ public static String computeJavaExecutableFullyQualifiedPath(IJavaProject javaProject) throws CoreException { IVMInstall projectVMInstall = JavaRuntime.getVMInstall(javaProject); if (projectVMInstall == null) { throw new CoreException(new Status(Status.ERROR, CorePlugin.PLUGIN_ID, "Unable to locate the JVM for project " + javaProject.getElementName() + ". Please verify that you have a project-level JVM installed by inspecting your project's build path.")); } return getJavaExecutableForVMInstall(projectVMInstall); }