org.eclipse.jdt.core.IPackageFragment Java Examples
The following examples show how to use
org.eclipse.jdt.core.IPackageFragment.
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: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testReconcile() throws Exception { IJavaProject javaProject = newEmptyProject(); IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E123 {\n"); buf.append(" public void testing() {\n"); buf.append(" int someIntegerChanged = 5;\n"); buf.append(" int i = someInteger + 5\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu1 = pack1.createCompilationUnit("E123.java", buf.toString(), false, null); openDocument(cu1, cu1.getSource(), 1); assertEquals(true, cu1.isWorkingCopy()); assertEquals(false, cu1.hasUnsavedChanges()); List<PublishDiagnosticsParams> diagnosticsParams = getClientRequests("publishDiagnostics"); assertEquals(1, diagnosticsParams.size()); PublishDiagnosticsParams diagnosticsParam = diagnosticsParams.get(0); List<Diagnostic> diagnostics = diagnosticsParam.getDiagnostics(); assertEquals(2, diagnostics.size()); diagnosticsParams.clear(); closeDocument(cu1); }
Example #2
Source File: ModifierCorrectionsQuickFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testInvalidMemberClassModifiers() throws Exception { IPackageFragment pack = fSourceFolder.createPackageFragment("test", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test;\n"); buf.append("public interface E {\n"); buf.append(" private class Inner {\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack.createCompilationUnit("E.java", buf.toString(), false, null); buf = new StringBuilder(); buf.append("package test;\n"); buf.append("public interface E {\n"); buf.append(" class Inner {\n"); buf.append(" }\n"); buf.append("}\n"); Expected e1 = new Expected(proposal, buf.toString()); assertCodeActions(cu, e1); }
Example #3
Source File: UnresolvedMethodsQuickFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testConstructorInvocation() throws Exception { IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public E(int i) {\n"); buf.append(" this(i, true);\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public E(int i) {\n"); buf.append(" this(i, true);\n"); buf.append(" }\n"); buf.append("\n"); buf.append(" public E(int i, boolean b) {\n"); buf.append(" }\n"); buf.append("}\n"); Expected e1 = new Expected("Create constructor 'E(int, boolean)'", buf.toString()); assertCodeActionExists(cu, e1); }
Example #4
Source File: ModuleUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Scans the package fragments (including jars if includeJars is true) invoking the visitor * callback. * * Stops if the callback returns a non-null result, and passes that result back to the caller. */ private static <T> T visitFragments(IJavaProject project, boolean includeJars, IPackageFragmentVisitor<T> visitor) { try { for (IPackageFragmentRoot pckgRoot : project.getPackageFragmentRoots()) { if (pckgRoot.isArchive() && !includeJars) { continue; } for (IJavaElement elem : pckgRoot.getChildren()) { T result = visitor.visit((IPackageFragment) elem); if (result != null) { return result; } } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } return null; }
Example #5
Source File: JavaElementResourceMapping.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static ResourceTraversal[] getPackageFragmentTraversals(IPackageFragment pack) throws CoreException { ArrayList<ResourceTraversal> res= new ArrayList<ResourceTraversal>(); IContainer container= (IContainer)pack.getResource(); if (container != null) { res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0)); if (pack.exists()) { // folder may not exist any more, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=269167 Object[] nonJavaResources= pack.getNonJavaResources(); for (int i= 0; i < nonJavaResources.length; i++) { Object resource= nonJavaResources[i]; if (resource instanceof IFolder) { res.add(new ResourceTraversal(new IResource[] { (IResource)resource }, IResource.DEPTH_INFINITE, 0)); } } } } return res.toArray(new ResourceTraversal[res.size()]); }
Example #6
Source File: ReorgQuickFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testUnusedImportsInDefaultPackage() throws Exception { IPackageFragment pack1 = fSourceFolder.createPackageFragment("", false, null); StringBuilder buf = new StringBuilder(); buf.append("import java.util.Vector;\n"); buf.append("public class E {\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); buf = new StringBuilder(); buf.append("\n"); buf.append("public class E {\n"); buf.append("}\n"); Expected e1 = new Expected("Remove unused import", buf.toString()); buf = new StringBuilder(); buf.append("public class E {\n"); buf.append("}\n"); Expected e2 = new Expected("Organize imports", buf.toString()); assertCodeActions(cu, e1, e2); }
Example #7
Source File: NewCheckCatalogWizardPage.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** {@inheritDoc} */ @Override public IStatus typeNameChanged() { super.typeNameChanged(); IStatus status = validator.checkCatalogName(getCatalogName()); if (!previousPageIsProjectPage()) { IPackageFragment packageFragment = getPackageFragment(); if (packageFragment != null && catalogExists(packageFragment.getResource())) { return new Status(IStatus.ERROR, status.getPlugin(), NLS.bind(com.avaloq.tools.ddk.check.validation.Messages.CheckJavaValidator_CATALOG_NAME_STATUS, com.avaloq.tools.ddk.check.validation.Messages.CheckJavaValidator_EXISTS)); } } if (!status.matches(IStatus.ERROR)) { projectInfo.setCatalogName(getCatalogName()); } return status; }
Example #8
Source File: PackageFileStore.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
private void deleteRecursivelyEmptyPackages(final IJavaProject project, IPackageFragment packageFragment) throws JavaModelException { if (packageFragment != null) { packageFragment.delete(true, new NullProgressMonitor());//delete the first one, we have only one package per Type packageFragment = retrieveParentPackageFragment(project, packageFragment); while (!packageFragment.hasChildren()) { //I don't find another way than passing through IResource, directly using IJavaElement seems not possible. final IPackageFragment parent = retrieveParentPackageFragment(project, packageFragment); packageFragment.delete(true, new NullProgressMonitor()); if (parent instanceof IPackageFragment && !parent.isDefaultPackage()) { packageFragment = parent; } else { return; } } } }
Example #9
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public boolean canUpdateQualifiedNames() { if (!canEnableQualifiedNameUpdating()) { return false; } IPackageFragment pack= getDestinationAsPackageFragment(); if (pack == null) { return false; } if (pack.isDefaultPackage()) { return false; } IJavaElement destination= getJavaElementDestination(); if (destination instanceof IPackageFragmentRoot && getCus().length > 0) { return false; } return true; }
Example #10
Source File: RegionBasedHierarchyBuilder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Adds all of the openables defined within this package fragment to the * list. */ private void injectAllOpenablesForPackageFragment( IPackageFragment packFrag, ArrayList openables) { try { IPackageFragmentRoot root = (IPackageFragmentRoot) packFrag.getParent(); int kind = root.getKind(); if (kind != 0) { boolean isSourcePackageFragment = (kind == IPackageFragmentRoot.K_SOURCE); if (isSourcePackageFragment) { ICompilationUnit[] cus = packFrag.getCompilationUnits(); for (int i = 0, length = cus.length; i < length; i++) { openables.add(cus[i]); } } else { IClassFile[] classFiles = packFrag.getClassFiles(); for (int i = 0, length = classFiles.length; i < length; i++) { openables.add(classFiles[i]); } } } } catch (JavaModelException e) { // ignore } }
Example #11
Source File: ClassDiagramExporter.java From txtUML with Eclipse Public License 1.0 | 6 votes |
private List<Class<?>> loadAllLinksFromModel(String modelName, ElementExporter elementExporter) throws NotFoundException, JavaModelException, IOException { IJavaProject javaProject = ProjectUtils.findJavaProject(elementExporter.getSourceProjectName()); // Sneaky.<JavaModelException> Throw(); // TODO check if explicit type parameters can be omitted > Neon.2 Stream<ICompilationUnit> stream = Stream.of(PackageUtils.findPackageFragments(javaProject, modelName)) .flatMap(Sneaky.<IPackageFragment, Stream<ICompilationUnit>, JavaModelException>unchecked( pf -> Stream.of(pf.getCompilationUnits()))); CompilationUnit[] units = SharedUtils.parseICompilationUnitStream(stream, javaProject); Iterator<Class<?>> it = elementExporter.getNodes().keySet().iterator(); if (it.hasNext()) { List<Class<?>> allLinks = new ArrayList<>(); ClassLoader loader = it.next().getClassLoader(); Stream.of(units).forEach(cu -> cu.accept(new AssociationVisitor(allLinks, loader))); return allLinks; } else { // No exported nodes found. throw new NotFoundException(); } }
Example #12
Source File: SignatureHelpHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testSignatureHelp_singleMethod() throws JavaModelException { IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" /** This is a method */\n"); buf.append(" public int foo(String s) { }\n"); buf.append(" public int bar(String s) { this.foo() }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); SignatureHelp help = getSignatureHelp(cu, 4, 39); assertNotNull(help); assertEquals(1, help.getSignatures().size()); assertEquals("foo(String s) : int", help.getSignatures().get(0).getLabel()); assertTrue(help.getSignatures().get(0).getDocumentation().getLeft().length() > 0); assertEquals((Integer) 0, help.getActiveParameter()); }
Example #13
Source File: CreateJavaTypeQuickfixes.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void setPackageName(NewTypeWizardPage page, URI contextUri, String packageName) { IJavaProject javaProject = getJavaProject(contextUri); String path = contextUri.trimSegments(1).toPlatformString(true); try { if(javaProject != null) { IPackageFragment contextPackageFragment = javaProject.findPackageFragment(new Path(path)); if (contextPackageFragment != null) { IPackageFragmentRoot root = (IPackageFragmentRoot) contextPackageFragment .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPackageFragment packageFragment; if(!isEmpty(packageName)) { packageFragment = root.getPackageFragment(packageName); } else { packageFragment = contextPackageFragment; } page.setPackageFragment(packageFragment, true); page.setPackageFragmentRoot(root, true); } } } catch (JavaModelException e) { LOG.error("Could not find package for " + path, e); } }
Example #14
Source File: PrepareRenameHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testRenameTypeWithResourceChanges() throws JavaModelException, BadLocationException { when(clientPreferences.isResourceOperationSupported()).thenReturn(true); IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); String[] codes = { "package test1;\n", "public class E|* {\n", " public E() {\n", " }\n", " public int bar() {\n", " }\n", " public int foo() {\n", " this.bar();\n", " }\n", "}\n" }; StringBuilder builder = new StringBuilder(); Position pos = mergeCode(builder, codes); ICompilationUnit cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null); Either<Range, PrepareRenameResult> result = prepareRename(cu, pos, "Newname"); assertNotNull(result.getLeft()); assertTrue(result.getLeft().getStart().getLine() > 0); }
Example #15
Source File: UnresolvedVariablesQuickFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testVarWithMethodName1() throws Exception { IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" int foo(String str) {\n"); buf.append(" for (int i = 0; i > str.length; i++) {\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" int foo(String str) {\n"); buf.append(" for (int i = 0; i > str.length(); i++) {\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); Expected e1 = new Expected("Change to 'length()'", buf.toString()); assertCodeActions(cu, e1); }
Example #16
Source File: OpenAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object getPackageFragmentObjectToOpen(IPackageFragment packageFragment) throws JavaModelException { ITypeRoot typeRoot= null; IPackageFragmentRoot root= (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root.getKind() == IPackageFragmentRoot.K_BINARY) typeRoot= (packageFragment).getClassFile(JavaModelUtil.PACKAGE_INFO_CLASS); else typeRoot= (packageFragment).getCompilationUnit(JavaModelUtil.PACKAGE_INFO_JAVA); if (typeRoot.exists()) return typeRoot; Object[] nonJavaResources= (packageFragment).getNonJavaResources(); for (Object nonJavaResource : nonJavaResources) { if (nonJavaResource instanceof IFile) { IFile file= (IFile) nonJavaResource; if (file.exists() && JavaModelUtil.PACKAGE_HTML.equals(file.getName())) { return file; } } } return packageFragment; }
Example #17
Source File: JavaBrowsingContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object[] getPackageContents(IPackageFragment fragment) throws JavaModelException { ISourceReference[] sourceRefs; if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceRefs= fragment.getCompilationUnits(); } else { IClassFile[] classFiles= fragment.getClassFiles(); List<IClassFile> topLevelClassFile= new ArrayList<IClassFile>(); for (int i= 0; i < classFiles.length; i++) { IType type= classFiles[i].getType(); if (type != null && type.getDeclaringType() == null && !type.isAnonymous() && !type.isLocal()) topLevelClassFile.add(classFiles[i]); } sourceRefs= topLevelClassFile.toArray(new ISourceReference[topLevelClassFile.size()]); } Object[] result= new Object[0]; for (int i= 0; i < sourceRefs.length; i++) result= concatenate(result, removeImportAndPackageDeclarations(getChildren(sourceRefs[i]))); return concatenate(result, fragment.getNonJavaResources()); }
Example #18
Source File: TypeMismatchQuickFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testTypeMismatchWithEnumConstant() throws Exception { IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null); StringBuilder buf = new StringBuilder(); buf.append("package pack;\n"); buf.append("public enum E {\n"); buf.append(" ONE;\n"); buf.append(" int m(int i) {\n"); buf.append(" return ONE;\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); buf = new StringBuilder(); buf.append("package pack;\n"); buf.append("public enum E {\n"); buf.append(" ONE;\n"); buf.append(" E m(int i) {\n"); buf.append(" return ONE;\n"); buf.append(" }\n"); buf.append("}\n"); Expected e1 = new Expected("Change method return type to 'E'", buf.toString()); assertCodeActions(cu, e1); }
Example #19
Source File: SignatureHelpHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testSignatureHelp_assertEquals() throws Exception { importProjects("maven/classpathtest"); project = WorkspaceHelper.getProject("classpathtest"); IJavaProject javaProject = JavaCore.create(project); sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src/test/java")); IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("import static org.junit.Assert.assertEquals;\n"); buf.append("public class E {\n"); buf.append(" public static void main(String[] args) {\n"); buf.append(" long num = 1;\n"); buf.append(" assertEquals(num,num)\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); testAssertEquals(cu, 5, 16); testAssertEquals(cu, 5, 17); testAssertEquals(cu, 5, 18); testAssertEquals(cu, 5, 19); testAssertEquals(cu, 5, 20); testAssertEquals(cu, 5, 21); testAssertEquals(cu, 5, 22); }
Example #20
Source File: PackagesViewHierarchicalContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private List<IAdaptable> getFoldersAndElements(IResource[] resources) { List<IAdaptable> list= new ArrayList<IAdaptable>(); for (int i= 0; i < resources.length; i++) { IResource resource= resources[i]; if (resource instanceof IFolder) { IFolder folder= (IFolder) resource; IJavaElement element= JavaCore.create(folder); if (element instanceof IPackageFragment) { list.add(element); } else { list.add(folder); } } } return list; }
Example #21
Source File: FileTransferDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected int determineOperation(Object target, int operation, TransferData transferType, int operations) { boolean isPackageFragment= target instanceof IPackageFragment; boolean isJavaProject= target instanceof IJavaProject; boolean isPackageFragmentRoot= target instanceof IPackageFragmentRoot; boolean isContainer= target instanceof IContainer; if (!(isPackageFragment || isJavaProject || isPackageFragmentRoot || isContainer)) return DND.DROP_NONE; if (isContainer) { IContainer container= (IContainer)target; if (container.isAccessible() && !Resources.isReadOnly(container)) return DND.DROP_COPY; } else { IJavaElement element= (IJavaElement)target; if (!element.isReadOnly()) return DND.DROP_COPY; } return DND.DROP_NONE; }
Example #22
Source File: ElementTypeTeller.java From txtUML with Eclipse Public License 1.0 | 6 votes |
/** * Checks a package if it belong to an existing model. Searches for a * package-info.java compilation unit in the package or one of the ancestor * packages and checks if it has the {@link Model} annotation. */ public static boolean isModelPackage(IPackageFragment pack) { try { IJavaProject javaProject = pack.getJavaProject(); String packageName = pack.getElementName(); for (IPackageFragmentRoot pfRoot : javaProject.getPackageFragmentRoots()) { if (!pfRoot.isExternal()) { if (isModelPackage(pfRoot, packageName)) { return true; } } } } catch (JavaModelException e) { // TODO: use PluginLogWrapper e.printStackTrace(); } return false; }
Example #23
Source File: ResourceUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Returns the classpath-relative path (with slashes, not dots) of the file * with the given filename. */ public static IPath getClasspathRelativePath(IPackageFragment pckg, String filename) { if (pckg.isDefaultPackage()) { return new Path(filename); } return new Path(pckg.getElementName().replace('.', '/')).append(filename); }
Example #24
Source File: EmptyPackageFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean select(Viewer viewer, Object parent, Object element) { if (element instanceof IPackageFragment) { IPackageFragment pkg= (IPackageFragment)element; try { return pkg.hasChildren() || hasUnfilteredResources(viewer, pkg); } catch (JavaModelException e) { return false; } } return true; }
Example #25
Source File: RenamePackageProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }
Example #26
Source File: PackagesViewFlatContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addElement(IPackageFragment frag) { String key= getKey(frag); LogicalPackage lp= fMapToLogicalPackage.get(key); if(lp != null && lp.belongs(frag)){ lp.add(frag); return; } IPackageFragment fragment= fMapToPackageFragments.get(key); if(fragment != null){ //must create a new LogicalPackage if(!fragment.equals(frag)){ lp= new LogicalPackage(fragment); lp.add(frag); fMapToLogicalPackage.put(key, lp); //@Improve: should I replace this with a refresh? postRemove(fragment); postAdd(lp); return; } } else { fMapToPackageFragments.put(key, frag); postAdd(frag); } }
Example #27
Source File: SourceFirstPackageSelectionDialogField.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void setDefaults(IPackageFragment fragment, ICompilationUnit cu) { IJavaElement element= fragment; if (element == null) { element= cu; } fSourceFolderSelection.setRoot(searchSourcePackageFragmentRoot(element)); fPackageSelection.setPackageFragment(searchPackageFragment(element)); }
Example #28
Source File: MoveCuUpdateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static SearchResultGroup[] getReferences(ICompilationUnit unit, IProgressMonitor pm, RefactoringStatus status) throws CoreException { final SearchPattern pattern= RefactoringSearchEngine.createOrPattern(unit.getTypes(), IJavaSearchConstants.REFERENCES); if (pattern != null) { String binaryRefsDescription= Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description , BasicElementLabels.getFileName(unit)); ReferencesInBinaryContext binaryRefs= new ReferencesInBinaryContext(binaryRefsDescription); Collector requestor= new Collector(((IPackageFragment) unit.getParent()), binaryRefs); IJavaSearchScope scope= RefactoringScopeFactory.create(unit, true, false); SearchResultGroup[] result= RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(pm, 1), status); binaryRefs.addErrorIfNecessary(status); return result; } return new SearchResultGroup[] {}; }
Example #29
Source File: RenamePackageChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void doRename(IProgressMonitor pm) throws CoreException { IPackageFragment pack= getPackage(); if (pack == null) return; if (!fRenameSubpackages) { renamePackage(pack, pm, createNewPath(), getNewName()); } else { IPackageFragment[] allPackages= JavaElementUtil.getPackageAndSubpackages(pack); Arrays.sort(allPackages, new Comparator<IPackageFragment>() { public int compare(IPackageFragment o1, IPackageFragment o2) { String p1= o1.getElementName(); String p2= o2.getElementName(); return p1.compareTo(p2); } }); int count= allPackages.length; pm.beginTask("", count); //$NON-NLS-1$ // When renaming to subpackage (a -> a.b), do it inside-out: boolean insideOut= getNewName().startsWith(getOldName()); try { for (int i= 0; i < count; i++) { IPackageFragment currentPackage= allPackages[insideOut ? count - i - 1 : i]; renamePackage(currentPackage, new SubProgressMonitor(pm, 1), createNewPath(currentPackage), getNewName(currentPackage)); } } finally { pm.done(); } } }
Example #30
Source File: RenamePackageChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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(); }