Java Code Examples for org.eclipse.ltk.core.refactoring.RefactoringStatus#addInfo()

The following examples show how to use org.eclipse.ltk.core.refactoring.RefactoringStatus#addInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError()) {
		return superStatus;
	}

	Object commonParent= getCommonParent();
	if (destination.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && destinationAsContainer.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IJavaElement destinationContainerAsPackage= getDestinationContainerAsJavaElement();
	if (destinationContainerAsPackage != null && destinationContainerAsPackage.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}

	if (cannotUpdateReferencesForDestination()) {
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);
	}

	return superStatus;
}
 
Example 2
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError())
		return superStatus;

	Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent();
	if (destination.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && (destinationAsContainer.equals(commonParent) || commonParent instanceof IPackageFragmentRoot
			&& destinationAsContainer.equals(((IPackageFragmentRoot) commonParent).getResource())))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IPackageFragment destinationAsPackage= getDestinationAsPackageFragment();
	if (destinationAsPackage != null && (destinationAsPackage.equals(commonParent)))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);

	if (cannotUpdateReferencesForDestination())
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);

	return superStatus;
}
 
Example 3
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError())
		return superStatus;

	Object commonParent= getCommonParent();
	if (destination.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && destinationAsContainer.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IJavaElement destinationContainerAsPackage= getDestinationContainerAsJavaElement();
	if (destinationContainerAsPackage != null && destinationContainerAsPackage.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	
	if (cannotUpdateReferencesForDestination())
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);

	return superStatus;
}
 
Example 4
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError()) {
		return superStatus;
	}

	Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent();
	if (destination.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && (destinationAsContainer.equals(commonParent) || commonParent instanceof IPackageFragmentRoot
			&& destinationAsContainer.equals(((IPackageFragmentRoot) commonParent).getResource()))) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IPackageFragment destinationAsPackage= getDestinationAsPackageFragment();
	if (destinationAsPackage != null && (destinationAsPackage.equals(commonParent))) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}

	if (cannotUpdateReferencesForDestination()) {
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);
	}

	return superStatus;
}
 
Example 5
Source File: ImportsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ICleanUpFix createCleanUp(final CompilationUnit cu, CodeGenerationSettings settings, boolean organizeImports, RefactoringStatus status) throws CoreException {
if (!organizeImports)
	return null;

final boolean hasAmbiguity[]= new boolean[] { false };
IChooseImportQuery query= new IChooseImportQuery() {
	public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
		hasAmbiguity[0]= true;
		return new TypeNameMatch[0];
	}
};

final ICompilationUnit unit= (ICompilationUnit)cu.getJavaElement();
OrganizeImportsOperation op= new OrganizeImportsOperation(unit, cu, settings.importIgnoreLowercase, false, false, query);
final TextEdit edit= op.createTextEdit(null);
if (hasAmbiguity[0]) {
	status.addInfo(Messages.format(ActionMessages.OrganizeImportsAction_multi_error_unresolvable, getLocationString(cu)));
}

if (op.getParseError() != null) {
	status.addInfo(Messages.format(ActionMessages.OrganizeImportsAction_multi_error_parse, getLocationString(cu)));
	return null;
}

if (edit == null || (edit instanceof MultiTextEdit && edit.getChildrenSize() == 0))
	return null;

return new ImportsFix(edit, unit, FixMessages.ImportsFix_OrganizeImports_Description);
  }
 
Example 6
Source File: NLSRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
	checkParameters();
	try {

		pm.beginTask(NLSMessages.NLSRefactoring_checking, 5);

		RefactoringStatus result= new RefactoringStatus();

		result.merge(checkIfAnythingToDo());
		if (result.hasFatalError()) {
			return result;
		}
		pm.worked(1);

		result.merge(validateModifiesFiles());
		if (result.hasFatalError()) {
			return result;
		}
		pm.worked(1);
		if (pm.isCanceled())
			throw new OperationCanceledException();

		result.merge(checkSubstitutionPattern());
		pm.worked(1);

		if (pm.isCanceled())
			throw new OperationCanceledException();


		result.merge(checkKeys());
		pm.worked(1);
		if (pm.isCanceled())
			throw new OperationCanceledException();

		if (!propertyFileExists() && willModifyPropertyFile()) {
			String msg= Messages.format(NLSMessages.NLSRefactoring_will_be_created, BasicElementLabels.getPathLabel(getPropertyFilePath(), false));
			result.addInfo(msg);
		}
		pm.worked(1);

		return result;
	} finally {
		pm.done();
	}
}