Java Code Examples for org.eclipse.jdt.core.IType#newTypeHierarchy()
The following examples show how to use
org.eclipse.jdt.core.IType#newTypeHierarchy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeHierarchyLifeCycle.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private ITypeHierarchy createTypeHierarchy(IJavaElement[] elements, IProgressMonitor pm) throws JavaModelException { if (elements.length == 1 && elements[0].getElementType() == IJavaElement.TYPE) { IType type= (IType)elements[0]; if (fIsSuperTypesOnly) { return type.newSupertypeHierarchy(pm); } else { return type.newTypeHierarchy(pm); } } else { IRegion region= JavaCore.newRegion(); for (int i= 0; i < elements.length; i++) { if (elements[i].getElementType() == IJavaElement.JAVA_PROJECT) { // for projects only add the contained source folders IPackageFragmentRoot[] roots= ((IJavaProject)elements[i]).getPackageFragmentRoots(); for (int j= 0; j < roots.length; j++) { if (!roots[j].isExternal()) { region.add(roots[j]); } } } else { region.add(elements[i]); } } return JavaCore.newTypeHierarchy(region, null, pm); } }
Example 2
Source File: JavaImplementorFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public Collection<IType> findImplementingTypes(IType type, IProgressMonitor progressMonitor) { ITypeHierarchy typeHierarchy; try { typeHierarchy = type.newTypeHierarchy(progressMonitor); IType[] implementingTypes = typeHierarchy.getAllClasses(); HashSet<IType> result = new HashSet<IType>(Arrays.asList(implementingTypes)); return result; } catch (JavaModelException e) { JavaPlugin.log(e); } return null; }
Example 3
Source File: RippleMethodFinder.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { IType rep = fUnionFind.find(type); if (rep != null) { Collection<IType> collection = fRootReps.get(rep); for (Iterator<IType> iter = collection.iterator(); iter.hasNext();) { IType root = iter.next(); ITypeHierarchy hierarchy = fRootHierarchies.get(root); if (hierarchy == null) { hierarchy = root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1)); fRootHierarchies.put(root, hierarchy); } if (hierarchy.contains(type)) { return hierarchy; } } } return null; }
Example 4
Source File: RippleMethodFinder2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { IType rep= fUnionFind.find(type); if (rep != null) { Collection<IType> collection= fRootReps.get(rep); for (Iterator<IType> iter= collection.iterator(); iter.hasNext();) { IType root= iter.next(); ITypeHierarchy hierarchy= fRootHierarchies.get(root); if (hierarchy == null) { hierarchy= root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1)); fRootHierarchies.put(root, hierarchy); } if (hierarchy.contains(type)) { return hierarchy; } } } return null; }
Example 5
Source File: DispatchRenameSupport.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected Iterable<JvmGenericType> getSubTypes(JvmGenericType type, ResourceSet tempResourceSet) { IType javaType = (IType) javaElementFinder.findExactElementFor(type); List<JvmGenericType> allSubTypes = newArrayList(); try { ITypeHierarchy typeHierarchy = javaType.newTypeHierarchy(javaType.getJavaProject(), new NullProgressMonitor()); for (IType subType : typeHierarchy.getSubtypes(javaType)) { EObject jvmSubType = jvmElementFinder.getCorrespondingJvmElement(subType, tempResourceSet); if (jvmSubType instanceof JvmGenericType) { EObject indexJvmSubType = jvmElementFinder.findJvmElementDeclarationInIndex(jvmSubType, subType .getJavaProject().getProject(), type.eResource().getResourceSet()); if (indexJvmSubType instanceof JvmGenericType) { allSubTypes.add((JvmGenericType) indexJvmSubType); } else { EObject jvmSubTypeInOtherResourceSet = type.eResource().getResourceSet().getEObject(EcoreUtil2.getPlatformResourceOrNormalizedURI(jvmSubType), true); if(jvmSubTypeInOtherResourceSet instanceof JvmGenericType) allSubTypes.add((JvmGenericType) jvmSubTypeInOtherResourceSet); } } } } catch (JavaModelException e) { LOG.error("Error calculating subtypes", e); } return allSubTypes; }
Example 6
Source File: ReplaceInvocationsRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl= fSourceProvider.getDeclaration(); IMethod method= (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type= method.getDeclaringType(); ITypeHierarchy hierarchy= type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); //$NON-NLS-1$ }
Example 7
Source File: InlineMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl= fSourceProvider.getDeclaration(); IMethod method= (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type= method.getDeclaringType(); ITypeHierarchy hierarchy= type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); //$NON-NLS-1$ }
Example 8
Source File: RippleMethodFinder2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { IType rep= fUnionFind.find(type); if (rep != null) { Collection<IType> collection= fRootReps.get(rep); for (Iterator<IType> iter= collection.iterator(); iter.hasNext();) { IType root= iter.next(); ITypeHierarchy hierarchy= fRootHierarchies.get(root); if (hierarchy == null) { hierarchy= root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1)); fRootHierarchies.put(root, hierarchy); } if (hierarchy.contains(type)) return hierarchy; } } return null; }
Example 9
Source File: MethodChecks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Locates the topmost method of an override ripple and returns it. If none * is found, null is returned. * * @param method the IMethod which may be part of a ripple * @param typeHierarchy a ITypeHierarchy of the declaring type of the method. May be null * @param monitor an IProgressMonitor * @return the topmost method of the ripple, or null if none * @throws JavaModelException */ public static IMethod getTopmostMethod(IMethod method, ITypeHierarchy typeHierarchy, IProgressMonitor monitor) throws JavaModelException { Assert.isNotNull(method); ITypeHierarchy hierarchy= typeHierarchy; IMethod topmostMethod= null; final IType declaringType= method.getDeclaringType(); if (!declaringType.isInterface()) { if ((hierarchy == null) || !declaringType.equals(hierarchy.getType())) hierarchy= declaringType.newTypeHierarchy(monitor); IMethod inInterface= isDeclaredInInterface(method, hierarchy, monitor); if (inInterface != null && !inInterface.equals(method)) topmostMethod= inInterface; } if (topmostMethod == null) { if (hierarchy == null) hierarchy= declaringType.newSupertypeHierarchy(monitor); IMethod overrides= overridesAnotherMethod(method, hierarchy); if (overrides != null && !overrides.equals(method)) topmostMethod= overrides; } return topmostMethod; }
Example 10
Source File: ConstructorReferenceFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IType[] getNonBinarySubtypes(WorkingCopyOwner owner, IType type, IProgressMonitor monitor) throws JavaModelException{ ITypeHierarchy hierarchy= null; if (owner == null) hierarchy= type.newTypeHierarchy(monitor); else hierarchy= type.newSupertypeHierarchy(owner, monitor); IType[] subTypes= hierarchy.getAllSubtypes(type); List<IType> result= new ArrayList<IType>(subTypes.length); for (int i= 0; i < subTypes.length; i++) { if (! subTypes[i].isBinary()) { result.add(subTypes[i]); } } return result.toArray(new IType[result.size()]); }
Example 11
Source File: PotentialProgrammingProblemsFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IType[] findTypesWithMissingUID(IJavaProject project, ICompilationUnit[] compilationUnits, IProgressMonitor monitor) throws CoreException { try { monitor.beginTask("", compilationUnits.length); //$NON-NLS-1$ IType serializable= project.findType(SERIALIZABLE_NAME); List<IType> types= new ArrayList<IType>(); if (compilationUnits.length > 500) { //500 is a guess. Building the type hierarchy on serializable is very expensive //depending on how many subtypes exit in the project. HashSet<ICompilationUnit> cus= new HashSet<ICompilationUnit>(); for (int i= 0; i < compilationUnits.length; i++) { cus.add(compilationUnits[i]); } monitor.subTask(Messages.format(FixMessages.Java50Fix_SerialVersion_CalculateHierarchy_description, SERIALIZABLE_NAME)); ITypeHierarchy hierarchy1= serializable.newTypeHierarchy(project, new SubProgressMonitor(monitor, compilationUnits.length)); IType[] allSubtypes1= hierarchy1.getAllSubtypes(serializable); addTypes(allSubtypes1, cus, types); } else { monitor.subTask(FixMessages.Java50Fix_InitializeSerialVersionId_subtask_description); for (int i= 0; i < compilationUnits.length; i++) { collectChildrenWithMissingSerialVersionId(compilationUnits[i].getChildren(), serializable, types); if (monitor.isCanceled()) throw new OperationCanceledException(); monitor.worked(1); } } return types.toArray(new IType[types.size()]); } finally { monitor.done(); } }
Example 12
Source File: JavaProjectPipelineOptionsHierarchy.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Creates a new {@link JavaProjectPipelineOptionsHierarchy}. This can be a long-running method, * as it fetches the type hierarchy of the provided project. * * @throws JavaModelException */ public JavaProjectPipelineOptionsHierarchy( IJavaProject project, MajorVersion version, IProgressMonitor monitor) throws JavaModelException { IType rootType = project.findType(PipelineOptionsNamespaces.rootType(version)); Preconditions.checkNotNull(rootType, "project has no PipelineOptions type"); Preconditions.checkArgument(rootType.exists(), "PipelineOptions does not exist in project"); // Flatten the class hierarchy, recording all the classes present this.hierarchy = rootType.newTypeHierarchy(monitor); this.project = project; this.majorVersion = version; this.knownTypes = new HashMap<>(); }
Example 13
Source File: TypeHierarchyCache.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public synchronized ITypeHierarchy getHierarchy(IType type) throws JavaModelException { // Return from the cache if available if (hierarchies.containsKey(type)) { return hierarchies.get(type); } // Create an auto-updating type hierarchy and cache it ITypeHierarchy hierarchy = type.newTypeHierarchy(null); hierarchy.addTypeHierarchyChangedListener(hierarchyUpdater); hierarchies.put(type, hierarchy); return hierarchy; }
Example 14
Source File: MethodChecks.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Locates the topmost method of an override ripple and returns it. If none * is found, null is returned. * * @param method the IMethod which may be part of a ripple * @param typeHierarchy a ITypeHierarchy of the declaring type of the method. May be null * @param monitor an IProgressMonitor * @return the topmost method of the ripple, or null if none * @throws JavaModelException */ public static IMethod getTopmostMethod(IMethod method, ITypeHierarchy typeHierarchy, IProgressMonitor monitor) throws JavaModelException { Assert.isNotNull(method); ITypeHierarchy hierarchy= typeHierarchy; IMethod topmostMethod= null; final IType declaringType= method.getDeclaringType(); if (!declaringType.isInterface()) { if ((hierarchy == null) || !declaringType.equals(hierarchy.getType())) { hierarchy= declaringType.newTypeHierarchy(monitor); } IMethod inInterface= isDeclaredInInterface(method, hierarchy, monitor); if (inInterface != null && !inInterface.equals(method)) { topmostMethod= inInterface; } } if (topmostMethod == null) { if (hierarchy == null) { hierarchy= declaringType.newSupertypeHierarchy(monitor); } IMethod overrides= overridesAnotherMethod(method, hierarchy); if (overrides != null && !overrides.equals(method)) { topmostMethod= overrides; } } return topmostMethod; }
Example 15
Source File: RenameVirtualMethodProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private ITypeHierarchy getCachedHierarchy(IType declaring, IProgressMonitor monitor) throws JavaModelException { if (fCachedHierarchy != null && declaring.equals(fCachedHierarchy.getType())) { return fCachedHierarchy; } fCachedHierarchy= declaring.newTypeHierarchy(new SubProgressMonitor(monitor, 1)); return fCachedHierarchy; }
Example 16
Source File: JavaElementDelegateJunitLaunch.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected IType[] getAllSuperTypes(IType type) throws JavaModelException { /* * https://stackoverflow.com/questions/49611587/developing-a-eclipse-how-to-get-all-inherited-methods-from-a-icompilationunit */ ITypeHierarchy th = type.newTypeHierarchy(new NullProgressMonitor()); IType[] superTypes = th.getAllSuperclasses(type); return superTypes; }
Example 17
Source File: ClassGenerator.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
private static IType generateImplementationClass(String packageName, String className, SourceRepositoryStore sourceStore, IProgressMonitor progressMonitor) throws Exception { final IJavaProject javaProject = RepositoryManager.getInstance().getCurrentRepository().getJavaProject(); final IType abstractConnectorType = javaProject.findType(AbstractConnector.class.getName()); final IType abstractFilterType = javaProject.findType(AbstractUserFilter.class.getName()); String abstractClassName = "Abstract" + className; if (packageName != null && !packageName.isEmpty()) { abstractClassName = packageName + "." + abstractClassName; } final IType classType = javaProject.findType(abstractClassName); if (classType == null) { throw new ClassNotFoundException(abstractClassName); } final ITypeHierarchy hierarchy = classType.newTypeHierarchy(javaProject, progressMonitor); String tempatePattern = null; if (hierarchy.contains(abstractConnectorType)) { tempatePattern = "/**\n*The connector execution will follow the steps" + "\n* 1 - setInputParameters() --> the connector receives input parameters values" + "\n* 2 - validateInputParameters() --> the connector can validate input parameters values" + "\n* 3 - connect() --> the connector can establish a connection to a remote server (if necessary)" + "\n* 4 - executeBusinessLogic() --> execute the connector" + "\n* 5 - getOutputParameters() --> output are retrieved from connector" + "\n* 6 - disconnect() --> the connector can close connection to remote server (if any)\n*/"; } else if (hierarchy.contains(abstractFilterType)) { tempatePattern = "/**\n*The actor filter execution will follow the steps" + "\n* 1 - setInputParameters() --> the actor filter receives input parameters values" + "\n* 2 - validateInputParameters() --> the actor filter can validate input parameters values" + "\n* 3 - filter(final String actorName) --> execute the user filter" + "\n* 4 - shouldAutoAssignTaskIfSingleResult() --> auto-assign the task if filter returns a single result\n*/"; } final NewClassWizardPage classWizard = new NewClassWizardPage(); classWizard.enableCommentControl(true); final ProjectTemplateStore fTemplateStore = new ProjectTemplateStore( RepositoryManager.getInstance().getCurrentRepository().getProject()); try { fTemplateStore.load(); } catch (final IOException e) { BonitaStudioLog.error(e); } final Template t = fTemplateStore.findTemplateById("org.eclipse.jdt.ui.text.codetemplates.typecomment"); t.setPattern(tempatePattern); classWizard.setSuperClass(abstractClassName, false); classWizard.setAddComments(true, false); classWizard.setModifiers(classWizard.F_PUBLIC, false); classWizard.setTypeName(className, false); classWizard.setMethodStubSelection(false, false, false, false); IPackageFragmentRoot packageFragmentRoot = null; final IResource srcFolder = sourceStore.getResource(); packageFragmentRoot = javaProject.getPackageFragmentRoot(srcFolder); classWizard.setPackageFragmentRoot(packageFragmentRoot, false); IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(packageName == null ? "" : packageName); if (!packageFragment.exists()) { packageFragment = packageFragmentRoot.createPackageFragment(packageName, true, progressMonitor); } classWizard.setPackageFragment(packageFragment, false); classWizard.createType(progressMonitor); return classWizard.getCreatedType(); }
Example 18
Source File: JDTTypeHierarchyManager.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected ITypeHierarchy createTypeHierarchy(final IType type) throws JavaModelException { final ITypeHierarchy res = type.newTypeHierarchy(null); typeHierarchies.put(type, res); return res; }
Example 19
Source File: RenameVirtualMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private ITypeHierarchy getCachedHierarchy(IType declaring, IProgressMonitor monitor) throws JavaModelException { if (fCachedHierarchy != null && declaring.equals(fCachedHierarchy.getType())) return fCachedHierarchy; fCachedHierarchy= declaring.newTypeHierarchy(new SubProgressMonitor(monitor, 1)); return fCachedHierarchy; }