本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil类的典型用法代码示例。如果您正苦于以下问题:Java JavaElementUtil类的具体用法?Java JavaElementUtil怎么用?Java JavaElementUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaElementUtil类属于org.eclipse.jdt.internal.corext.refactoring.util包,在下文中一共展示了JavaElementUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHierarchicalDisabledImport
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
@Test
public void testHierarchicalDisabledImport() throws Exception {
fRenameSubpackages = true;
fUpdateTextualMatches = true;
PackageRename rename =
new PackageRename(new String[] {"my", "my.pack"}, new String[][] {{}, {"C"}}, "your");
IPackageFragment thisPackage = rename.fPackages[0];
ParticipantTesting.reset();
List toRename =
new ArrayList(Arrays.asList(JavaElementUtil.getPackageAndSubpackages(thisPackage)));
toRename.add(thisPackage.getResource());
String[] renameHandles = ParticipantTesting.createHandles(toRename.toArray());
rename.execute();
ParticipantTesting.testRename(
renameHandles,
new RenameArguments[] {
new RenameArguments(rename.getNewPackageName(rename.fPackageNames[0]), true),
new RenameArguments(rename.getNewPackageName(rename.fPackageNames[1]), true),
new RenameArguments("your", true)
});
}
示例2: checkParameterNamesInRippleMethods
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
private RefactoringStatus checkParameterNamesInRippleMethods() throws JavaModelException {
RefactoringStatus result = new RefactoringStatus();
Set<String> newParameterNames = getNewParameterNamesList();
for (int i = 0; i < fRippleMethods.length; i++) {
String[] paramNames = fRippleMethods[i].getParameterNames();
for (int j = 0; j < paramNames.length; j++) {
if (newParameterNames.contains(paramNames[j])) {
String[] args =
new String[] {
JavaElementUtil.createMethodSignature(fRippleMethods[i]),
BasicElementLabels.getJavaElementName(paramNames[j])
};
String msg =
Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_already_has, args);
RefactoringStatusContext context =
JavaStatusContext.create(
fRippleMethods[i].getCompilationUnit(), fRippleMethods[i].getNameRange());
result.addError(msg, context);
}
}
}
return result;
}
示例3: checkNativeMethods
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
private RefactoringStatus checkNativeMethods() throws JavaModelException {
RefactoringStatus result = new RefactoringStatus();
for (int i = 0; i < fRippleMethods.length; i++) {
if (JdtFlags.isNative(fRippleMethods[i])) {
String message =
Messages.format(
RefactoringCoreMessages.ChangeSignatureRefactoring_native,
new String[] {
JavaElementUtil.createMethodSignature(fRippleMethods[i]),
BasicElementLabels.getJavaElementName(
fRippleMethods[i].getDeclaringType().getFullyQualifiedName('.'))
});
result.addError(message, JavaStatusContext.create(fRippleMethods[i]));
}
}
return result;
}
示例4: checkNewAccessor
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
private RefactoringStatus checkNewAccessor(IMethod existingAccessor, String newAccessorName)
throws CoreException {
RefactoringStatus result = new RefactoringStatus();
IMethod accessor =
JavaModelUtil.findMethod(
newAccessorName,
existingAccessor.getParameterTypes(),
false,
fField.getDeclaringType());
if (accessor == null || !accessor.exists()) return null;
String message =
Messages.format(
RefactoringCoreMessages.RenameFieldRefactoring_already_exists,
new String[] {
JavaElementUtil.createMethodSignature(accessor),
BasicElementLabels.getJavaElementName(
fField.getDeclaringType().getFullyQualifiedName('.'))
});
result.addError(message, JavaStatusContext.create(accessor));
return result;
}
示例5: checkIfOverridesAnother
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
public static RefactoringStatus checkIfOverridesAnother(IMethod method, ITypeHierarchy hierarchy)
throws JavaModelException {
IMethod overrides = MethodChecks.overridesAnotherMethod(method, hierarchy);
if (overrides == null) return null;
RefactoringStatusContext context = JavaStatusContext.create(overrides);
String message =
Messages.format(
RefactoringCoreMessages.MethodChecks_overrides,
new String[] {
JavaElementUtil.createMethodSignature(overrides),
JavaElementLabels.getElementLabel(
overrides.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)
});
return RefactoringStatus.createStatus(
RefactoringStatus.FATAL,
message,
context,
Corext.getPluginId(),
RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD,
overrides);
}
示例6: checkIfComesFromInterface
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
public static RefactoringStatus checkIfComesFromInterface(
IMethod method, ITypeHierarchy hierarchy, IProgressMonitor monitor)
throws JavaModelException {
IMethod inInterface = MethodChecks.isDeclaredInInterface(method, hierarchy, monitor);
if (inInterface == null) return null;
RefactoringStatusContext context = JavaStatusContext.create(inInterface);
String message =
Messages.format(
RefactoringCoreMessages.MethodChecks_implements,
new String[] {
JavaElementUtil.createMethodSignature(inInterface),
JavaElementLabels.getElementLabel(
inInterface.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)
});
return RefactoringStatus.createStatus(
RefactoringStatus.FATAL,
message,
context,
Corext.getPluginId(),
RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE,
inInterface);
}
示例7: getChangedFiles
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
@Override
protected IFile[] getChangedFiles() throws CoreException {
Set<IFile> combined = new HashSet<IFile>();
combined.addAll(Arrays.asList(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits())));
if (fRenameSubpackages) {
IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(fPackage);
for (int i = 0; i < allPackages.length; i++) {
combined.addAll(Arrays.asList(ResourceUtil.getFiles(allPackages[i].getCompilationUnits())));
}
} else {
combined.addAll(Arrays.asList(ResourceUtil.getFiles(fPackage.getCompilationUnits())));
}
if (fQualifiedNameSearchResult != null)
combined.addAll(Arrays.asList(fQualifiedNameSearchResult.getAllFiles()));
return combined.toArray(new IFile[combined.size()]);
}
示例8: getUpdateModelFlags
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
protected int getUpdateModelFlags(boolean isCopy) throws JavaModelException {
final int destination = IPackageFragmentRoot.DESTINATION_PROJECT_CLASSPATH;
final int replace = IPackageFragmentRoot.REPLACE;
final int originating;
final int otherProjects;
if (isCopy) {
originating = 0; // ORIGINATING_PROJECT_CLASSPATH does not apply to copy
otherProjects = 0; // OTHER_REFERRING_PROJECTS_CLASSPATH does not apply to copy
} else {
originating = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH;
otherProjects = IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
}
IJavaElement javaElement = JavaCore.create(getDestination());
if (javaElement == null || !javaElement.exists()) return replace | originating;
if (fUpdateClasspathQuery == null) return replace | originating | destination;
IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(getRoot());
if (referencingProjects.length <= 1) return replace | originating | destination;
boolean updateOtherProjectsToo =
fUpdateClasspathQuery.confirmManipulation(getRoot(), referencingProjects);
if (updateOtherProjectsToo) return replace | originating | destination | otherProjects;
else return replace | originating | destination;
}
示例9: createUndoChange
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
@Override
protected Change createUndoChange(long stampToRestore) throws CoreException {
IPackageFragment pack = getPackage();
if (pack == null) return new NullChange();
Map<IResource, Long> stamps = new HashMap<IResource, Long>();
if (!fRenameSubpackages) {
addStamps(stamps, pack.getCompilationUnits());
} else {
IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
for (int i = 0; i < allPackages.length; i++) {
IPackageFragment currentPackage = allPackages[i];
addStamps(stamps, currentPackage.getCompilationUnits());
}
}
return new RenamePackageChange(
createNewPath(), getNewName(), getOldName(), stampToRestore, stamps, fRenameSubpackages);
// Note: This reverse change only works if the renamePackage change did
// not merge the source package into an existing target.
}
示例10: checkDestinationInsideTypeToMove
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
private RefactoringStatus checkDestinationInsideTypeToMove() throws JavaModelException {
RefactoringStatus result= new RefactoringStatus();
for (int i= 0; i < fMembersToMove.length; i++) {
if (! (fMembersToMove[i] instanceof IType))
continue;
IType type= (IType) fMembersToMove[i];
if (fDestinationType.equals(type) || JavaElementUtil.isAncestorOf(type, fDestinationType)) {
String message= Messages.format(RefactoringCoreMessages.MoveMembersRefactoring_inside,
new String[] { getQualifiedTypeLabel(type), getQualifiedTypeLabel(fDestinationType)});
RefactoringStatusContext context= JavaStatusContext.create(fDestinationType.getCompilationUnit(), fDestinationType.getNameRange());
result.addFatalError(message, context);
return result;
}
}
return result;
}
示例11: checkNativeMovedMethods
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
private RefactoringStatus checkNativeMovedMethods(IProgressMonitor pm) throws JavaModelException{
pm.beginTask(RefactoringCoreMessages.MoveMembersRefactoring_checking, fMembersToMove.length);
RefactoringStatus result= new RefactoringStatus();
for (int i= 0; i < fMembersToMove.length; i++) {
if (fMembersToMove[i].getElementType() != IJavaElement.METHOD)
continue;
if (! JdtFlags.isNative(fMembersToMove[i]))
continue;
String message= Messages.format(RefactoringCoreMessages.MoveMembersRefactoring_native,
JavaElementUtil.createMethodSignature((IMethod)fMembersToMove[i]));
result.addWarning(message, JavaStatusContext.create(fMembersToMove[i]));
pm.worked(1);
}
pm.done();
return result;
}
示例12: checkParameterNamesInRippleMethods
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
private RefactoringStatus checkParameterNamesInRippleMethods() throws JavaModelException {
RefactoringStatus result= new RefactoringStatus();
Set<String> newParameterNames= getNewParameterNamesList();
for (int i= 0; i < fRippleMethods.length; i++) {
String[] paramNames= fRippleMethods[i].getParameterNames();
for (int j= 0; j < paramNames.length; j++) {
if (newParameterNames.contains(paramNames[j])){
String[] args= new String[]{ JavaElementUtil.createMethodSignature(fRippleMethods[i]), BasicElementLabels.getJavaElementName(paramNames[j])};
String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_already_has, args);
RefactoringStatusContext context= JavaStatusContext.create(fRippleMethods[i].getCompilationUnit(), fRippleMethods[i].getNameRange());
result.addError(msg, context);
}
}
}
return result;
}
示例13: getChangedFiles
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
@Override
protected IFile[] getChangedFiles() throws CoreException {
Set<IFile> combined= new HashSet<IFile>();
combined.addAll(Arrays.asList(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits())));
if (fRenameSubpackages) {
IPackageFragment[] allPackages= JavaElementUtil.getPackageAndSubpackages(fPackage);
for (int i= 0; i < allPackages.length; i++) {
combined.addAll(Arrays.asList(ResourceUtil.getFiles(allPackages[i].getCompilationUnits())));
}
} else {
combined.addAll(Arrays.asList(ResourceUtil.getFiles(fPackage.getCompilationUnits())));
}
if (fQualifiedNameSearchResult != null)
combined.addAll(Arrays.asList(fQualifiedNameSearchResult.getAllFiles()));
return combined.toArray(new IFile[combined.size()]);
}
示例14: addDeletableParentPackages
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
/**
* Adds deletable parent packages of the fragment "frag" to the list
* "deletableParentPackages"; also adds the resources of those packages to the
* set "resourcesToDelete".
* @param frag the package fragment
* @param initialPackagesToDelete the initial packages to delete
* @param resourcesToDelete result to add resources to delete
* @param deletableParentPackages result ro add deletable parent packages
* @throws CoreException should not happen
*/
private void addDeletableParentPackages(IPackageFragment frag, List<IPackageFragment> initialPackagesToDelete, Set<IResource> resourcesToDelete, List<IPackageFragment> deletableParentPackages)
throws CoreException {
if (frag.getResource().isLinked()) {
final IConfirmQuery query= fDeleteQueries.createYesNoQuery(RefactoringCoreMessages.JavaDeleteProcessor_confirm_linked_folder_delete, false, IReorgQueries.CONFIRM_DELETE_LINKED_PARENT);
if (!query.confirm(Messages.format(RefactoringCoreMessages.JavaDeleteProcessor_delete_linked_folder_question, BasicElementLabels.getResourceName(frag.getResource()))))
return;
}
final IResource[] children= ((IContainer) frag.getResource()).members();
for (int i= 0; i < children.length; i++) {
// Child must be a package fragment already in the list,
// or a resource which is deleted as well.
if (!resourcesToDelete.contains(children[i]))
return;
}
resourcesToDelete.add(frag.getResource());
deletableParentPackages.add(frag);
final IPackageFragment parent= JavaElementUtil.getParentSubpackage(frag);
if (parent != null && !initialPackagesToDelete.contains(parent))
addDeletableParentPackages(parent, initialPackagesToDelete, resourcesToDelete, deletableParentPackages);
}
示例15: removeUnconfirmedReferencedArchiveFiles
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入依赖的package包/类
private void removeUnconfirmedReferencedArchiveFiles(IConfirmQuery query) throws JavaModelException, OperationCanceledException {
List<IResource> filesToSkip= new ArrayList<IResource>(0);
for (int i= 0; i < fResources.length; i++) {
IResource resource= fResources[i];
if (! (resource instanceof IFile))
continue;
IJavaProject project= JavaCore.create(resource.getProject());
if (project == null || ! project.exists())
continue;
IPackageFragmentRoot root= project.findPackageFragmentRoot(resource.getFullPath());
if (root == null)
continue;
List<IJavaProject> referencingProjects= Arrays.asList(JavaElementUtil.getReferencingProjects(root));
if (skipDeletingReferencedRoot(query, root, referencingProjects))
filesToSkip.add(resource);
}
removeFromSetToDelete(filesToSkip.toArray(new IFile[filesToSkip.size()]));
}