当前位置: 首页>>代码示例>>Java>>正文


Java Refactoring类代码示例

本文整理汇总了Java中org.eclipse.ltk.core.refactoring.Refactoring的典型用法代码示例。如果您正苦于以下问题:Java Refactoring类的具体用法?Java Refactoring怎么用?Java Refactoring使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Refactoring类属于org.eclipse.ltk.core.refactoring包,在下文中一共展示了Refactoring类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: activate

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
/**
 * @param refactoring
 * @param wizard
 * @param parent
 * @param dialogTitle
 * @param saveMode
 *            a save mode from {@link RefactoringSaveHelper}
 * @return <code>true</code> if the refactoring was executed,
 *         <code>false</code> otherwise
 * @throws JavaScriptModelException
 */
public boolean activate(Refactoring refactoring, RefactoringWizard wizard, Shell parent, String dialogTitle,
		int saveMode) {
	RefactoringSaveHelper saveHelper = new RefactoringSaveHelper(saveMode);
	if (!canActivate(saveHelper, parent))
		return false;

	try {
		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
		int result = op.run(parent, dialogTitle);
		fStatus = op.getInitialConditionCheckingStatus();
		if (result == IDialogConstants.CANCEL_ID
				|| result == RefactoringWizardOpenOperation.INITIAL_CONDITION_CHECKING_FAILED) {
			saveHelper.triggerIncrementalBuild();
			return false;
		} else {
			return true;
		}
	} catch (InterruptedException e) {
		return false; // User action got cancelled
	}
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:33,代码来源:RefactoringStarter.java

示例2: checkInitialConditions

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
/**
 * CHANGED to protected
 * CHANGED do not fork as we are keeping the resource lock.
 */
protected RefactoringStatus checkInitialConditions(Refactoring refactoring, Shell parent, String title,
		IRunnableContext context) throws InterruptedException {
	try {
		CheckConditionsOperation cco = new CheckConditionsOperation(refactoring,
				CheckConditionsOperation.INITIAL_CONDITONS);
		WorkbenchRunnableAdapter workbenchRunnableAdapter = new WorkbenchRunnableAdapter(cco, ResourcesPlugin
				.getWorkspace().getRoot());
		/* CHANGE: don't fork (or use busyCursorWhile) as this will cause a deadlock */
		if (context == null) {
			PlatformUI.getWorkbench().getProgressService().run(false, true, workbenchRunnableAdapter);
		} else if (context instanceof IProgressService) {
			((IProgressService) context).run(false, true, workbenchRunnableAdapter);
		} else {
			context.run(false, true, workbenchRunnableAdapter);
		}
		return cco.getStatus();
	} catch (InvocationTargetException e) {
		ExceptionHandler.handle(e, parent, title, RefactoringUIMessages.RefactoringUI_open_unexpected_exception);
		return RefactoringStatus
				.createFatalErrorStatus(RefactoringUIMessages.RefactoringUI_open_unexpected_exception);
	}
}
 
开发者ID:cplutte,项目名称:bts,代码行数:27,代码来源:RefactoringWizardOpenOperation_NonForking.java

示例3: createMoveRefactoringSession

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
/**
 * Create move refactoring session.
 *
 * @param javaElements the java elements
 * @return the ID of the refactoring session
 */
public String createMoveRefactoringSession(IJavaElement[] javaElements)
    throws JavaModelException, RefactoringException {
  IReorgPolicy.IMovePolicy policy =
      ReorgPolicyFactory.createMovePolicy(new IResource[0], javaElements);
  if (policy.canEnable()) {
    JavaMoveProcessor processor = new JavaMoveProcessor(policy);
    // TODO this may overwrite existing sources.
    processor.setReorgQueries(new NullReorgQueries());
    processor.setCreateTargetQueries(() -> null);
    Refactoring refactoring = new MoveRefactoring(processor);
    MoveRefactoringSession session = new MoveRefactoringSession(refactoring, processor);
    final String id = String.format("move-%s", sessionId.getAndIncrement());
    sessions.put(id, session);
    return id;
  } else {
    throw new RefactoringException("Can't create move refactoring session.");
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RefactoringManager.java

示例4: helper3

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
private void helper3(
    String oldName,
    String newName,
    boolean updateRef,
    boolean updateTextual,
    boolean updateSimilar,
    String nonJavaFiles)
    throws JavaModelException, CoreException, IOException, Exception {
  RefactoringDescriptor descriptor =
      initWithAllOptions(
          oldName,
          oldName,
          newName,
          updateRef,
          updateTextual,
          updateSimilar,
          nonJavaFiles,
          RenamingNameSuggestor.STRATEGY_EMBEDDED);
  Refactoring ref = createRefactoring(descriptor);
  RefactoringStatus status = performRefactoring(ref);
  Assert.assertNull("was supposed to pass", status);
  checkResultInClass(newName);
  checkMappedSimilarElementsExist(ref);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RenameTypeTest.java

示例5: helper3_inner

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
private void helper3_inner(
    String oldName,
    String oldInnerName,
    String newName,
    String innerNewName,
    boolean updateRef,
    boolean updateTextual,
    boolean updateSimilar,
    String nonJavaFiles)
    throws JavaModelException, CoreException, IOException, Exception {
  RefactoringDescriptor descriptor =
      initWithAllOptions(
          oldName,
          oldInnerName,
          innerNewName,
          updateRef,
          updateTextual,
          updateSimilar,
          nonJavaFiles,
          RenamingNameSuggestor.STRATEGY_EMBEDDED);
  Refactoring ref = createRefactoring(descriptor);
  Assert.assertNull("was supposed to pass", performRefactoring(ref));
  checkResultInClass(newName);
  checkMappedSimilarElementsExist(ref);
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:RenameTypeTest.java

示例6: testSimilarElements24

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
@Test
public void testSimilarElements24() throws Exception {
  // Test transplanter for ICompilationUnit and IFile

  ParticipantTesting.reset();
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
  IType someClass = getType(cu, "SomeClass");
  IJavaElement[] someClassMembers = someClass.getChildren();

  RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(someClass, "SomeNewClass");
  setTheOptions(descriptor, true, false, true, null, RenamingNameSuggestor.STRATEGY_EMBEDDED);
  Refactoring ref = createRefactoring(descriptor);
  RefactoringStatus status = performRefactoring(ref);
  Assert.assertNull("was supposed to pass", status);

  checkResultInClass("SomeNewClass");

  checkMappers(ref, someClass, "SomeNewClass.java", someClassMembers);
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:RenameTypeTest.java

示例7: test18

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
@Test
public void test18() throws Exception {
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  ICompilationUnit cuC = createCUfromTestFile(getPackageP(), "C");

  IType classB = getType(cu, "B");
  IMethod method = classB.getMethod("m", new String[] {"I"});

  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setJavaElement(method);
  descriptor.setNewName("kk");
  descriptor.setUpdateReferences(true);
  final RefactoringStatus status = new RefactoringStatus();
  final Refactoring refactoring = descriptor.createRefactoring(status);
  assertNotNull("Refactoring should not be null", refactoring);
  assertTrue("status should be ok", status.isOK());

  assertEquals("was supposed to pass", null, performRefactoring(refactoring));
  assertEqualLines(
      "invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
  assertEqualLines(
      "invalid renaming C", getFileContents(getOutputTestFileName("C")), cuC.getSource());
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:RenameVirtualMethodInClassTest.java

示例8: test40

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
@Test
public void test40() throws Exception { // test for bug 68592
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  IType localClass = cu.getType("A").getMethod("doit", new String[0]).getType("LocalClass", 1);
  IMethod method = localClass.getMethod("method", new String[] {"I"});

  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setJavaElement(method);
  descriptor.setNewName("method2");
  descriptor.setUpdateReferences(true);
  final RefactoringStatus status = new RefactoringStatus();
  final Refactoring refactoring = descriptor.createRefactoring(status);
  assertNotNull("Refactoring should not be null", refactoring);
  assertTrue("status should be ok", status.isOK());

  assertEquals("was supposed to pass", null, performRefactoring(refactoring));
  assertEqualLines(
      "invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:RenameVirtualMethodInClassTest.java

示例9: createRefactoring

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:JavaRefactoringDescriptor.java

示例10: createRefactoring

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
  IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
  IResource[] resources = new IResource[fResourcePaths.length];
  for (int i = 0; i < fResourcePaths.length; i++) {
    IResource resource = wsRoot.findMember(fResourcePaths[i]);
    if (resource == null || !resource.exists()) {
      status.addFatalError(
          Messages.format(
              RefactoringCoreMessages.DeleteResourcesDescriptor_error_delete_not_exists,
              BasicElementLabels.getPathLabel(fResourcePaths[i], false)));
      return null;
    }
    resources[i] = resource;
  }
  DeleteResourcesProcessor processor = new DeleteResourcesProcessor(resources, fDeleteContents);
  return new DeleteRefactoring(processor);
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:DeleteResourcesDescriptor.java

示例11: createChange

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
/**
 * Creates a {@link Change} from the given {@link Refactoring}.
 * 
 * @param errorLevel the error level for the condition checking which should
 *          cause the change creation to fail
 * 
 * @return a non-null {@link Change}
 * @throws RefactoringException if there was a problem creating the change
 */
public static Change createChange(IWorkspace workspace, IProgressMonitor pm,
    Refactoring refactoring, int errorLevel) throws RefactoringException {
  CreateChangeOperation createChangeOperation = ChangeUtilities.createCreateChangeOperation(
      refactoring, errorLevel);
  try {
    workspace.run(createChangeOperation, pm);

    RefactoringStatus status = createChangeOperation.getConditionCheckingStatus();
    if (status.getSeverity() >= errorLevel) {
      // Could not create the change, throw an exception with the failure
      // status message
      throw new RefactoringException(
          status.getMessageMatchingSeverity(status.getSeverity()));
    }
  } catch (CoreException e) {
    throw new RefactoringException(e);
  }

  return createChangeOperation.getChange();
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:30,代码来源:ChangeUtilities.java

示例12: createRefactoring

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
/**
 * Creates a refactoring (or returns a previously created refactoring).
 */
public Refactoring createRefactoring() throws RefactoringException {
  if (refactoring != null) {
    return refactoring;
  }

  RefactoringStatus status = new RefactoringStatus();
  D descriptor = createDescriptor();
  try {
    refactoring = descriptor.createRefactoring(status);
  } catch (CoreException e) {
    throw new RefactoringException(e);
  }
  if (refactoring == null) {
    throw new RefactoringException(
        String.format(
            "The refactoring descriptor (%s) was unable to create a refactoring.",
            descriptor.getClass().getSimpleName()));
  }
  if (status.hasError()) {
    throw new RefactoringException(
        status.getMessageMatchingSeverity(RefactoringStatus.ERROR));
  }

  return refactoring;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:29,代码来源:ChangeBuilder.java

示例13: helperPass

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
private void helperPass(ICompilationUnit cu, IMethod[] methods, boolean testCompilation)
		throws JavaModelException, CoreException, Exception, IOException {
	Refactoring refactoring = getRefactoring(methods);

	RefactoringStatus initialStatus = refactoring.checkInitialConditions(new NullProgressMonitor());
	getLogger().info("Initial status: " + initialStatus);

	RefactoringStatus finalStatus = refactoring.checkFinalConditions(new NullProgressMonitor());
	getLogger().info("Final status: " + finalStatus);

	assertTrue("Precondition was supposed to pass.", initialStatus.isOK() && finalStatus.isOK());
	performChange(refactoring, false);

	String outputTestFileName = getOutputTestFileName("A");
	String actual = cu.getSource();

	if (testCompilation)
		assertTrue("Actual output should compile.", compiles(actual));

	if (this.replaceExpectedWithActual)
		setFileContents(outputTestFileName, actual);

	String expected = getFileContents(outputTestFileName);
	assertEqualLines(expected, actual);
}
 
开发者ID:ponder-lab,项目名称:Common-Eclipse-Java-Refactoring-Framework,代码行数:26,代码来源:RefactoringTest.java

示例14: refactoringPerformed

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected RefactoringStatus refactoringPerformed(final Refactoring refactoring, final IProgressMonitor monitor) {
	try {
		monitor.beginTask("", 120); //$NON-NLS-1$
		final RefactoringStatus status= super.refactoringPerformed(refactoring, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
		if (!status.hasFatalError()) {
			if (fSourceFolder != null) {
				try {
					fSourceFolder.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
				} catch (CoreException exception) {
					JavaPlugin.log(exception);
				}
			}
		}
		return status;
	} finally {
		monitor.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:23,代码来源:BinaryRefactoringHistoryWizard.java

示例15: run

import org.eclipse.ltk.core.refactoring.Refactoring; //导入依赖的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());
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:20,代码来源:ReorgMoveStarter.java


注:本文中的org.eclipse.ltk.core.refactoring.Refactoring类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。