List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
private void verbose_triggering_container_initialization(IJavaProject project, IPath containerPath, ClasspathContainerInitializer initializer) { Util.verbose("CPContainer INIT - triggering initialization\n" + //$NON-NLS-1$ " project: " + project.getElementName() + '\n' + //$NON-NLS-1$ " container path: " + containerPath + '\n' + //$NON-NLS-1$ " initializer: " + initializer); //$NON-NLS-1$ }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
private static void recreatePersistedContainer(final IJavaProject project, final IPath containerPath, String containerString, boolean addToContainerValues) { if (!project.getProject().isAccessible()) return; // avoid leaking deleted project's persisted container if (containerString == null) { getJavaModelManager().containerPut(project, containerPath, null); } else {/*from w w w . ja va 2 s . co m*/ IClasspathEntry[] entries; try { entries = ((JavaProject) project).decodeClasspath(containerString, null/*not interested in unknown elements*/)[0]; } catch (IOException e) { Util.log(e, "Could not recreate persisted container: \n" + containerString); //$NON-NLS-1$ entries = JavaProject.INVALID_CLASSPATH; } if (entries != JavaProject.INVALID_CLASSPATH) { final IClasspathEntry[] containerEntries = entries; IClasspathContainer container = new IClasspathContainer() { public IClasspathEntry[] getClasspathEntries() { return containerEntries; } public String getDescription() { return "Persisted container [" + containerPath + " for project [" + project.getElementName() //$NON-NLS-1$//$NON-NLS-2$ + "]"; //$NON-NLS-1$ } public int getKind() { return 0; } public IPath getPath() { return containerPath; } public String toString() { return getDescription(); } }; if (addToContainerValues) { getJavaModelManager().containerPut(project, containerPath, container); } Map projectContainers = (Map) getJavaModelManager().previousSessionContainers.get(project); if (projectContainers == null) { projectContainers = new HashMap(1); getJavaModelManager().previousSessionContainers.put(project, projectContainers); } projectContainers.put(containerPath, container); } } }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
/** * Get all secondary types for a project and store result in per project info cache. * * This cache is an Hashtable<String, HashMap<String, IType>>: * - key: package name//from w ww . j av a2 s. co m * - value: * + key: type name * + value: java model handle for the secondary type * Hashtable was used to protect callers from possible concurrent access. * * Note that this map may have a specific entry which key is {@link #INDEXED_SECONDARY_TYPES } * and value is a map containing all secondary types created during indexing. * When this key is in cache and indexing is finished, returned map is merged * with the value of this special key. If indexing is not finished and caller does * not wait for the end of indexing, returned map is the current secondary * types cache content which may be invalid... * * @param project Project we want get secondary types from * @return HashMap Table of secondary type names->path for given project */ public Map secondaryTypes(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor) throws JavaModelException { if (VERBOSE) { StringBuffer buffer = new StringBuffer("JavaModelManager.secondaryTypes("); //$NON-NLS-1$ buffer.append(project.getElementName()); buffer.append(','); buffer.append(waitForIndexes); buffer.append(')'); Util.verbose(buffer.toString()); } // Return cache if not empty and there's no new secondary types created during indexing final PerProjectInfo projectInfo = getPerProjectInfoCheckExistence(project.getProject()); Map indexingSecondaryCache = projectInfo.secondaryTypes == null ? null : (Map) projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES); if (projectInfo.secondaryTypes != null && indexingSecondaryCache == null) { return projectInfo.secondaryTypes; } // Perform search request only if secondary types cache is not initialized yet (this will happen only once!) if (projectInfo.secondaryTypes == null) { return secondaryTypesSearching(project, waitForIndexes, monitor, projectInfo); } // New secondary types have been created while indexing secondary types cache // => need to know whether the indexing is finished or not boolean indexing = this.indexManager.awaitingJobsCount() > 0; if (indexing) { if (!waitForIndexes) { // Indexing is running but caller cannot wait => return current cache return projectInfo.secondaryTypes; } // Wait for the end of indexing or a cancel while (this.indexManager.awaitingJobsCount() > 0) { if (monitor != null && monitor.isCanceled()) { return projectInfo.secondaryTypes; } try { Thread.sleep(10); } catch (InterruptedException e) { return projectInfo.secondaryTypes; } } } // Indexing is finished => merge caches and return result return secondaryTypesMerging(projectInfo.secondaryTypes); }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
private Map secondaryTypesSearching(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor, final PerProjectInfo projectInfo) throws JavaModelException { if (VERBOSE || BasicSearchEngine.VERBOSE) { StringBuffer buffer = new StringBuffer("JavaModelManager.secondaryTypesSearch("); //$NON-NLS-1$ buffer.append(project.getElementName()); buffer.append(','); buffer.append(waitForIndexes);//www . ja v a2s.c o m buffer.append(')'); Util.verbose(buffer.toString()); } final Hashtable secondaryTypes = new Hashtable(3); IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { String key = packageName == null ? "" : new String(packageName); //$NON-NLS-1$ HashMap types = (HashMap) secondaryTypes.get(key); if (types == null) types = new HashMap(3); types.put(new String(simpleTypeName), path); secondaryTypes.put(key, types); } }; // Build scope using prereq projects but only source folders IPackageFragmentRoot[] allRoots = project.getAllPackageFragmentRoots(); int length = allRoots.length, size = 0; IPackageFragmentRoot[] allSourceFolders = new IPackageFragmentRoot[length]; for (int i = 0; i < length; i++) { if (allRoots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { allSourceFolders[size++] = allRoots[i]; } } if (size < length) { System.arraycopy(allSourceFolders, 0, allSourceFolders = new IPackageFragmentRoot[size], 0, size); } // Search all secondary types on scope new BasicSearchEngine().searchAllSecondaryTypeNames(allSourceFolders, nameRequestor, waitForIndexes, monitor); // Build types from paths Iterator packages = secondaryTypes.values().iterator(); while (packages.hasNext()) { HashMap types = (HashMap) packages.next(); Iterator names = types.entrySet().iterator(); while (names.hasNext()) { Map.Entry entry = (Map.Entry) names.next(); String typeName = (String) entry.getKey(); String path = (String) entry.getValue(); if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path)) { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null); IType type = unit.getType(typeName); types.put(typeName, type); // replace stored path with type itself } else { names.remove(); } } } // Store result in per project info cache if still null or there's still an indexing cache (may have been set by another thread...) if (projectInfo.secondaryTypes == null || projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES) != null) { projectInfo.secondaryTypes = secondaryTypes; if (VERBOSE || BasicSearchEngine.VERBOSE) { System.out.print(Thread.currentThread() + " -> secondary paths stored in cache: "); //$NON-NLS-1$ System.out.println(); Iterator entries = secondaryTypes.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); String qualifiedName = (String) entry.getKey(); Util.verbose(" - " + qualifiedName + '-' + entry.getValue()); //$NON-NLS-1$ } } } return projectInfo.secondaryTypes; }
From source file:org.eclipse.jem.internal.proxy.ide.IDERegistration.java
License:Open Source License
/** * This will create a remote VM and return an initialized REMProxyFactoryRegistry. * Passed in are://from w w w .j a va 2 s.c o m * project: The project this is being started on. Must not be null and must be a JavaProject. (Currently ignored for IDE). * attachAWT: Should AWT be attached to this implementation. * contributors: Contributors to the configuration. Can be null. * pm: ProgressMonitor to use. Must not be null. * vmName: Name for the vm. Can be null. */ public ProxyFactoryRegistry startImplementation(IConfigurationContributor[] contributors, boolean attachAWT, IProject project, String vmName, IProgressMonitor pm) throws CoreException { URL[] classPaths = null; IJavaProject javaProject = null; if (project != null) { javaProject = JavaCore.create(project); // Add in the paths for the project classPaths = ProxyLaunchSupport .convertStringPathsToURL(JavaRuntime.computeDefaultRuntimeClassPath(javaProject)); } else classPaths = new URL[0]; final IJavaProject jp = javaProject; final ProxyLaunchSupport.LaunchInfo launchInfo = new ProxyLaunchSupport.LaunchInfo(); contributors = ProxyLaunchSupport.fillInLaunchInfo( contributors == null ? ProxyLaunchSupport.EMPTY_CONFIG_CONTRIBUTORS : contributors, launchInfo, jp != null ? jp.getElementName() : null); final LocalFileConfigurationContributorController controller = new LocalFileConfigurationContributorController( classPaths, new URL[3][], launchInfo); final IConfigurationContributor[] contribs = contributors; for (int i = 0; i < contributors.length; i++) { final int ii = i; // Run in safe mode so that anything happens we don't go away. SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { // Don't need to do anything. Platform.run logs it for me. } public void run() throws Exception { contribs[ii].initialize(launchInfo.getConfigInfo()); } }); } for (int i = 0; i < contributors.length; i++) { final int ii = i; // Run in safe mode so that anything happens we don't go away. SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { // Don't need to do anything. Platform.run logs it for me. } public void run() throws Exception { contribs[ii].contributeClasspaths(controller); } }); } classPaths = controller.getFinalClasspath(); final BaseProxyFactoryRegistry registry = (BaseProxyFactoryRegistry) createIDEProxyFactoryRegistry(vmName, pluginName, classPaths); ProxyLaunchSupport.performExtensionRegistrations(registry, launchInfo); for (int i = 0; i < contribs.length; i++) { final int ii = i; // Run in safe mode so that anything happens we don't go away. SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { // Don't need to do anything. Platform.run logs it for me. } public void run() throws Exception { contribs[ii].contributeToRegistry(registry); } }); } return registry; }
From source file:org.eclipse.m2e.jdt.internal.InternalModuleSupport.java
License:Open Source License
private static String getModuleNameFromProject(IPath projectPath, IProgressMonitor monitor) { IJavaProject project = getJavaProject(projectPath); String module = null;/*from ww w . j a v a2 s . c o m*/ if (project != null) { try { if (project.getModuleDescription() == null) { String buildName = null; IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry() .getProject(project.getProject()); if (facade != null) { MavenProject mavenProject = facade.getMavenProject(monitor); if (mavenProject != null) { buildName = mavenProject.getBuild().getFinalName(); } } if (buildName == null || buildName.isEmpty()) { buildName = project.getElementName(); } module = new String(AutomaticModuleNaming.determineAutomaticModuleName(buildName, false, null)); } else { module = project.getModuleDescription().getElementName(); } } catch (CoreException ex) { log.error(ex.getMessage(), ex); } } return module; }
From source file:org.eclipse.modisco.java.discoverer.ElementsToAnalyze.java
License:Open Source License
@Override public String toString() { StringBuilder builder = new StringBuilder(); boolean first = true; for (Object object : getElementsToDiscover()) { if (!first) { builder.append(", "); //$NON-NLS-1$ }/*from www . j a v a 2 s . c o m*/ first = false; if (object instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) object; builder.append(javaProject.getElementName()); } else if (object instanceof IPackageFragmentRoot) { IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) object; builder.append(packageFragmentRoot.getElementName()); } else { builder.append(object.toString()); } } return builder.toString(); }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JavaReader.java
License:Open Source License
public void readModel(final Object source, final Model resultModel1, final BindingManager bindingManager, final IProgressMonitor monitor) { if (source == null) { return;//w ww . j a v a2 s .c o m } setResultModel(resultModel1); setGlobalBindings(bindingManager); if (this.incremental) { getGlobalBindings().enableIncrementalDiscovering(getResultModel()); } else { getGlobalBindings().disableIncrementalDiscovering(); } JDTVisitorUtils.initializePrimitiveTypes(this.factory, resultModel1, getGlobalBindings()); try { if (source instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) source; if (resultModel1.getName() == null || resultModel1.getName().length() == 0) { resultModel1.setName(javaProject.getElementName()); } IPackageFragment[] packageFolder = javaProject.getPackageFragments(); // loop on CompilationUnit-s for (IPackageFragment parent : packageFolder) { // test if package has compilations units and has not been // excluded if (parent.getCompilationUnits().length > 0 && !ignorePackage(parent)) { // report some feedback monitor.subTask(Messages.JavaReader_discoveringTask + parent.getElementName()); // parse package parsePackage(javaProject, resultModel1, parent, monitor); } if (monitor.isCanceled()) { return; } } } else if (source instanceof ITypeRoot) { parseTypeRoot((ITypeRoot) source); } else { throw new IllegalArgumentException( "Java reader can not handle source object : " + source.toString()); //$NON-NLS-1$ } } catch (Exception e) { MoDiscoLogger.logError(e, JavaActivator.getDefault()); } }
From source file:org.eclipse.modisco.java.discoverer.internal.serialization.ElementsToAnalyzeSerializer.java
License:Open Source License
public String serialize(final ElementsToAnalyze elementsToAnalyze) { try {/*w w w .j av a 2 s . com*/ StringBuilder builder = new StringBuilder(); IJavaProject javaProject = elementsToAnalyze.getJavaProject(); if (javaProject == null) { return ""; //$NON-NLS-1$ } builder.append(escape(javaProject.getElementName())); builder.append(ElementsToAnalyzeSerializer.SEPARATOR1); Set<Object> elementsToDiscover = elementsToAnalyze.getElementsToDiscover(); boolean first = true; for (Object object : elementsToDiscover) { if (!first) { builder.append(ElementsToAnalyzeSerializer.SEPARATOR1); } first = false; if (object instanceof IJavaProject) { IJavaProject javaProject2 = (IJavaProject) object; builder.append(ElementsToAnalyzeSerializer.PROJECT_PREFIX); builder.append(escape(javaProject2.getElementName())); } else if (object instanceof IJavaElement) { IJavaElement javaElement = (IJavaElement) object; builder.append(ElementsToAnalyzeSerializer.ELEMENT_PREFIX); builder.append(escape(javaElement.getJavaProject().getElementName())); builder.append(ElementsToAnalyzeSerializer.SEPARATOR3); builder.append(escape(javaElement.getElementName())); builder.append(ElementsToAnalyzeSerializer.SEPARATOR3); builder.append(escape(javaElement.getPath().toString())); } else { MoDiscoLogger.logError("Unexpected element: " + object.getClass().getName(), //$NON-NLS-1$ JavaActivator.getDefault()); continue; } Map<String, Object> discoveryOptions = elementsToAnalyze.getDiscoveryOptions(object); for (Entry<String, Object> entry : discoveryOptions.entrySet()) { builder.append(ElementsToAnalyzeSerializer.SEPARATOR2); builder.append(escape(entry.getKey())); builder.append(ElementsToAnalyzeSerializer.SEPARATOR2); ISerializer<?> serializer2 = ISerializationRegistry.INSTANCE .getSerializerFor(entry.getValue().getClass()); if (serializer2 != null) { String serialized2 = ISerializationService.INSTANCE.serialize(entry.getValue()); if (serialized2 != null) { builder.append(escape(serialized2)); } } else { MoDiscoLogger.logError("No serializer for: " + entry.getValue().getClass().getName(), //$NON-NLS-1$ JavaActivator.getDefault()); } } } return builder.toString(); } catch (Exception e) { MoDiscoLogger.logError(e, "Error serializing elements to analyze", //$NON-NLS-1$ JavaActivator.getDefault()); return ""; //$NON-NLS-1$ } }
From source file:org.eclipse.modisco.java.discoverer.internal.serialization.JavaProjectSerializer.java
License:Open Source License
public String serialize(final IJavaProject javaProject) { return javaProject.getElementName(); }