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

The following examples show how to use org.eclipse.ltk.core.refactoring.RefactoringStatus#createWarningStatus() . 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: RenameTypeProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private RefactoringStatus checkNewPathValidity() {
	IContainer c = fType.getCompilationUnit().getResource().getParent();

	String notRename = RefactoringCoreMessages.RenameTypeRefactoring_will_not_rename;
	IStatus status = c.getWorkspace().validateName(getNewElementName(), IResource.FILE);
	if (status.getSeverity() == IStatus.ERROR) {
		return RefactoringStatus.createWarningStatus(status.getMessage() + ". " + notRename); //$NON-NLS-1$
	}

	status = c.getWorkspace().validatePath(createNewPath(getNewElementName()), IResource.FILE);
	if (status.getSeverity() == IStatus.ERROR) {
		return RefactoringStatus.createWarningStatus(status.getMessage() + ". " + notRename); //$NON-NLS-1$
	}

	return new RefactoringStatus();
}
 
Example 2
Source File: IntroduceIndirectionRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkOverloading() {
	try {
		if (fIntermediaryType != null) {
			IMethod[] toCheck= fIntermediaryType.getMethods();
			for (int i= 0; i < toCheck.length; i++) {
				IMethod method= toCheck[i];
				if (method.getElementName().equals(fIntermediaryMethodName))
					return RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_duplicate_method_name_in_declaring_type_error,
							BasicElementLabels.getJavaElementName(fIntermediaryMethodName)));
			}
		}
	} catch (JavaModelException e) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_could_not_parse_declaring_type_error);
	}
	return new RefactoringStatus();
}
 
Example 3
Source File: Checks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a fatal error in case the name is empty. In all other cases, an
 * error based on the given status is returned.
 *
 * @param name a name
 * @param status a status
 * @return RefactoringStatus based on the given status or the name, if
 *         empty.
 */
public static RefactoringStatus checkName(String name, IStatus status) {
	RefactoringStatus result= new RefactoringStatus();
	if ("".equals(name)) //$NON-NLS-1$
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.Checks_Choose_name);

	if (status.isOK())
		return result;

	switch (status.getSeverity()){
		case IStatus.ERROR:
			return RefactoringStatus.createFatalErrorStatus(status.getMessage());
		case IStatus.WARNING:
			return RefactoringStatus.createWarningStatus(status.getMessage());
		case IStatus.INFO:
			return RefactoringStatus.createInfoStatus(status.getMessage());
		default: //no nothing
			return new RefactoringStatus();
	}
}
 
Example 4
Source File: RenameMethodProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public final RefactoringStatus checkNewElementName(String newName) {
	Assert.isNotNull(newName, "new name"); //$NON-NLS-1$

	RefactoringStatus status= Checks.checkName(newName, JavaConventionsUtil.validateMethodName(newName, fMethod));
	if (status.isOK() && !Checks.startsWithLowerCase(newName)) {
		status= RefactoringStatus.createWarningStatus(fIsComposite
				? Messages.format(RefactoringCoreMessages.Checks_method_names_lowercase2, new String[] { BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()})
				: RefactoringCoreMessages.Checks_method_names_lowercase);
	}

	if (Checks.isAlreadyNamed(fMethod, newName)) {
		status.addFatalError(fIsComposite
				? Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_same_name2, new String[] { BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel() } )
				: RefactoringCoreMessages.RenameMethodRefactoring_same_name,
				JavaStatusContext.create(fMethod));
	}
	return status;
}
 
Example 5
Source File: RenameMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public final RefactoringStatus checkNewElementName(String newName) {
	Assert.isNotNull(newName, "new name"); //$NON-NLS-1$

	RefactoringStatus status= Checks.checkName(newName, JavaConventionsUtil.validateMethodName(newName, fMethod));
	if (status.isOK() && !Checks.startsWithLowerCase(newName))
		status= RefactoringStatus.createWarningStatus(fIsComposite
				? Messages.format(RefactoringCoreMessages.Checks_method_names_lowercase2, new String[] { BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()})
				: RefactoringCoreMessages.Checks_method_names_lowercase);

	if (Checks.isAlreadyNamed(fMethod, newName))
		status.addFatalError(fIsComposite
				? Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_same_name2, new String[] { BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel() } )
				: RefactoringCoreMessages.RenameMethodRefactoring_same_name,
				JavaStatusContext.create(fMethod));
	return status;
}
 
Example 6
Source File: RenameTypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkNewPathValidity() {
	IContainer c= fType.getCompilationUnit().getResource().getParent();

	String notRename= RefactoringCoreMessages.RenameTypeRefactoring_will_not_rename;
	IStatus status= c.getWorkspace().validateName(getNewElementName(), IResource.FILE);
	if (status.getSeverity() == IStatus.ERROR)
		return RefactoringStatus.createWarningStatus(status.getMessage() + ". " + notRename); //$NON-NLS-1$

	status= c.getWorkspace().validatePath(createNewPath(getNewElementName()), IResource.FILE);
	if (status.getSeverity() == IStatus.ERROR)
		return RefactoringStatus.createWarningStatus(status.getMessage() + ". " + notRename); //$NON-NLS-1$

	return new RefactoringStatus();
}
 
Example 7
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getModifiersWithUpdatedVisibility(final IMember member, final int modifiers, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, final IProgressMonitor monitor, final boolean considerReferences, final RefactoringStatus status) throws JavaModelException {
	if (needsVisibilityAdjustment(member, considerReferences, monitor, status)) {
		final MemberVisibilityAdjustor.OutgoingMemberVisibilityAdjustment adjustment= new MemberVisibilityAdjustor.OutgoingMemberVisibilityAdjustment(member, Modifier.ModifierKeyword.PROTECTED_KEYWORD, RefactoringStatus.createWarningStatus(Messages.format(MemberVisibilityAdjustor.getMessage(member), new String[] { MemberVisibilityAdjustor.getLabel(member), MemberVisibilityAdjustor.getLabel(Modifier.ModifierKeyword.PROTECTED_KEYWORD)})));
		adjustment.setNeedsRewriting(false);
		adjustments.put(member, adjustment);
		return JdtFlags.clearAccessModifiers(modifiers) | Modifier.PROTECTED;
	}
	if (getDestinationType().isInterface()) {
		final int flags= JdtFlags.clearAccessModifiers(modifiers) | Modifier.PUBLIC;
		if (member instanceof IMethod)
			return JdtFlags.clearFlag(Modifier.STATIC, flags);
		return flags;
	}
	return modifiers;
}
 
Example 8
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkIfTypeDeclaredIn(final IType iType, final IType type) {
	final IType typeInType= type.getType(iType.getElementName());
	if (!typeInType.exists())
		return null;
	final String[] keys= { JavaElementLabels.getTextLabel(typeInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)};
	final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Type_declared_in_class, keys);
	final RefactoringStatusContext context= JavaStatusContext.create(typeInType);
	return RefactoringStatus.createWarningStatus(msg, context);
}
 
Example 9
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkIfMethodDeclaredIn(final IMethod iMethod, final IType type) throws JavaModelException {
	final IMethod methodInType= JavaModelUtil.findMethod(iMethod.getElementName(), iMethod.getParameterTypes(), iMethod.isConstructor(), type);
	if (methodInType == null || !methodInType.exists())
		return null;
	final String[] keys= { JavaElementLabels.getTextLabel(methodInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)};
	final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Method_declared_in_class, keys);
	final RefactoringStatusContext context= JavaStatusContext.create(methodInType);
	return RefactoringStatus.createWarningStatus(msg, context);
}
 
Example 10
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkIfFieldDeclaredIn(final IField iField, final IType type) {
	final IField fieldInType= type.getField(iField.getElementName());
	if (!fieldInType.exists())
		return null;
	final String[] keys= { JavaElementLabels.getTextLabel(fieldInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)};
	final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Field_declared_in_class, keys);
	final RefactoringStatusContext context= JavaStatusContext.create(fieldInType);
	return RefactoringStatus.createWarningStatus(msg, context);
}
 
Example 11
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkVisibilityChanges() throws JavaModelException {
	if (isVisibilitySameAsInitial())
		return null;
    if (fRippleMethods.length == 1)
    	return null;
    Assert.isTrue(JdtFlags.getVisibilityCode(fMethod) != Modifier.PRIVATE);
    if (fVisibility == Modifier.PRIVATE)
    	return RefactoringStatus.createWarningStatus(RefactoringCoreMessages.ChangeSignatureRefactoring_non_virtual);
	return null;
}
 
Example 12
Source File: IntroduceIndirectionRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private RefactoringStatus createWarningAboutCall(IMember enclosing, ASTNode concreteNode, String message) {
	String name= JavaElementLabels.getElementLabel(enclosing, JavaElementLabels.ALL_DEFAULT);
	String container= JavaElementLabels.getElementLabel(enclosing.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED);
	return RefactoringStatus.createWarningStatus(Messages.format(message, new String[] { name, container }), JavaStatusContext.create(enclosing.getCompilationUnit(), concreteNode));
}
 
Example 13
Source File: Checks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Checks if method will have a constructor name after renaming.
 * @param method
 * @param newMethodName
 * @param newTypeName
 * @return <code>RefactoringStatus</code> with <code>WARNING</code> severity if
 * the give method will have a constructor name after renaming
 * <code>null</code> otherwise.
 */
public static RefactoringStatus checkIfConstructorName(IMethod method, String newMethodName, String newTypeName){
	if (! newMethodName.equals(newTypeName))
		return null;
	else
		return RefactoringStatus.createWarningStatus(
			Messages.format(RefactoringCoreMessages.Checks_constructor_name,
			new Object[] {JavaElementUtil.createMethodSignature(method), JavaElementLabels.getElementLabel(method.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED) } ));
}
 
Example 14
Source File: Checks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Checks if the given name is a valid Java method name.
 *
 * @param name the java method name.
 * @param context an {@link IJavaElement} or <code>null</code>
 * @return a refactoring status containing the error message if the
 *  name is not a valid java method name.
 */
public static RefactoringStatus checkMethodName(String name, IJavaElement context) {
	RefactoringStatus status= checkName(name, JavaConventionsUtil.validateMethodName(name, context));
	if (status.isOK() && !startsWithLowerCase(name))
		return RefactoringStatus.createWarningStatus(RefactoringCoreMessages.Checks_method_names_lowercase);
	else
		return status;
}
 
Example 15
Source File: JavaRefactoringDescriptorUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates a warning status telling that the input element does not exist.
 *
 * @param element
 *            the input element, or <code>null</code>
 * @param name
 *            the name of the refactoring
 * @param id
 *            the id of the refactoring
 * @return the refactoring status
 */
public static RefactoringStatus createInputWarningStatus(final Object element, final String name, final String id) {
	Assert.isNotNull(name);
	Assert.isNotNull(id);
	if (element != null)
		return RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_input_not_exists, new String[] { JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED), name, id}));
	else
		return RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist, new String[] { name, id}));
}
 
Example 16
Source File: ArtifactProjectRenameRefactorParticipant.java    From developer-studio with Apache License 2.0 3 votes vote down vote up
/**
 * This method is used to check the pre-conditions for the refactoring.
 * This method can be used to communicate with user about refactoring about
 * to happen such as
 * if there is an fatal issue related to refactoring, you can create a
 * Status with Fatal error, or
 * you can create a warning status where user can be informed.
 */
@Override
public RefactoringStatus checkConditions(IProgressMonitor arg0, CheckConditionsContext arg1)
                                                                                            throws OperationCanceledException {
	return RefactoringStatus.createWarningStatus("You are about to rename your project and configuration from " +
	                                             originalProject.getName() + " to " + latestName);
}
 
Example 17
Source File: ArtifactProjectDeleteParticipant.java    From developer-studio with Apache License 2.0 2 votes vote down vote up
/**
 * This method is used to check the pre-conditions for the refactoring. This
 * method can be used to communicate with user about refactoring about to
 * happen such as if there is an fatal issue related to refactoring, you can
 * create a Status with Fatal error, or you can create a warning status
 * where user can be informed.
 */
@Override
public RefactoringStatus checkConditions(IProgressMonitor arg0, CheckConditionsContext arg1)
                                                                                            throws OperationCanceledException {
	return RefactoringStatus.createWarningStatus("You are about to delete your Artifact project");
}