本文整理汇总了Java中org.eclipse.jdt.core.refactoring.CompilationUnitChange类的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnitChange类的具体用法?Java CompilationUnitChange怎么用?Java CompilationUnitChange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationUnitChange类属于org.eclipse.jdt.core.refactoring包,在下文中一共展示了CompilationUnitChange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
@Override
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite((ICompilationUnit)fCompilationUnit.getJavaElement(), fCompilationUnit);
fLinkedProposalModel.clear();
for (int i= 0; i < fOperations.length; i++) {
CompilationUnitRewriteOperation operation= fOperations[i];
operation.rewriteAST(cuRewrite, fLinkedProposalModel);
}
CompilationUnitChange result= cuRewrite.createChange(getDisplayString(), true, null);
if (result == null) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, Messages
.format(FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError, getDisplayString())));
}
return result;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:CompilationUnitRewriteOperationsFix.java
示例2: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
/** {@inheritDoc} */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
CompilationUnitRewrite cuRewrite =
new CompilationUnitRewrite(
(ICompilationUnit) fCompilationUnit.getJavaElement(), fCompilationUnit);
fLinkedProposalModel.clear();
for (int i = 0; i < fOperations.length; i++) {
CompilationUnitRewriteOperation operation = fOperations[i];
operation.rewriteAST(cuRewrite, fLinkedProposalModel);
}
CompilationUnitChange result = cuRewrite.createChange(getDisplayString(), true, null);
if (result == null)
throw new CoreException(
new Status(
IStatus.ERROR,
JavaPlugin.ID_PLUGIN,
Messages.format(
FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError,
getDisplayString())));
return result;
}
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:CompilationUnitRewriteOperationsFix.java
示例3: createAddImportChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
static CompilationUnitChange createAddImportChange(
ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
String[] args = {
BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName))
};
String label =
Messages.format(
CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);
CompilationUnitChange cuChange = new CompilationUnitChange(label, cu);
ImportRewrite importRewrite =
StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
importRewrite.addImport(fullyQualifiedName);
cuChange.setEdit(importRewrite.rewriteImports(null));
return cuChange;
}
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:UnresolvedElementsSubProcessor.java
示例4: cloneCompilationUnitChangeWithDifferentCu
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
/**
* Destructively clones a {@link CompilationUnitChange} where the cloned
* change will have a different compilation unit. This does not update text
* regions or anything more than setting the change properties and moving text
* edits from the old to new change.
*
* @param originalChange the original change, this change's internal state
* will likely become invalid (its text edits will be moved to the
* new change)
* @param cu the compilation unit to be used for the new
* {@link CompilationUnitChange}
* @return the cloned {@link CompilationUnitChange}
*/
public static CompilationUnitChange cloneCompilationUnitChangeWithDifferentCu(
TextFileChange originalChange, ICompilationUnit cu) {
CompilationUnitChange newChange = new CompilationUnitChange(
originalChange.getName(), cu);
newChange.setEdit(originalChange.getEdit());
newChange.setEnabledShallow(originalChange.isEnabled());
newChange.setKeepPreviewEdits(originalChange.getKeepPreviewEdits());
newChange.setSaveMode(originalChange.getSaveMode());
newChange.setTextType(originalChange.getTextType());
// Copy the changes over
TextEditUtilities.moveTextEditGroupsIntoChange(
originalChange.getChangeGroups(), newChange);
return newChange;
}
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:31,代码来源:ChangeUtilities.java
示例5: updateCu
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
private void updateCu(CompilationUnit unit, Set<ConstraintVariable> vars, CompilationUnitChange unitChange,
ASTRewrite unitRewriter, String typeName) throws JavaModelException {
// use custom SourceRangeComputer to avoid losing comments
unitRewriter.setTargetSourceRangeComputer(new SourceRangeComputer());
for (Iterator<ConstraintVariable> it=vars.iterator(); it.hasNext(); ){
ConstraintVariable cv = it.next();
ASTNode decl= findDeclaration(unit, cv);
if ((decl instanceof SimpleName || decl instanceof QualifiedName) && cv instanceof ExpressionVariable) {
ASTNode gp= decl.getParent().getParent();
updateType(unit, getType(gp), unitChange, unitRewriter, typeName); // local variable or parameter
} else if (decl instanceof MethodDeclaration || decl instanceof FieldDeclaration) {
updateType(unit, getType(decl), unitChange, unitRewriter, typeName); // method return or field type
} else if (decl instanceof ParameterizedType){
updateType(unit, getType(decl), unitChange, unitRewriter, typeName);
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:ChangeTypeRefactoring.java
示例6: addFields
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
public static Change addFields(ICompilationUnit cu, List<String> fields) throws CoreException {
AccessorClassModifier sourceModification= new AccessorClassModifier(cu);
String message= Messages.format(NLSMessages.AccessorClassModifier_add_fields_to_accessor, BasicElementLabels.getFileName(cu));
TextChange change= new CompilationUnitChange(message, cu);
MultiTextEdit multiTextEdit= new MultiTextEdit();
change.setEdit(multiTextEdit);
for (int i= 0; i < fields.size(); i++) {
String field= fields.get(i);
NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null);
sourceModification.addKey(substitution, change);
}
if (change.getChangeGroups().length == 0)
return null;
change.addEdit(sourceModification.getTextEdit());
return change;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:AccessorClassModifier.java
示例7: removeFields
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
public static Change removeFields(ICompilationUnit cu, List<String> fields) throws CoreException {
AccessorClassModifier sourceModification= new AccessorClassModifier(cu);
String message= Messages.format(NLSMessages.AccessorClassModifier_remove_fields_from_accessor, BasicElementLabels.getFileName(cu));
TextChange change= new CompilationUnitChange(message, cu);
MultiTextEdit multiTextEdit= new MultiTextEdit();
change.setEdit(multiTextEdit);
for (int i= 0; i < fields.size(); i++) {
String field= fields.get(i);
NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null);
sourceModification.removeKey(substitution, change);
}
if (change.getChangeGroups().length == 0)
return null;
change.addEdit(sourceModification.getTextEdit());
return change;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:AccessorClassModifier.java
示例8: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite((ICompilationUnit)fCompilationUnit.getJavaElement(), fCompilationUnit);
fLinkedProposalModel.clear();
for (int i= 0; i < fOperations.length; i++) {
CompilationUnitRewriteOperation operation= fOperations[i];
operation.rewriteAST(cuRewrite, fLinkedProposalModel);
}
CompilationUnitChange result= cuRewrite.createChange(getDisplayString(), true, null);
if (result == null)
throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format(FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError, getDisplayString())));
return result;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:CompilationUnitRewriteOperationsFix.java
示例9: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
CompositeChange changes = new CompositeChange("Rename method change");
for (ICompilationUnit unit : map.keySet()) {
TextEdit newEdit = map.get(unit).getAstRewrite().rewriteAST();
TextChange existingChange = getTextChange(unit);
if (existingChange == null) {
CompilationUnitChange change = new CompilationUnitChange("change", unit);
change.setEdit(newEdit);
changes.add(change);
} else {
TextEdit existingEdit = existingChange.getEdit();
if (existingEdit.covers(newEdit)) {
mergeEdits(existingEdit, newEdit);
} else {
existingEdit.addChild(newEdit);
}
}
}
return changes;
}
开发者ID:EsfingeFramework,项目名称:querybuilder_plugin,代码行数:25,代码来源:EsfingeRenameParticipant.java
示例10: addCopyrightsHeader
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
/**
* Adds copyright header to the compilation unit
*
* @param compilationUnit
* compilation unit affected
* @return compilation unit change
*/
public CompilationUnitChange addCopyrightsHeader(final CompilationUnit compilationUnit) {
final ICompilationUnit unit = (ICompilationUnit) compilationUnit.getJavaElement();
change = new CompilationUnitChange(ADD_COPYRIGHT, unit);
rewriter = ASTRewrite.create(compilationUnit.getAST());
final ListRewrite listRewrite = rewriter.getListRewrite(compilationUnit.getPackage(),
PackageDeclaration.ANNOTATIONS_PROPERTY);
final Comment placeHolder = (Comment) rewriter.createStringPlaceholder(getCopyrightText() + NEW_LINE_SEPARATOR,
ASTNode.BLOCK_COMMENT);
listRewrite.insertFirst(placeHolder, null);
rewriteCompilationUnit(unit, getNewUnitSource(unit, null));
return change;
}
开发者ID:SAP,项目名称:hybris-commerce-eclipse-plugin,代码行数:20,代码来源:CopyrightManager.java
示例11: replaceCopyrightsHeader
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
/**
* Replaces copyright header to the compilation unit
*
* @param compilationUnit
* compilation unit affected
* @return compilation unit change
*/
public CompilationUnitChange replaceCopyrightsHeader(final CompilationUnit compilationUnit) {
final ICompilationUnit unit = (ICompilationUnit) compilationUnit.getJavaElement();
change = new CompilationUnitChange(OVERRIDE_COPYRIGHT, unit);
rewriter = ASTRewrite.create(compilationUnit.getAST());
final List<Comment> comments = getCommentList(compilationUnit);
Comment copyrightComment = null;
if (!comments.isEmpty()) {
copyrightComment = comments.get(0);
}
rewriteCompilationUnit(unit, getNewUnitSource(unit, copyrightComment));
return change;
}
开发者ID:SAP,项目名称:hybris-commerce-eclipse-plugin,代码行数:20,代码来源:CopyrightManager.java
示例12: replaceDuplicates
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
private void replaceDuplicates(CompilationUnitChange result, int modifiers) {
int numberOf = getNumberOfDuplicates();
if (numberOf == 0 || !fReplaceDuplicates) {
return;
}
String label = null;
if (numberOf == 1) {
label = Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_single, BasicElementLabels.getJavaElementName(fMethodName));
} else {
label = Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_multi, BasicElementLabels.getJavaElementName(fMethodName));
}
TextEditGroup description = new TextEditGroup(label);
result.addTextEditGroup(description);
for (Match duplicate : fDuplicates) {
if (!duplicate.isInvalidNode()) {
if (isDestinationReachable(duplicate.getEnclosingMethod())) {
ASTNode[] callNodes = createCallNodes(duplicate, modifiers);
ASTNode[] duplicateNodes = duplicate.getNodes();
for (int i = 0; i < duplicateNodes.length; i++) {
ASTNode parent = duplicateNodes[i].getParent();
if (parent instanceof ParenthesizedExpression) {
duplicateNodes[i] = parent;
}
}
new StatementRewrite(fRewriter, duplicateNodes).replace(callNodes, description);
}
}
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:32,代码来源:ExtractMethodRefactoring.java
示例13: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
final String NN = ""; //$NON-NLS-1$
if (pm == null) {
pm = new NullProgressMonitor();
}
pm.beginTask(NN, 2);
try {
final CompilationUnitChange result = new CompilationUnitChange(getName(), fCUnit);
if (fLeaveDirty) {
result.setSaveMode(TextFileChange.LEAVE_DIRTY);
}
MultiTextEdit root = new MultiTextEdit();
result.setEdit(root);
fRewriter = ASTRewrite.create(fAnalyzer.getEnclosingBodyDeclaration().getAST());
fRewriter.setTargetSourceRangeComputer(new SelectionAwareSourceRangeComputer(fAnalyzer.getSelectedNodes(), fCUnit.getBuffer(), fSelection.getOffset(), fSelection.getLength()));
fImportRewrite = StubUtility.createImportRewrite(fRootNode, true);
fLinkedProposalModel = new LinkedProposalModel();
fScope = CodeScopeBuilder.perform(fAnalyzer.getEnclosingBodyDeclaration(), fSelection).findScope(fSelection.getOffset(), fSelection.getLength());
fScope.setCursor(fSelection.getOffset());
fSelectedNodes = fAnalyzer.getSelectedNodes();
createTryCatchStatement(fCUnit.getBuffer(), fCUnit.findRecommendedLineSeparator());
if (fImportRewrite.hasRecordedChanges()) {
TextEdit edit = fImportRewrite.rewriteImports(null);
root.addChild(edit);
result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] { edit }));
}
TextEdit change = fRewriter.rewriteAST();
root.addChild(change);
result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] { change }));
return result;
} finally {
pm.done();
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:41,代码来源:SurroundWithTryCatchRefactoring.java
示例14: addUnimplementedMethodsProposals
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
public static void addUnimplementedMethodsProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
IProposableFix fix = UnimplementedCodeFix.createAddUnimplementedMethodsFix(context.getASTRoot(), problem);
if (fix != null) {
try {
CompilationUnitChange change = fix.createChange(null);
CUCorrectionProposal proposal = new CUCorrectionProposal(change.getName(), change.getCompilationUnit(), change, IProposalRelevance.ADD_UNIMPLEMENTED_METHODS);
proposals.add(proposal);
} catch (CoreException e) {
JavaLanguageServerPlugin.log(e);
}
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:LocalCorrectionsSubProcessor.java
示例15: addUnusedMemberProposal
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
public static void addUnusedMemberProposal(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
int problemId = problem.getProblemId();
UnusedCodeFix fix = UnusedCodeFix.createUnusedMemberFix(context.getASTRoot(), problem, false);
if (fix != null) {
try {
CompilationUnitChange change = fix.createChange(null);
CUCorrectionProposal proposal = new CUCorrectionProposal(change.getName(), change.getCompilationUnit(), change, IProposalRelevance.UNUSED_MEMBER);
proposals.add(proposal);
} catch (CoreException e) {
JavaLanguageServerPlugin.log(e);
}
}
// TODO need to fork FixCorrectionProposal/ ICleanUp over from jdt.ui??
// if (problemId==IProblem.LocalVariableIsNeverUsed){
// fix= UnusedCodeFix.createUnusedMemberFix(context.getASTRoot(), problem, true);
// addProposal(context, proposals, fix);
// }
if (problemId == IProblem.ArgumentIsNeverUsed) {
JavadocTagsSubProcessor.getUnusedAndUndocumentedParameterOrExceptionProposals(context, problem, proposals);
}
if (problemId == IProblem.UnusedPrivateField) {
GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, problem, proposals);
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:29,代码来源:LocalCorrectionsSubProcessor.java
示例16: createTextChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
@Override
protected TextChange createTextChange() throws CoreException {
CompilationUnitChange createChange = fFix.createChange(null);
createChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
// if (fFix instanceof ILinkedFix) {
// setLinkedProposalModel(((ILinkedFix) fFix).getLinkedPositions());
// }
return createChange;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:12,代码来源:FixCorrectionProposal.java
示例17: createAddImportChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
static CompilationUnitChange createAddImportChange(ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
String[] args= { BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName)) };
String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);
CompilationUnitChange cuChange= new CompilationUnitChange(label, cu);
ImportRewrite importRewrite= StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
importRewrite.addImport(fullyQualifiedName);
cuChange.setEdit(importRewrite.rewriteImports(null));
return cuChange;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:12,代码来源:UnresolvedElementsSubProcessor.java
示例18: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
@Override
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
final CompilationUnitChange change = new CompilationUnitChange("Remove unnecessary visibility modifiers",
_context.getCompilationUnit());
final AST ast = _context.getAST().getAST();
final ASTRewrite rewriter = ASTRewrite.create(ast);
for (final ASTNode node : _annotationsToRemove) {
rewriter.remove(node, null);
}
addAnnotation(ast, rewriter, "ParametersAreNonnullByDefault", _nodesToAnnotateWithParameterAreNonnullByDefault);
addAnnotation(ast, rewriter, "ReturnValuesAreNonnullByDefault",
_nodesToAnnotateWithReturnValuesAreNonnullByDefault);
change.setEdit(rewriter.rewriteAST());
final boolean addImportForParameters = !_nodesToAnnotateWithParameterAreNonnullByDefault.isEmpty();
final boolean addImportForReturns = !_nodesToAnnotateWithReturnValuesAreNonnullByDefault.isEmpty();
if (addImportForParameters || addImportForReturns) {
final ImportRewrite importRewrite = createImportRewriterWithProjectSettings();
if (addImportForParameters) {
importRewrite.addImport(Jsr305CleanUp.FQN_PARAMETERS_ARE_NONNULL_BY_DEFAULT);
}
if (addImportForReturns) {
importRewrite.addImport(Jsr305CleanUp.FQN_RETURN_VALUES_ARE_NONNULL_BY_DEFAULT);
}
change.addEdit(importRewrite.rewriteImports(progressMonitor));
}
return change;
}
开发者ID:fabotronix,项目名称:jsr305CleanUp,代码行数:29,代码来源:Jsr305CleanUpFix.java
示例19: manageCompilationUnit
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
private void manageCompilationUnit(final TextEditBasedChangeManager manager, CompilationUnitRewrite rewrite,
Optional<IProgressMonitor> monitor) throws CoreException {
monitor.ifPresent(m -> m.beginTask("Creating change ...", IProgressMonitor.UNKNOWN));
CompilationUnitChange change = rewrite.createChange(false, monitor.orElseGet(NullProgressMonitor::new));
if (change != null)
change.setTextType("java");
manager.manage(rewrite.getCu(), change);
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:11,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java
示例20: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入依赖的package包/类
/** {@inheritDoc} */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
if (fEditGroups == null || fEditGroups.length == 0) return null;
CompilationUnitChange result = new CompilationUnitChange(getDisplayString(), fCompilationUnit);
for (int i = 0; i < fEditGroups.length; i++) {
TextEdit[] edits = fEditGroups[i].getTextEdits();
String groupName = fEditGroups[i].getName();
for (int j = 0; j < edits.length; j++) {
TextChangeCompatibility.addTextEdit(result, groupName, edits[j]);
}
}
return result;
}
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:StringFix.java
注:本文中的org.eclipse.jdt.core.refactoring.CompilationUnitChange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论