本文整理汇总了Java中org.eclipse.jdt.core.refactoring.CompilationUnitChange.perform方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnitChange.perform方法的具体用法?Java CompilationUnitChange.perform怎么用?Java CompilationUnitChange.perform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.refactoring.CompilationUnitChange
的用法示例。
在下文中一共展示了CompilationUnitChange.perform方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
public void run(IProgressMonitor monitor) throws CoreException {
ICompilationUnit icu = clientBundle.getCompilationUnit();
CompilationUnit cu = JavaASTUtils.parseCompilationUnit(icu);
ImportRewrite importRewrite = StubUtility.createImportRewrite(cu, true);
// Find the target type declaration
TypeDeclaration typeDecl = JavaASTUtils.findTypeDeclaration(cu,
clientBundle.getFullyQualifiedName());
if (typeDecl == null) {
throw new CoreException(
StatusUtilities.newErrorStatus("Missing ClientBundle type "
+ clientBundle.getFullyQualifiedName(), GWTPlugin.PLUGIN_ID));
}
// We need to rewrite the AST of the ClientBundle type declaration
ASTRewrite astRewrite = ASTRewrite.create(cu.getAST());
ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(typeDecl);
ListRewrite listRewriter = astRewrite.getListRewrite(typeDecl, property);
// Add the new resource methods
boolean addComments = StubUtility.doAddComments(icu.getJavaProject());
for (ClientBundleResource resource : resources) {
listRewriter.insertLast(resource.createMethodDeclaration(clientBundle,
astRewrite, importRewrite, addComments), null);
}
// Create the edit to add the methods and update the imports
TextEdit rootEdit = new MultiTextEdit();
rootEdit.addChild(astRewrite.rewriteAST());
rootEdit.addChild(importRewrite.rewriteImports(null));
// Apply the change to the compilation unit
CompilationUnitChange cuChange = new CompilationUnitChange(
"Update ClientBundle", icu);
cuChange.setSaveMode(TextFileChange.KEEP_SAVE_STATE);
cuChange.setEdit(rootEdit);
cuChange.perform(new NullProgressMonitor());
}
示例2: createChange_singlelineClassInstanceCreationWidgetSelectedAdapter_savedSinglelineLambda
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Test
public void createChange_singlelineClassInstanceCreationWidgetSelectedAdapter_savedSinglelineLambda() throws JavaModelException, CoreException, BadLocationException, IOException, URISyntaxException {
CompilationUnit astRoot = setupEnvironment(String.join("\n"
, "package " + PACKAGE_NAME
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(new SelectionAdapter() {"
, " @Override"
, " public void widgetSelected(SelectionEvent e) {"
, " System.out.println(\"Hello\");"
, " }"
, " });"
, " }"
, "}"
));
ICleanUpFix cleanUp = LambdaConverterFix.createCleanUp(astRoot, true);
CompilationUnitChange compilationUnitChange = cleanUp.createChange(new NullProgressMonitor());
compilationUnitChange.perform(new NullProgressMonitor());
ICompilationUnit iCU = (ICompilationUnit) astRoot.getJavaElement().getAdapter(IOpenable.class);
String expected = String.join("\n"
, "package p"
, "import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println(\"Hello\")));"
, " }"
, "}");
assertEquals(expected, iCU.getSource());
}
示例3: createChange_multilineClassInstanceCreationWidgetSelectedAdapter_savedMultilineLambda
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Test
public void createChange_multilineClassInstanceCreationWidgetSelectedAdapter_savedMultilineLambda() throws JavaModelException, CoreException, BadLocationException, IOException, URISyntaxException {
CompilationUnit astRoot = setupEnvironment(String.join("\n"
, "package " + PACKAGE_NAME
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(new SelectionAdapter() {"
, " @Override"
, " public void widgetSelected(SelectionEvent e) {"
, " System.out.println(\"Hello\");"
, " System.out.println(\"world\");"
, " }"
, " });"
, " }"
, "}"
));
ICleanUpFix cleanUp = LambdaConverterFix.createCleanUp(astRoot, true);
CompilationUnitChange compilationUnitChange = cleanUp.createChange(new NullProgressMonitor());
compilationUnitChange.perform(new NullProgressMonitor());
ICompilationUnit iCU = (ICompilationUnit) astRoot.getJavaElement().getAdapter(IOpenable.class);
String expected = String.join("\n"
, "package p"
, "import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(widgetSelectedAdapter(e -> {"
, " System.out.println(\"Hello\");"
, " System.out.println(\"world\");"
, " }));"
, " }"
, "}");
assertEquals(expected, iCU.getSource());
}
示例4: createChange_multilineClassInstanceCreationWidgetDefaultSelectedAdapter_savedMultilineLambda
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Test
public void createChange_multilineClassInstanceCreationWidgetDefaultSelectedAdapter_savedMultilineLambda() throws JavaModelException, CoreException, BadLocationException, IOException, URISyntaxException {
CompilationUnit astRoot = setupEnvironment(String.join("\n"
, "package " + PACKAGE_NAME
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(new SelectionAdapter() {"
, " @Override"
, " public void widgetDefaultSelected(SelectionEvent e) {"
, " System.out.println(\"Hello\");"
, " System.out.println(\"world\");"
, " }"
, " });"
, " }"
, "}"
));
ICleanUpFix cleanUp = LambdaConverterFix.createCleanUp(astRoot, true);
CompilationUnitChange compilationUnitChange = cleanUp.createChange(new NullProgressMonitor());
compilationUnitChange.perform(new NullProgressMonitor());
ICompilationUnit iCU = (ICompilationUnit) astRoot.getJavaElement().getAdapter(IOpenable.class);
String expected = String.join("\n"
, "package p"
, "import static org.eclipse.swt.events.SelectionListener.widgetDefaultSelectedAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(widgetDefaultSelectedAdapter(e -> {"
, " System.out.println(\"Hello\");"
, " System.out.println(\"world\");"
, " }));"
, " }"
, "}");
assertEquals(expected, iCU.getSource());
}
示例5: createChange_selectionAdapterImportStillNeededWidgetSelectedAdapter_selectionAdapterImportPreserved
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Test
public void createChange_selectionAdapterImportStillNeededWidgetSelectedAdapter_selectionAdapterImportPreserved() throws JavaModelException, CoreException, BadLocationException, IOException, URISyntaxException {
CompilationUnit astRoot = setupEnvironment(String.join("\n"
, "package " + PACKAGE_NAME
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " SelectionAdapter adapter = button.addSelectionListener(new SelectionAdapter() {"
, " @Override"
, " public void widgetSelected(SelectionEvent e) {"
, " System.out.println(\"Hello\");"
, " }"
, " });"
, " }"
, "}"
));
ICleanUpFix cleanUp = LambdaConverterFix.createCleanUp(astRoot, true);
CompilationUnitChange compilationUnitChange = cleanUp.createChange(new NullProgressMonitor());
compilationUnitChange.perform(new NullProgressMonitor());
ICompilationUnit iCU = (ICompilationUnit) astRoot.getJavaElement().getAdapter(IOpenable.class);
String expected = String.join("\n"
, "package " + PACKAGE_NAME
, "import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;"
, ""
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " SelectionAdapter adapter = button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println(\"Hello\")));"
, " }"
, "}");
assertEquals(expected, iCU.getSource());
}
示例6: createChange_selectionAdapterImportStillNeededBCofSuperClass_selectionAdapterImportPreserved
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Test
public void createChange_selectionAdapterImportStillNeededBCofSuperClass_selectionAdapterImportPreserved() throws JavaModelException, CoreException, BadLocationException, IOException, URISyntaxException {
CompilationUnit astRoot = setupEnvironment(String.join("\n"
, "package " + PACKAGE_NAME
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart extends SelectionAdapter {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(new SelectionAdapter() {"
, " @Override"
, " public void widgetSelected(SelectionEvent e) {"
, " System.out.println(\"Hello\");"
, " }"
, " });"
, " }"
, "}"
));
ICleanUpFix cleanUp = LambdaConverterFix.createCleanUp(astRoot, true);
CompilationUnitChange compilationUnitChange = cleanUp.createChange(new NullProgressMonitor());
compilationUnitChange.perform(new NullProgressMonitor());
ICompilationUnit iCU = (ICompilationUnit) astRoot.getJavaElement().getAdapter(IOpenable.class);
String expected = String.join("\n"
, "package " + PACKAGE_NAME
, "import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;"
, ""
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart extends SelectionAdapter {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println(\"Hello\")));"
, " }"
, "}");
assertEquals(expected, iCU.getSource());
}
示例7: createChange_selectionAdapterImportStillNeededBCofSuperInterface_selectionAdapterImportPreserved
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Test
public void createChange_selectionAdapterImportStillNeededBCofSuperInterface_selectionAdapterImportPreserved() throws JavaModelException, CoreException, BadLocationException, IOException, URISyntaxException {
CompilationUnit astRoot = setupEnvironment(String.join("\n"
, "package " + PACKAGE_NAME
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart implements SelectionAdapter {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(new SelectionAdapter() {"
, " @Override"
, " public void widgetSelected(SelectionEvent e) {"
, " System.out.println(\"Hello\");"
, " }"
, " });"
, " }"
, "}"
));
ICleanUpFix cleanUp = LambdaConverterFix.createCleanUp(astRoot, true);
CompilationUnitChange compilationUnitChange = cleanUp.createChange(new NullProgressMonitor());
compilationUnitChange.perform(new NullProgressMonitor());
ICompilationUnit iCU = (ICompilationUnit) astRoot.getJavaElement().getAdapter(IOpenable.class);
String expected = String.join("\n"
, "package " + PACKAGE_NAME
, "import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;"
, ""
, "import org.eclipse.swt.events.SelectionAdapter;"
, "public class SamplePart implements SelectionAdapter {"
, " @PostConstruct"
, " public void createComposite() {"
, " Button button = new Button(parent, SWT.PUSH);"
, " button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));"
, " button.setText(\"Text\");"
, " button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println(\"Hello\")));"
, " }"
, "}");
assertEquals(expected, iCU.getSource());
}