public static IType[] getClasses(ICompilationUnit cu) { if (cu == null) { throw new IllegalArgumentException("cu is null"); } try { return cu.getAllTypes(); } catch (JavaModelException e) { } return null; }
private IType findType(ICompilationUnit cu, String fullyQualifiedName) throws JavaModelException{ IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { IType type= types[i]; if (getFullyQualifiedName(type).equals(fullyQualifiedName)) return type; } return null; }
private static boolean doIsTest(ICompilationUnit iCompilationUnit) throws JavaModelException { IType[] types = iCompilationUnit.getAllTypes(); for (IType type : types) { if (doIsTest(type)) { return true; } } return false; }
IFile myJavaFile = <get the file> ICompilationUnit unit = JavaCore.createFromFile(myJavaFile); IType[] types = unit.getAllTypes(); for (IType type : types) { ITypeHierarchy th= type.newTypeHierarchy(null); // do something with the hierarchy }
private static IType findType(ICompilationUnit cu, String fullyQualifiedName) throws JavaModelException{ IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { IType type= types[i]; if (getFullyQualifiedName(type).equals(fullyQualifiedName)) return type; } return null; }
private static IType findType(ICompilationUnit cu, String fullyQualifiedName) throws JavaModelException{ IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { IType type= types[i]; if (getFullyQualifiedName(type).equals(fullyQualifiedName)) return type; } return null; }
private IType[] getDestinationPackageTypes() throws JavaModelException { List<IType> types= new ArrayList<>(); if (fDestination.exists()) { ICompilationUnit[] cus= fDestination.getCompilationUnits(); for (int i= 0; i < cus.length; i++) { types.addAll(Arrays.asList(cus[i].getAllTypes())); } } return types.toArray(new IType[types.size()]); }
private IType[] getDestinationPackageTypes() throws JavaModelException { List<IType> types= new ArrayList<>(); if (fDestination.exists()) { ICompilationUnit[] cus= fDestination.getCompilationUnits(); for (int i= 0; i < cus.length; i++) { types.addAll(Arrays.asList(cus[i].getAllTypes())); } } return types.toArray(new IType[types.size()]); }
private IType[] getDestinationPackageTypes() throws JavaModelException { List<IType> types= new ArrayList<>(); if (fDestination.exists()) { ICompilationUnit[] cus= fDestination.getCompilationUnits(); for (int i= 0; i < cus.length; i++) { types.addAll(Arrays.asList(cus[i].getAllTypes())); } } return types.toArray(new IType[types.size()]); }
private IType[] getDestinationPackageTypes() throws JavaModelException { List types= new ArrayList(); if (fDestination.exists()) { ICompilationUnit[] cus= fDestination.getCompilationUnits(); for (int i= 0; i < cus.length; i++) { types.addAll(Arrays.asList(cus[i].getAllTypes())); } } return (IType[]) types.toArray(new IType[types.size()]); }
/** * Finds a type in a compilation unit. Typical usage is to find the corresponding * type in a working copy. * @param cu the compilation unit to search in * @param typeQualifiedName the type qualified name (type name with enclosing type names (separated by dots)) * @return the type found, or null if not existing */ public static IType findTypeInCompilationUnit(ICompilationUnit cu, String typeQualifiedName) throws JavaModelException { IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { String currName= getTypeQualifiedName(types[i]); if (typeQualifiedName.equals(currName)) { return types[i]; } } return null; }
/** * Finds a type in a compilation unit. Typical usage is to find the corresponding * type in a working copy. * @param cu the compilation unit to search in * @param typeQualifiedName the type qualified name (type name with enclosing type names (separated by dots)) * @return the type found, or null if not existing */ public static IType findTypeInCompilationUnit(ICompilationUnit cu, String typeQualifiedName) throws JavaModelException { IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { String currName= getTypeQualifiedName(types[i]); if (typeQualifiedName.equals(currName)) { return types[i]; } } return null; }
/** * Finds a type in a compilation unit. Typical usage is to find the corresponding * type in a working copy. * @param cu the compilation unit to search in * @param typeQualifiedName the type qualified name (type name with enclosing type names (separated by dots)) * @return the type found, or null if not existing * @throws JavaModelException thrown when the cu can not be accessed */ public static IType findTypeInCompilationUnit(ICompilationUnit cu, String typeQualifiedName) throws JavaModelException { IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { String currName= types[i].getTypeQualifiedName('.'); if (typeQualifiedName.equals(currName)) { return types[i]; } } return null; }
/** * Finds a type in a compilation unit. Typical usage is to find the corresponding * type in a working copy. * @param cu the compilation unit to search in * @param typeQualifiedName the type qualified name (type name with enclosing type names (separated by dots)) * @return the type found, or null if not existing * @throws JavaModelException thrown when the cu can not be accessed */ public static IType findTypeInCompilationUnit(ICompilationUnit cu, String typeQualifiedName) throws JavaModelException { IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { String currName= types[i].getTypeQualifiedName('.'); if (typeQualifiedName.equals(currName)) { return types[i]; } } return null; }
private static void searchInNestedClass(List<TestItem> resultList, SearchTestItemParams params) throws JavaModelException { final ICompilationUnit compilationUnit = JDTUtils.resolveCompilationUnit(params.getUri()); for (final IType type : compilationUnit.getAllTypes()) { if (type.getFullyQualifiedName().equals(params.getFullName())) { resultList.addAll(searchTestMethodsOfType(type)); } } }
private void addImportToSourcePackageTypes(ICompilationUnit movedUnit, IProgressMonitor pm) throws CoreException{ List cuList= Arrays.asList(fCus); IType[] allCuTypes= movedUnit.getAllTypes(); IType[] referencedTypes= ReferenceFinderUtil.getTypesReferencedIn(allCuTypes, pm); ImportRewrite importEdit= getImportRewrite(movedUnit); importEdit.setFilterImplicitImports(false); IPackageFragment srcPack= (IPackageFragment)movedUnit.getParent(); for (int i= 0; i < referencedTypes.length; i++) { IType iType= referencedTypes[i]; if (! iType.exists()) continue; if (! iType.getPackageFragment().equals(srcPack)) continue; if (cuList.contains(iType.getCompilationUnit())) continue; importEdit.addImport(JavaModelUtil.getFullyQualifiedName(iType)); } }
private IType[] getTypes() throws JavaModelException { IEditorInput input= fEditor.getEditorInput(); if (input instanceof IClassFileEditorInput) { IClassFile classFile= ((IClassFileEditorInput)input).getClassFile(); if (classFile instanceof IOrdinaryClassFile) return new IType[] { ((IOrdinaryClassFile) classFile).getType() }; return new IType[0]; } else { return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input).getAllTypes(); } }
private IType[] getTypes() throws JavaModelException { IEditorInput input= fEditor.getEditorInput(); if (input instanceof IClassFileEditorInput) { return new IType[] { ((IClassFileEditorInput)input).getClassFile().getType() }; } else { return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input).getAllTypes(); } }
private IType[] getTypes() throws JavaModelException { IEditorInput input= fEditor.getEditorInput(); if (input instanceof IClassFileEditorInput) { return new IType[] { ((IClassFileEditorInput)input).getClassFile().getType() }; } else { return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input).getAllTypes(); } }
private void addImportToSourcePackageTypes(ICompilationUnit movedUnit, IProgressMonitor pm) throws CoreException{ List<ICompilationUnit> cuList= Arrays.asList(fCus); IType[] allCuTypes= movedUnit.getAllTypes(); IType[] referencedTypes= ReferenceFinderUtil.getTypesReferencedIn(allCuTypes, pm); ImportRewrite importEdit= getImportRewrite(movedUnit); importEdit.setFilterImplicitImports(false); IPackageFragment srcPack= (IPackageFragment)movedUnit.getParent(); for (int i= 0; i < referencedTypes.length; i++) { IType iType= referencedTypes[i]; if (! iType.exists()) continue; if (!JavaModelUtil.isSamePackage(iType.getPackageFragment(), srcPack)) continue; if (cuList.contains(iType.getCompilationUnit())) continue; importEdit.addImport(iType.getFullyQualifiedName('.')); } }