本文整理汇总了Java中org.eclipse.ltk.core.refactoring.RefactoringCore类的典型用法代码示例。如果您正苦于以下问题:Java RefactoringCore类的具体用法?Java RefactoringCore怎么用?Java RefactoringCore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RefactoringCore类属于org.eclipse.ltk.core.refactoring包,在下文中一共展示了RefactoringCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perform
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
/**
* Executes the rename refactoring without showing a dialog to gather additional user input (for
* example the new name of the <tt>IJavaElement</tt>). Only an error dialog is shown (if
* necessary) to present the result of the refactoring's full precondition checking.
*
* <p>The method has to be called from within the UI thread.
*
* @throws InterruptedException if the operation has been canceled by the user.
* @throws InvocationTargetException if an error occurred while executing the operation.
*/
public RefactoringStatus perform() throws InterruptedException, InvocationTargetException {
try {
ensureChecked();
if (fPreCheckStatus.hasFatalError()) {
return fPreCheckStatus;
}
RefactoringExecutionHelper helper =
new RefactoringExecutionHelper(
fRefactoring,
RefactoringCore.getConditionCheckingFailedSeverity(),
getJavaRenameProcessor().getSaveMode());
RefactoringStatus status = helper.perform(true, true);
fPerformChangeOperation = helper.getfPerformChangeOperation();
return status;
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
示例2: createRefactoring
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
/** {@inheritDoc} */
public Refactoring createRefactoring(final RefactoringStatus status) throws CoreException {
Refactoring refactoring = null;
final String id = getID();
final RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(id);
if (contribution != null) {
if (contribution instanceof JavaRefactoringContribution) {
JavaRefactoringContribution javaContribution = (JavaRefactoringContribution) contribution;
refactoring = javaContribution.createRefactoring(this, status);
} else
JavaPlugin.log(
new Status(
IStatus.ERROR,
JavaPlugin.getPluginId(),
0,
MessageFormat.format(
DescriptorMessages.JavaRefactoringDescriptor_no_resulting_descriptor,
new Object[] {id}),
null));
}
return refactoring;
}
示例3: createDescriptor
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
/**
* Creates a {@link RefactoringDescriptor} from a
* {@link RefactoringContribution} of the given ID.
*
* @return a non-null {@link RefactoringDescriptor}
* @throws RefactoringException if there was a problem creating the descriptor
*/
public static RefactoringDescriptor createDescriptor(String contributionId)
throws RefactoringException {
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(contributionId);
if (contribution == null) {
throw new RefactoringException(
String.format("The refactoring contribution (%s) is not available.",
contributionId));
}
RefactoringDescriptor refactoringDescriptor = contribution.createDescriptor();
if (refactoringDescriptor == null) {
throw new RefactoringException(
String.format(
"A descriptor could not be created from the refactoring contribution (%s).",
contribution.getClass().getSimpleName()));
}
return refactoringDescriptor;
}
示例4: getRefactoringDescriptor
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
private IntroduceParameterDescriptor getRefactoringDescriptor() {
ChangeMethodSignatureDescriptor extended= (ChangeMethodSignatureDescriptor) fChangeSignatureProcessor.createDescriptor();
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(IJavaRefactorings.CHANGE_METHOD_SIGNATURE);
Map<String, String> argumentsMap= contribution.retrieveArgumentMap(extended);
final Map<String, String> arguments= new HashMap<String, String>();
arguments.put(ATTRIBUTE_ARGUMENT, fParameter.getNewName());
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$
arguments.putAll(argumentsMap);
String signature= fChangeSignatureProcessor.getMethodName();
try {
signature= fChangeSignatureProcessor.getOldMethodSignature();
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description= Messages.format(RefactoringCoreMessages.IntroduceParameterRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fChangeSignatureProcessor.getMethod().getElementName()));
final String header= Messages.format(RefactoringCoreMessages.IntroduceParameterRefactoring_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fParameter.getNewName()), signature, BasicElementLabels.getJavaCodeString(ASTNodes.asString(fSelectedExpression))});
final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(extended.getProject(), this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceParameterRefactoring_original_pattern, JavaElementLabels.getTextLabel(fChangeSignatureProcessor.getMethod(),
JavaElementLabels.ALL_FULLY_QUALIFIED)));
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceParameterRefactoring_expression_pattern, BasicElementLabels.getJavaCodeString(ASTNodes.asString(fSelectedExpression))));
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceParameterRefactoring_parameter_pattern, BasicElementLabels.getJavaElementName(getAddedParameterInfo().getNewName())));
return RefactoringSignatureDescriptorFactory.createIntroduceParameterDescriptor(extended.getProject(), description, comment.asString(), arguments, extended.getFlags());
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:IntroduceParameterRefactoring.java
示例5: run
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
public boolean run(Shell parent) throws InterruptedException, InvocationTargetException {
Refactoring ref= new MoveRefactoring(fMoveProcessor);
if (fMoveProcessor.hasAllInputSet()) {
IRunnableContext context= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
fMoveProcessor.setCreateTargetQueries(new CreateTargetQueries(parent));
fMoveProcessor.setReorgQueries(new ReorgQueries(parent));
new RefactoringExecutionHelper(ref, RefactoringCore.getConditionCheckingFailedSeverity(), fMoveProcessor.getSaveMode(), parent, context).perform(false, false);
return true;
} else {
RefactoringWizard wizard= new ReorgMoveWizard(fMoveProcessor, ref);
/*
* We want to get the shell from the refactoring dialog but it's not known at this point,
* so we pass the wizard and then, once the dialog is open, we will have access to its shell.
*/
fMoveProcessor.setCreateTargetQueries(new CreateTargetQueries(wizard));
fMoveProcessor.setReorgQueries(new ReorgQueries(wizard));
return new RefactoringStarter().activate(wizard, parent, RefactoringMessages.OpenRefactoringWizardAction_refactoring, fMoveProcessor.getSaveMode());
}
}
示例6: perform
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
/**
* Executes the rename refactoring without showing a dialog to gather
* additional user input (for example the new name of the <tt>IJavaElement</tt>).
* Only an error dialog is shown (if necessary) to present the result
* of the refactoring's full precondition checking.
* <p>
* The method has to be called from within the UI thread.
* </p>
*
* @param parent a shell used as a parent for the error dialog.
* @param context a {@link IRunnableContext} to execute the operation.
*
* @throws InterruptedException if the operation has been canceled by the
* user.
* @throws InvocationTargetException if an error occurred while executing the
* operation.
*
* @see #openDialog(Shell)
* @see IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
*/
public void perform(Shell parent, IRunnableContext context) throws InterruptedException, InvocationTargetException {
try {
ensureChecked();
if (fPreCheckStatus.hasFatalError()) {
showInformation(parent, fPreCheckStatus);
return;
}
RenameSelectionState state= createSelectionState();
RefactoringExecutionHelper helper= new RefactoringExecutionHelper(fRefactoring,
RefactoringCore.getConditionCheckingFailedSeverity(),
getJavaRenameProcessor().getSaveMode(),
parent,
context);
helper.perform(true, true);
restoreSelectionState(state);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
示例7: renameVariable
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
public static void renameVariable(String task, IJavaElement element, String new_name) {
RefactoringStatus status = new RefactoringStatus();
RefactoringContribution contrib = RefactoringCore
.getRefactoringContribution(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
RenameJavaElementDescriptor rnDesc = (RenameJavaElementDescriptor) contrib.createDescriptor();
rnDesc.setFlags(JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING);
rnDesc.setProject(element.getJavaProject().getProject().getName());
rnDesc.setUpdateReferences(true);
rnDesc.setJavaElement(element);
rnDesc.setNewName(new_name);
Refactoring ref;
try {
ref = rnDesc.createRefactoring(status);
ref.checkInitialConditions(NULL_MON);
ref.checkFinalConditions(NULL_MON);
Change change = ref.createChange(NULL_MON);
change.perform(NULL_MON);
} catch (CoreException e) {
e.printStackTrace();
}
}
示例8: executionNotification
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
@Override
public void executionNotification(RefactoringExecutionEvent event) {
refactoringName = getRefactoringID(event);
int refactoringEventType = event.getEventType();
RefactoringDescriptor refactoringDescriptor = getRefactoringDescriptorFromEvent(event);
RefactoringContribution refactoringContribution = RefactoringCore.getRefactoringContribution(refactoringName);
Map argumentMap = refactoringContribution.retrieveArgumentMap(refactoringDescriptor);
if (refactoringEventType == RefactoringExecutionEvent.ABOUT_TO_PERFORM || refactoringEventType == RefactoringExecutionEvent.ABOUT_TO_REDO) {
isRefactoringInProgress = true;
clientRecorder.recordRefactoring(refactoringName, argumentMap);
}
if (refactoringEventType == RefactoringExecutionEvent.ABOUT_TO_UNDO) {
isRefactoringInProgress = true;
clientRecorder.recordRefactoringUndo(refactoringName, argumentMap);
}
if (refactoringEventType == RefactoringExecutionEvent.PERFORMED || refactoringEventType == RefactoringExecutionEvent.REDONE || refactoringEventType == RefactoringExecutionEvent.UNDONE) {
isRefactoringInProgress = false;
clientRecorder.recordRefactoringEnd(refactoringName, argumentMap);
refactoringName = "";
}
}
开发者ID:ChangeOrientedProgrammingEnvironment,项目名称:eclipseRecorder,代码行数:25,代码来源:RefactoringExecutionListener.java
示例9: register
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
/**
* Registers a refactoring execution manager with the refactoring history service.
* @param rm the refactoring execution manager
*/
public static void register(RefactoringExecutionManager rm) {
IRefactoringHistoryService rs = RefactoringCore.getHistoryService();
if (rs != null) {
rs.addExecutionListener(rm);
// rs.addHistoryListener(rm);
}
}
示例10: unregister
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
/**
* Unregisters a refactoring execution manager with the refactoring history service.
* @param rm the refactoring execution manager
*/
public static void unregister(RefactoringExecutionManager rm) {
IRefactoringHistoryService rs = RefactoringCore.getHistoryService();
if (rs != null) {
rs.removeExecutionListener(rm);
// rs.removeHistoryListener(rm);
}
}
示例11: performChange
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
/**
* Performs the change associated with this proposal.
* <p>
* Subclasses may extend, but must call the super implementation.
*
* @throws CoreException
* when the invocation of the change failed
*/
protected void performChange() throws CoreException {
Change change= null;
try {
change= getChange();
if (change != null) {
change.initializeValidationData(new NullProgressMonitor());
RefactoringStatus valid= change.isValid(new NullProgressMonitor());
if (valid.hasFatalError()) {
IStatus status = new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, IStatus.ERROR,
valid.getMessageMatchingSeverity(RefactoringStatus.FATAL), null);
throw new CoreException(status);
} else {
IUndoManager manager= RefactoringCore.getUndoManager();
Change undoChange;
boolean successful= false;
try {
manager.aboutToPerformChange(change);
undoChange= change.perform(new NullProgressMonitor());
successful= true;
} finally {
manager.changePerformed(change, successful);
}
if (undoChange != null) {
undoChange.initializeValidationData(new NullProgressMonitor());
manager.addUndo(getName(), undoChange);
}
}
}
} finally {
if (change != null) {
change.dispose();
}
}
}
示例12: run
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
@Override
public void run(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask("", fForked && !fForkChangeExecution ? 7 : 11); //$NON-NLS-1$
pm.subTask(""); //$NON-NLS-1$
final RefactoringStatus status= fRefactoring.checkAllConditions(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
if (status.getSeverity() >= fStopSeverity) {
final boolean[] canceled= { false };
if (fForked) {
fParent.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
canceled[0]= showStatusDialog(status);
}
});
} else {
canceled[0]= showStatusDialog(status);
}
if (canceled[0]) {
throw new OperationCanceledException();
}
}
fChange= fRefactoring.createChange(new SubProgressMonitor(pm, 2, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
fChange.initializeValidationData(new SubProgressMonitor(pm, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
fPerformChangeOperation= new PerformChangeOperation(fChange);//RefactoringUI.createUIAwareChangeOperation(fChange);
fPerformChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), fRefactoring.getName());
if (fRefactoring instanceof IScheduledRefactoring)
fPerformChangeOperation.setSchedulingRule(((IScheduledRefactoring)fRefactoring).getSchedulingRule());
if (!fForked || fForkChangeExecution)
fPerformChangeOperation.run(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
} finally {
pm.done();
}
}
示例13: run
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
public void run(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask("", 11);
pm.subTask("");
final RefactoringStatus status = refactoring.checkAllConditions(new SubProgressMonitor(pm, 4,
SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
if (status.getSeverity() >= RefactoringStatus.WARNING) {
final boolean[] canceled = { false };
shell.getDisplay().syncExec(new Runnable() {
public void run() {
canceled[0] = showStatusDialog(status);
}
});
if (canceled[0]) {
throw new OperationCanceledException();
}
}
Change change = refactoring.createChange(new SubProgressMonitor(pm, 2,
SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
change.initializeValidationData(new SubProgressMonitor(pm, 1,
SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
performChangeOperation = new PerformChangeOperation(change);
performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName());
performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot());
} finally {
pm.done();
}
}
示例14: internalPerformFinish
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
private FinishResult internalPerformFinish(PerformChangeOperation op) {
op.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName());
try {
ResourcesPlugin.getWorkspace().run(op, new NullProgressMonitor());
} catch (CoreException e) {
JavaPlugin.log(e);
return FinishResult.createException();
}
return FinishResult.createOK();
}
示例15: helper2_0
import org.eclipse.ltk.core.refactoring.RefactoringCore; //导入依赖的package包/类
private void helper2_0(
String methodName,
String newMethodName,
String[] signatures,
boolean updateReferences,
boolean createDelegate)
throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType classA = getType(cu, "A");
IMethod method = classA.getMethod(methodName, signatures);
RenameJavaElementDescriptor descriptor =
RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
IJavaRefactorings.RENAME_METHOD);
descriptor.setUpdateReferences(updateReferences);
descriptor.setJavaElement(method);
descriptor.setNewName(newMethodName);
descriptor.setKeepOriginal(createDelegate);
descriptor.setDeprecateDelegate(true);
assertEquals("was supposed to pass", null, performRefactoring(descriptor));
assertEqualLines(
"invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
// assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
// assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}