@Override public Object[] getElements(Object inputElement) { try { if (inputElement instanceof IPackageFragment) { ICompilationUnit[] cu= ((IPackageFragment) inputElement).getCompilationUnits(); return cu; } } catch (JavaModelException e) { JavaPlugin.log(e); } return new Object[0]; }
private boolean isEmpty(IPackageFragment fragment) { try { return (fragment.getCompilationUnits().length == 0) && (fragment.getClassFiles().length == 0); } catch (JavaModelException e) { // ignore } return false; }
private Set<String> getTopLevelTypeNames() throws CoreException { ICompilationUnit[] cus= fPackage.getCompilationUnits(); Set<String> result= new HashSet<>(2 * cus.length); for (int i= 0; i < cus.length; i++) { result.addAll(getTopLevelTypeNames(cus[i])); } return result; }
private Set<String> getTopLevelTypeNames() throws CoreException { ICompilationUnit[] cus= fPackage.getCompilationUnits(); Set<String> result= new HashSet<>(2 * cus.length); for (int i= 0; i < cus.length; i++) { result.addAll(getTopLevelTypeNames(cus[i])); } return result; }
@Override public Object[] getElements(Object inputElement) { try { if (inputElement instanceof IPackageFragment) { ICompilationUnit[] cu= ((IPackageFragment) inputElement).getCompilationUnits(); return cu; } } catch (JavaModelException e) { JavaPlugin.log(e); } return new Object[0]; }
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 static boolean isDefaultPackageWithLinkedFiles(Object firstElement) throws JavaModelException { if (!JavaElementUtil.isDefaultPackage(firstElement)) return false; IPackageFragment defaultPackage= (IPackageFragment)firstElement; ICompilationUnit[] cus= defaultPackage.getCompilationUnits(); for (int i= 0; i < cus.length; i++) { if (isLinkedResource(cus[i])) return true; } return false; }
private static IType findType(IPackageFragment pack, String fullyQualifiedName) throws JavaModelException{ ICompilationUnit[] cus= pack.getCompilationUnits(); for (int i= 0; i < cus.length; i++) { ICompilationUnit unit= cus[i]; IType type= findType(unit, fullyQualifiedName); if (type != null && type.exists()) return type; } return null; }
private static IType findType(IPackageFragment pack, String fullyQualifiedName) throws JavaModelException{ ICompilationUnit[] cus= pack.getCompilationUnits(); for (int i= 0; i < cus.length; i++) { ICompilationUnit unit= cus[i]; IType type= findType(unit, fullyQualifiedName); if (type != null && type.exists()) return type; } return null; }
private void isValid(RefactoringStatus result, IPackageFragment pack, IProgressMonitor pm) throws JavaModelException { ICompilationUnit[] units= pack.getCompilationUnits(); pm.beginTask("", units.length); //$NON-NLS-1$ for (int i= 0; i < units.length; i++) { pm.subTask(Messages.format(RefactoringCoreMessages.RenamePackageChange_checking_change, JavaElementLabels.getElementLabel(pack, JavaElementLabels.ALL_DEFAULT))); checkIfModifiable(result, units[i].getResource(), VALIDATE_NOT_READ_ONLY | VALIDATE_NOT_DIRTY); pm.worked(1); } pm.done(); }
private void isValid(RefactoringStatus result, IPackageFragment pack, IProgressMonitor pm) throws JavaModelException { ICompilationUnit[] units= pack.getCompilationUnits(); pm.beginTask("", units.length); //$NON-NLS-1$ for (int i= 0; i < units.length; i++) { pm.subTask(Messages.format(RefactoringCoreMessages.RenamePackageChange_checking_change, JavaElementLabels.getElementLabel(pack, JavaElementLabels.ALL_DEFAULT))); checkIfModifiable(result, units[i].getResource(), VALIDATE_NOT_READ_ONLY | VALIDATE_NOT_DIRTY); pm.worked(1); } pm.done(); }
private RefactoringStatus checkTypeNameConflicts(IPackageFragmentRoot root, String newName, Set<String> topLevelTypeNames) throws CoreException { IPackageFragment otherPack= root.getPackageFragment(newName); if (fPackage.equals(otherPack)) { return null; } ICompilationUnit[] cus= otherPack.getCompilationUnits(); RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < cus.length; i++) { result.merge(checkTypeNameConflicts(cus[i], topLevelTypeNames)); } return result; }
private RefactoringStatus checkTypeNameConflicts(IPackageFragmentRoot root, String newName, Set<String> topLevelTypeNames) throws CoreException { IPackageFragment otherPack= root.getPackageFragment(newName); if (fPackage.equals(otherPack)) return null; ICompilationUnit[] cus= otherPack.getCompilationUnits(); RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < cus.length; i++) { result.merge(checkTypeNameConflicts(cus[i], topLevelTypeNames)); } return result; }
private RefactoringStatus checkTypeNameConflicts(IPackageFragmentRoot root, String newName, Set<String> topLevelTypeNames) throws CoreException { IPackageFragment otherPack= root.getPackageFragment(newName); if (fPackage.equals(otherPack)) return null; ICompilationUnit[] cus= otherPack.getCompilationUnits(); RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < cus.length; i++) { result.merge(checkTypeNameConflicts(cus[i], topLevelTypeNames)); } return result; }
private RefactoringStatus checkTypeNameConflicts(IPackageFragmentRoot root, String newName, Set topLevelTypeNames) throws CoreException { IPackageFragment otherPack= root.getPackageFragment(newName); if (fPackage.equals(otherPack)) return null; ICompilationUnit[] cus= otherPack.getCompilationUnits(); RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < cus.length; i++) { result.merge(checkTypeNameConflicts(cus[i], topLevelTypeNames)); } return result; }
private void findStaticHooks(final IPackageFragment pkg, final TreeMultimap<IType, IMethod> index) throws JavaModelException { for (final ITypeRoot f : pkg.getClassFiles()) { findStaticHooks(index, f); } for (final ITypeRoot f : pkg.getCompilationUnits()) { findStaticHooks(index, f); } }
private static void searchInPackage(List<TestItem> resultList, SearchTestItemParams params) throws JavaModelException { final IPackageFragment packageFragment = JDTUtils.resolvePackage(params.getUri()); for (final ICompilationUnit unit : packageFragment.getCompilationUnits()) { for (final IType type : unit.getTypes()) { resultList.add(TestItemUtils.constructTestItem(type, TestLevel.CLASS)); } } }
public static IType findTypeInPackage(IPackageFragment pack, String name) throws JavaModelException { Assert.isTrue(pack.exists()); Assert.isTrue(!pack.isReadOnly()); /* ICompilationUnit.getType expects simple name*/ if (name.indexOf(".") != -1) //$NON-NLS-1$ name= name.substring(0, name.indexOf(".")); //$NON-NLS-1$ ICompilationUnit[] cus= pack.getCompilationUnits(); for (int i= 0; i < cus.length; i++){ if (cus[i].getType(name).exists()) return cus[i].getType(name); } return null; }