Java Code Examples for org.eclipse.jdt.core.dom.rewrite.ImportRewrite#setFilterImplicitImports()

The following examples show how to use org.eclipse.jdt.core.dom.rewrite.ImportRewrite#setFilterImplicitImports() . 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: MoveCuUpdateCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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('.'));
	}
}
 
Example 2
Source File: MoveCuUpdateCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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('.'));
	}
}
 
Example 3
Source File: RenamePackageProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void rewriteImports(TextChangeManager changeManager, IProgressMonitor pm) throws CoreException {
	for (Iterator<Entry<ICompilationUnit, ImportChange>> iter= fImportChanges.entrySet().iterator(); iter.hasNext();) {
		Entry<ICompilationUnit, ImportChange> entry= iter.next();
		ICompilationUnit cu= entry.getKey();
		ImportChange importChange= entry.getValue();

		ImportRewrite importRewrite= StubUtility.createImportRewrite(cu, true);
		importRewrite.setFilterImplicitImports(false);
		for (Iterator<String> iterator= importChange.fStaticToRemove.iterator(); iterator.hasNext();) {
			importRewrite.removeStaticImport(iterator.next());
		}
		for (Iterator<String> iterator= importChange.fToRemove.iterator(); iterator.hasNext();) {
			importRewrite.removeImport(iterator.next());
		}
		for (Iterator<String[]> iterator= importChange.fStaticToAdd.iterator(); iterator.hasNext();) {
			String[] toAdd= iterator.next();
			importRewrite.addStaticImport(toAdd[0], toAdd[1], true);
		}
		for (Iterator<String> iterator= importChange.fToAdd.iterator(); iterator.hasNext();) {
			importRewrite.addImport(iterator.next());
		}

		if (importRewrite.hasRecordedChanges()) {
			TextEdit importEdit= importRewrite.rewriteImports(pm);
			String name= RefactoringCoreMessages.RenamePackageRefactoring_update_imports;
			try {
				TextChangeCompatibility.addTextEdit(changeManager.get(cu), name, importEdit);
			} catch (MalformedTreeException e) {
				JavaLanguageServerPlugin.logError("MalformedTreeException while processing cu " + cu); //$NON-NLS-1$
				throw e;
			}
		}
	}
}
 
Example 4
Source File: RenamePackageProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void rewriteImports(TextChangeManager changeManager, IProgressMonitor pm) throws CoreException {
	for (Iterator<Entry<ICompilationUnit, ImportChange>> iter= fImportChanges.entrySet().iterator(); iter.hasNext();) {
		Entry<ICompilationUnit, ImportChange> entry= iter.next();
		ICompilationUnit cu= entry.getKey();
		ImportChange importChange= entry.getValue();

		ImportRewrite importRewrite= StubUtility.createImportRewrite(cu, true);
		importRewrite.setFilterImplicitImports(false);
		for (Iterator<String> iterator= importChange.fStaticToRemove.iterator(); iterator.hasNext();) {
			importRewrite.removeStaticImport(iterator.next());
		}
		for (Iterator<String> iterator= importChange.fToRemove.iterator(); iterator.hasNext();) {
			importRewrite.removeImport(iterator.next());
		}
		for (Iterator<String[]> iterator= importChange.fStaticToAdd.iterator(); iterator.hasNext();) {
			String[] toAdd= iterator.next();
			importRewrite.addStaticImport(toAdd[0], toAdd[1], true);
		}
		for (Iterator<String> iterator= importChange.fToAdd.iterator(); iterator.hasNext();) {
			importRewrite.addImport(iterator.next());
		}

		if (importRewrite.hasRecordedChanges()) {
			TextEdit importEdit= importRewrite.rewriteImports(pm);
			String name= RefactoringCoreMessages.RenamePackageRefactoring_update_imports;
			try {
				TextChangeCompatibility.addTextEdit(changeManager.get(cu), name, importEdit);
			} catch (MalformedTreeException e) {
				JavaPlugin.logErrorMessage("MalformedTreeException while processing cu " + cu); //$NON-NLS-1$
				throw e;
			}
		}
	}
}