本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange类的典型用法代码示例。如果您正苦于以下问题:Java RenameCompilationUnitChange类的具体用法?Java RenameCompilationUnitChange怎么用?Java RenameCompilationUnitChange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RenameCompilationUnitChange类属于org.eclipse.jdt.internal.corext.refactoring.changes包,在下文中一共展示了RenameCompilationUnitChange类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareChangeInfo
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
private ChangeInfo prepareChangeInfo(ChangeCorrectionProposal changeCorrectionProposal)
throws CoreException {
org.eclipse.ltk.core.refactoring.Change change = changeCorrectionProposal.getChange();
if (change == null) {
return null;
}
ChangeInfo changeInfo = DtoFactory.newDto(ChangeInfo.class);
String changeName = change.getName();
if (changeName.startsWith("Rename") && change instanceof RenameCompilationUnitChange) {
prepareRenameCompilationUnitChange(changeInfo, change);
} else if (changeName.startsWith("Move")) {
prepareMoveChange(changeInfo, change);
}
return changeInfo;
}
示例2: prepareRenameCompilationUnitChange
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
private void prepareRenameCompilationUnitChange(
ChangeInfo changeInfo, org.eclipse.ltk.core.refactoring.Change change) {
changeInfo.setName(ChangeInfo.ChangeName.RENAME_COMPILATION_UNIT);
RenameCompilationUnitChange renameChange = (RenameCompilationUnitChange) change;
changeInfo.setPath(
renameChange
.getResourcePath()
.removeLastSegments(1)
.append(renameChange.getNewName())
.toString());
changeInfo.setOldPath(renameChange.getResourcePath().toString());
}
示例3: prepareChangesInfo
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
/**
* Prepare the information about changes which were applied.
*
* @param changes array of the applied changes
* @param changesInfo prepared list of {@link ChangeInfo}
*/
public void prepareChangesInfo(Change[] changes, List<ChangeInfo> changesInfo) {
for (Change ch : changes) {
if (ch instanceof DynamicValidationStateChange) {
prepareChangesInfo(((DynamicValidationStateChange) ch).getChildren(), changesInfo);
} else {
ChangeInfo changeInfo = DtoFactory.newDto(ChangeInfo.class);
String refactoringName = ch.getName();
if (ch instanceof UndoTextFileChange) {
changeInfo.setName(ChangeInfo.ChangeName.UPDATE);
changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
}
if (refactoringName.startsWith("Rename")) {
if (ch instanceof RenameCompilationUnitChange) {
prepareRenameCompilationUnitChange(changeInfo, ch);
} else if (ch instanceof RenamePackageChange) {
prepareRenamePackageChange(changesInfo, changeInfo, ch);
}
}
if (refactoringName.startsWith("Move")) {
prepareMoveChange(changeInfo, ch);
}
changesInfo.add(changeInfo);
}
}
}
示例4: prepareRenameCompilationUnitChange
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
private void prepareRenameCompilationUnitChange(ChangeInfo changeInfo, Change ch) {
changeInfo.setName(ChangeInfo.ChangeName.RENAME_COMPILATION_UNIT);
changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
RenameCompilationUnitChange renameChange = (RenameCompilationUnitChange) ch;
changeInfo.setOldPath(
renameChange
.getResourcePath()
.removeLastSegments(1)
.append(renameChange.getNewName())
.toString());
}
示例5: createChange
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 4);
String project = null;
IJavaProject javaProject = fType.getJavaProject();
if (javaProject != null) project = javaProject.getElementName();
int flags =
JavaRefactoringDescriptor.JAR_MIGRATION
| JavaRefactoringDescriptor.JAR_REFACTORING
| RefactoringDescriptor.STRUCTURAL_CHANGE;
try {
if (!Flags.isPrivate(fType.getFlags())) flags |= RefactoringDescriptor.MULTI_CHANGE;
if (fType.isAnonymous() || fType.isLocal())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description =
Messages.format(
RefactoringCoreMessages.RenameTypeProcessor_descriptor_description_short,
BasicElementLabels.getJavaElementName(fType.getElementName()));
final String header =
Messages.format(
RefactoringCoreMessages.RenameTypeProcessor_descriptor_description,
new String[] {
JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED),
getNewElementLabel()
});
final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
final RenameJavaElementDescriptor descriptor =
RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
IJavaRefactorings.RENAME_TYPE);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setJavaElement(fType);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
descriptor.setUpdateReferences(fUpdateReferences);
if (fUpdateQualifiedNames
&& fFilePatterns != null
&& !"".equals(fFilePatterns)) // $NON-NLS-1$
descriptor.setFileNamePatterns(fFilePatterns);
descriptor.setUpdateSimilarDeclarations(fUpdateSimilarElements);
descriptor.setMatchStrategy(fRenamingStrategy);
final DynamicValidationRefactoringChange result =
new DynamicValidationRefactoringChange(
descriptor, RefactoringCoreMessages.RenameTypeProcessor_change_name);
if (fChangeManager.containsChangesIn(fType.getCompilationUnit())) {
TextChange textChange = fChangeManager.get(fType.getCompilationUnit());
if (textChange instanceof TextFileChange) {
((TextFileChange) textChange).setSaveMode(TextFileChange.FORCE_SAVE);
}
}
result.addAll(fChangeManager.getAllChanges());
if (willRenameCU()) {
IResource resource = fType.getCompilationUnit().getResource();
if (resource != null && resource.isLinked()) {
String ext = resource.getFileExtension();
String renamedResourceName;
if (ext == null) renamedResourceName = getNewElementName();
else renamedResourceName = getNewElementName() + '.' + ext;
result.add(
new RenameResourceChange(fType.getCompilationUnit().getPath(), renamedResourceName));
} else {
String renamedCUName =
JavaModelUtil.getRenamedCUName(fType.getCompilationUnit(), getNewElementName());
result.add(new RenameCompilationUnitChange(fType.getCompilationUnit(), renamedCUName));
}
}
monitor.worked(1);
return result;
} finally {
fChangeManager = null;
}
}
示例6: getWrongTypeNameProposals
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
public static void getWrongTypeNameProposals(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
boolean isLinked = cu.getResource().isLinked();
IJavaProject javaProject = cu.getJavaProject();
String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
CompilationUnit root = context.getASTRoot();
ASTNode coveredNode = problem.getCoveredNode(root);
if (!(coveredNode instanceof SimpleName)) return;
ASTNode parentType = coveredNode.getParent();
if (!(parentType instanceof AbstractTypeDeclaration)) return;
String currTypeName = ((SimpleName) coveredNode).getIdentifier();
String newTypeName = JavaCore.removeJavaLikeExtension(cu.getElementName());
boolean hasOtherPublicTypeBefore = false;
boolean found = false;
List<AbstractTypeDeclaration> types = root.types();
for (int i = 0; i < types.size(); i++) {
AbstractTypeDeclaration curr = types.get(i);
if (parentType != curr) {
if (newTypeName.equals(curr.getName().getIdentifier())) {
return;
}
if (!found && Modifier.isPublic(curr.getModifiers())) {
hasOtherPublicTypeBefore = true;
}
} else {
found = true;
}
}
if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance)
.matches(IStatus.ERROR)) {
proposals.add(
new CorrectMainTypeNameProposal(
cu, context, currTypeName, newTypeName, IProposalRelevance.RENAME_TYPE));
}
if (!hasOtherPublicTypeBefore) {
String newCUName = JavaModelUtil.getRenamedCUName(cu, currTypeName);
ICompilationUnit newCU = ((IPackageFragment) (cu.getParent())).getCompilationUnit(newCUName);
if (!newCU.exists()
&& !isLinked
&& !JavaConventions.validateCompilationUnitName(newCUName, sourceLevel, compliance)
.matches(IStatus.ERROR)) {
RenameCompilationUnitChange change = new RenameCompilationUnitChange(cu, newCUName);
// rename CU
String label =
Messages.format(
CorrectionMessages.ReorgCorrectionsSubProcessor_renamecu_description,
BasicElementLabels.getResourceName(newCUName));
proposals.add(
new ChangeCorrectionProposal(
label,
change,
IProposalRelevance.RENAME_CU,
JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_RENAME)));
}
}
}
示例7: createChange
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 4);
String project= null;
IJavaProject javaProject= fType.getJavaProject();
if (javaProject != null)
project= javaProject.getElementName();
int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
try {
if (!Flags.isPrivate(fType.getFlags()))
flags|= RefactoringDescriptor.MULTI_CHANGE;
if (fType.isAnonymous() || fType.isLocal())
flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description= Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fType.getElementName()));
final String header= Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED), getNewElementLabel()});
final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setJavaElement(fType);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
descriptor.setUpdateReferences(fUpdateReferences);
if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) //$NON-NLS-1$
descriptor.setFileNamePatterns(fFilePatterns);
descriptor.setUpdateSimilarDeclarations(fUpdateSimilarElements);
descriptor.setMatchStrategy(fRenamingStrategy);
final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeProcessor_change_name);
if (fChangeManager.containsChangesIn(fType.getCompilationUnit())) {
TextChange textChange= fChangeManager.get(fType.getCompilationUnit());
if (textChange instanceof TextFileChange) {
((TextFileChange) textChange).setSaveMode(TextFileChange.FORCE_SAVE);
}
}
result.addAll(fChangeManager.getAllChanges());
if (willRenameCU()) {
IResource resource= fType.getCompilationUnit().getResource();
if (resource != null && resource.isLinked()) {
String ext= resource.getFileExtension();
String renamedResourceName;
if (ext == null)
renamedResourceName= getNewElementName();
else
renamedResourceName= getNewElementName() + '.' + ext;
result.add(new RenameResourceChange(fType.getCompilationUnit().getPath(), renamedResourceName));
} else {
String renamedCUName= JavaModelUtil.getRenamedCUName(fType.getCompilationUnit(), getNewElementName());
result.add(new RenameCompilationUnitChange(fType.getCompilationUnit(), renamedCUName));
}
}
monitor.worked(1);
return result;
} finally {
fChangeManager= null;
}
}
示例8: getWrongTypeNameProposals
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
public static void getWrongTypeNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu= context.getCompilationUnit();
boolean isLinked= cu.getResource().isLinked();
IJavaProject javaProject= cu.getJavaProject();
String sourceLevel= javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
String compliance= javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
CompilationUnit root= context.getASTRoot();
ASTNode coveredNode= problem.getCoveredNode(root);
if (!(coveredNode instanceof SimpleName))
return;
ASTNode parentType= coveredNode.getParent();
if (!(parentType instanceof AbstractTypeDeclaration))
return;
String currTypeName= ((SimpleName) coveredNode).getIdentifier();
String newTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName());
boolean hasOtherPublicTypeBefore= false;
boolean found= false;
List<AbstractTypeDeclaration> types= root.types();
for (int i= 0; i < types.size(); i++) {
AbstractTypeDeclaration curr= types.get(i);
if (parentType != curr) {
if (newTypeName.equals(curr.getName().getIdentifier())) {
return;
}
if (!found && Modifier.isPublic(curr.getModifiers())) {
hasOtherPublicTypeBefore= true;
}
} else {
found= true;
}
}
if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance).matches(IStatus.ERROR)) {
proposals.add(new CorrectMainTypeNameProposal(cu, context, currTypeName, newTypeName, IProposalRelevance.RENAME_TYPE));
}
if (!hasOtherPublicTypeBefore) {
String newCUName= JavaModelUtil.getRenamedCUName(cu, currTypeName);
ICompilationUnit newCU= ((IPackageFragment) (cu.getParent())).getCompilationUnit(newCUName);
if (!newCU.exists() && !isLinked && !JavaConventions.validateCompilationUnitName(newCUName, sourceLevel, compliance).matches(IStatus.ERROR)) {
RenameCompilationUnitChange change= new RenameCompilationUnitChange(cu, newCUName);
// rename CU
String label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_renamecu_description, BasicElementLabels.getResourceName(newCUName));
proposals.add(new ChangeCorrectionProposal(label, change, IProposalRelevance.RENAME_CU, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_RENAME)));
}
}
}
示例9: getWrongTypeNameProposals
import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; //导入依赖的package包/类
public static void getWrongTypeNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu= context.getCompilationUnit();
boolean isLinked= cu.getResource().isLinked();
IJavaProject javaProject= cu.getJavaProject();
String sourceLevel= javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
String compliance= javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
CompilationUnit root= context.getASTRoot();
ASTNode coveredNode= problem.getCoveredNode(root);
if (!(coveredNode instanceof SimpleName))
return;
ASTNode parentType= coveredNode.getParent();
if (!(parentType instanceof AbstractTypeDeclaration))
return;
String currTypeName= ((SimpleName) coveredNode).getIdentifier();
String newTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName());
boolean hasOtherPublicTypeBefore= false;
boolean found= false;
List<AbstractTypeDeclaration> types= root.types();
for (int i= 0; i < types.size(); i++) {
AbstractTypeDeclaration curr= types.get(i);
if (parentType != curr) {
if (newTypeName.equals(curr.getName().getIdentifier())) {
return;
}
if (!found && Modifier.isPublic(curr.getModifiers())) {
hasOtherPublicTypeBefore= true;
}
} else {
found= true;
}
}
if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance).matches(IStatus.ERROR)) {
proposals.add(new CorrectMainTypeNameProposal(cu, context, currTypeName, newTypeName, 5));
}
if (!hasOtherPublicTypeBefore) {
String newCUName= JavaModelUtil.getRenamedCUName(cu, currTypeName);
ICompilationUnit newCU= ((IPackageFragment) (cu.getParent())).getCompilationUnit(newCUName);
if (!newCU.exists() && !isLinked && !JavaConventions.validateCompilationUnitName(newCUName, sourceLevel, compliance).matches(IStatus.ERROR)) {
RenameCompilationUnitChange change= new RenameCompilationUnitChange(cu, newCUName);
// rename CU
String label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_renamecu_description, BasicElementLabels.getResourceName(newCUName));
proposals.add(new ChangeCorrectionProposal(label, change, 6, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_RENAME)));
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:55,代码来源:ReorgCorrectionsSubProcessor.java