Java Code Examples for org.eclipse.ltk.core.refactoring.RefactoringStatus#addWarning()
The following examples show how to use
org.eclipse.ltk.core.refactoring.RefactoringStatus#addWarning() .
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: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Checks if the new method is already used in the given type. * @param type * @param methodName * @param parameters * @return the status */ public static RefactoringStatus checkMethodInType(ITypeBinding type, String methodName, ITypeBinding[] parameters) { RefactoringStatus result= new RefactoringStatus(); IMethodBinding method= org.eclipse.jdt.internal.corext.dom.Bindings.findMethodInType(type, methodName, parameters); if (method != null) { if (method.isConstructor()) { result.addWarning(Messages.format(RefactoringCoreMessages.Checks_methodName_constructor, new Object[] { BasicElementLabels.getJavaElementName(type.getName()) })); } else { result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_exists, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(type.getName()) }), JavaStatusContext.create(method)); } } return result; }
Example 2
Source File: RenameFieldProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private RefactoringStatus checkNestedHierarchy(IType type) throws CoreException { IType[] nestedTypes= type.getTypes(); if (nestedTypes == null) { return null; } RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < nestedTypes.length; i++){ IField otherField= nestedTypes[i].getField(getNewElementName()); if (otherField.exists()){ String msg= Messages.format( RefactoringCoreMessages.RenameFieldRefactoring_hiding, new String[]{ BasicElementLabels.getJavaElementName(fField.getElementName()), BasicElementLabels.getJavaElementName(getNewElementName()), BasicElementLabels.getJavaElementName(nestedTypes[i].getFullyQualifiedName('.'))}); result.addWarning(msg, JavaStatusContext.create(otherField)); } result.merge(checkNestedHierarchy(nestedTypes[i])); } return result; }
Example 3
Source File: JavaDeleteProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void checkDirtyFile(RefactoringStatus result, IFile file) { if (file == null || !file.exists()) return; ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE); if (buffer != null && buffer.isDirty()) { if (buffer.isStateValidated() && buffer.isSynchronized()) { result.addWarning(Messages.format( RefactoringCoreMessages.JavaDeleteProcessor_unsaved_changes, BasicElementLabels.getPathLabel(file.getFullPath(), false))); } else { result.addFatalError(Messages.format( RefactoringCoreMessages.JavaDeleteProcessor_unsaved_changes, BasicElementLabels.getPathLabel(file.getFullPath(), false))); } } }
Example 4
Source File: MoveStaticMembersProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private RefactoringStatus checkNativeMovedMethods(IProgressMonitor pm) throws JavaModelException{ pm.beginTask(RefactoringCoreMessages.MoveMembersRefactoring_checking, fMembersToMove.length); RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < fMembersToMove.length; i++) { if (fMembersToMove[i].getElementType() != IJavaElement.METHOD) continue; if (! JdtFlags.isNative(fMembersToMove[i])) continue; String message= Messages.format(RefactoringCoreMessages.MoveMembersRefactoring_native, JavaElementUtil.createMethodSignature((IMethod)fMembersToMove[i])); result.addWarning(message, JavaStatusContext.create(fMembersToMove[i])); pm.worked(1); } pm.done(); return result; }
Example 5
Source File: MoveStaticMembersProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private RefactoringStatus checkMoveToInterface() throws JavaModelException { //could be more clever and make field final if it is only written once... boolean is18OrHigher= JavaModelUtil.is18OrHigher(fDestinationType.getJavaProject()); RefactoringStatus result= new RefactoringStatus(); boolean declaringIsInterface= getDeclaringType().isInterface(); if (declaringIsInterface && is18OrHigher) return result; String moveMembersMsg= is18OrHigher ? RefactoringCoreMessages.MoveMembersRefactoring_only_public_static_18 : RefactoringCoreMessages.MoveMembersRefactoring_only_public_static; for (int i= 0; i < fMembersToMove.length; i++) { if (declaringIsInterface && !(fMembersToMove[i] instanceof IMethod) && !is18OrHigher) { // moving from interface to interface is OK, unless method is moved to pre-18 } else if (!canMoveToInterface(fMembersToMove[i], is18OrHigher)) { result.addError(moveMembersMsg, JavaStatusContext.create(fMembersToMove[i])); } else if (!Flags.isPublic(fMembersToMove[i].getFlags()) && !declaringIsInterface) { result.addWarning(RefactoringCoreMessages.MoveMembersRefactoring_member_will_be_public, JavaStatusContext.create(fMembersToMove[i])); } } return result; }
Example 6
Source File: RenameFieldProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public RefactoringStatus checkNewElementName(String newName) throws CoreException { Assert.isNotNull(newName, "new name"); //$NON-NLS-1$ RefactoringStatus result= Checks.checkFieldName(newName, fField); if (isInstanceField(fField) && (!Checks.startsWithLowerCase(newName))) result.addWarning(fIsComposite ? Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_should_start_lowercase2, new String[] { BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel() }) : RefactoringCoreMessages.RenameFieldRefactoring_should_start_lowercase); if (Checks.isAlreadyNamed(fField, newName)) result.addError(fIsComposite ? Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_another_name2, new String[] { BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel() }) : RefactoringCoreMessages.RenameFieldRefactoring_another_name, JavaStatusContext.create(fField)); if (fField.getDeclaringType().getField(newName).exists()) result.addError(fIsComposite ? Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_field_already_defined2, new String[] { BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel() }) : RefactoringCoreMessages.RenameFieldRefactoring_field_already_defined, JavaStatusContext.create(fField.getDeclaringType().getField(newName))); return result; }
Example 7
Source File: ExtractClassRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Expression getAssignedValue(ParameterObjectFactory pof, String parameterName, IJavaProject javaProject, RefactoringStatus status, ASTRewrite rewrite, ParameterInfo pi, boolean useSuper, ITypeBinding typeBinding, Expression qualifier, ASTNode replaceNode, ITypeRoot typeRoot) { AST ast= rewrite.getAST(); boolean is50OrHigher= JavaModelUtil.is50OrHigher(javaProject); Expression assignedValue= handleSimpleNameAssignment(replaceNode, pof, parameterName, ast, javaProject, useSuper); if (assignedValue == null) { NullLiteral marker= qualifier == null ? null : ast.newNullLiteral(); Expression fieldReadAccess= pof.createFieldReadAccess(pi, parameterName, ast, javaProject, useSuper, marker); assignedValue= GetterSetterUtil.getAssignedValue(replaceNode, rewrite, fieldReadAccess, typeBinding, is50OrHigher); boolean markerReplaced= replaceMarker(rewrite, qualifier, assignedValue, marker); if (markerReplaced) { switch (qualifier.getNodeType()) { case ASTNode.METHOD_INVOCATION: case ASTNode.CLASS_INSTANCE_CREATION: case ASTNode.SUPER_METHOD_INVOCATION: case ASTNode.PARENTHESIZED_EXPRESSION: status.addWarning(RefactoringCoreMessages.ExtractClassRefactoring_warning_semantic_change, JavaStatusContext.create(typeRoot, replaceNode)); break; } } } return assignedValue; }
Example 8
Source File: RenameFieldProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private RefactoringStatus checkEnclosingHierarchy() { IType current= fField.getDeclaringType(); if (Checks.isTopLevel(current)) return null; RefactoringStatus result= new RefactoringStatus(); while (current != null){ IField otherField= current.getField(getNewElementName()); if (otherField.exists()){ String msg= Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_hiding2, new String[]{ BasicElementLabels.getJavaElementName(getNewElementName()), BasicElementLabels.getJavaElementName(current.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(otherField.getElementName())}); result.addWarning(msg, JavaStatusContext.create(otherField)); } current= current.getDeclaringType(); } return result; }
Example 9
Source File: RenameLocalVariableProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RefactoringStatus checkNewElementName(String newName) throws JavaModelException { RefactoringStatus result= Checks.checkFieldName(newName, fCu); if (! Checks.startsWithLowerCase(newName)) if (fIsComposite) { final String nameOfParent= JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_DEFAULT); final String nameOfType= JavaElementLabels.getElementLabel(fLocalVariable.getAncestor(IJavaElement.TYPE), JavaElementLabels.ALL_DEFAULT); result.addWarning(Messages.format(RefactoringCoreMessages.RenameTempRefactoring_lowercase2, new String[] { BasicElementLabels.getJavaElementName(newName), nameOfParent, nameOfType })); } else { result.addWarning(RefactoringCoreMessages.RenameTempRefactoring_lowercase); } return result; }
Example 10
Source File: RenameLocalVariableProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkNewElementName(String newName) throws JavaModelException { RefactoringStatus result= Checks.checkFieldName(newName, fCu); if (! Checks.startsWithLowerCase(newName)) { if (fIsComposite) { final String nameOfParent= JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_DEFAULT); final String nameOfType= JavaElementLabels.getElementLabel(fLocalVariable.getAncestor(IJavaElement.TYPE), JavaElementLabels.ALL_DEFAULT); result.addWarning(Messages.format(RefactoringCoreMessages.RenameTempRefactoring_lowercase2, new String[] { BasicElementLabels.getJavaElementName(newName), nameOfParent, nameOfType })); } else { result.addWarning(RefactoringCoreMessages.RenameTempRefactoring_lowercase); } } return result; }
Example 11
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkCompileErrors(RefactoringStatus result, CompilationUnit root, ICompilationUnit element) { IProblem[] messages= root.getProblems(); for (int i= 0; i < messages.length; i++) { IProblem problem= messages[i]; if (!isIgnorableProblem(problem)) { result.addWarning(Messages.format( RefactoringCoreMessages.SelfEncapsulateField_compiler_errors_update, BasicElementLabels.getFileName(element)), JavaStatusContext.create(element)); return; } } }
Example 12
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RefactoringStatus checkEnclosingInstanceName(String name) { if (!fCreateInstanceField) return new RefactoringStatus(); RefactoringStatus result= Checks.checkFieldName(name, fType); if (!Checks.startsWithLowerCase(name)) result.addWarning(RefactoringCoreMessages.MoveInnerToTopRefactoring_names_start_lowercase); if (fType.getField(name).exists()) { Object[] keys= new String[] { BasicElementLabels.getJavaElementName(name), BasicElementLabels.getJavaElementName(fType.getElementName())}; String msg= Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_already_declared, keys); result.addError(msg, JavaStatusContext.create(fType.getField(name))); } return result; }
Example 13
Source File: XtendRenameElementProcessor.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { RefactoringStatus status = super.checkInitialConditions(pm); if(hasUnsavedEditors()) { status.addWarning("Unsaved changes in Xtend editors could collide with this refactoring."); } return status; }
Example 14
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static RefactoringStatus checkConstantName(String newName, IJavaElement context) { RefactoringStatus result= Checks.checkFieldName(newName, context); if (result.hasFatalError()) return result; for (int i= 0; i < newName.length(); i++) { char c= newName.charAt(i); if (Character.isLetter(c) && !Character.isUpperCase(c)) { result.addWarning(RefactoringCoreMessages.ExtractConstantRefactoring_convention); break; } } return result; }
Example 15
Source File: ExternalizeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkMissingKeys(RefactoringStatus status) { for (int i= 0; i < fSubstitutions.length; i++) { NLSSubstitution substitution= fSubstitutions[i]; if ((substitution.getValue() == null) && (substitution.getKey() != null)) { status.addWarning(NLSUIMessages.ExternalizeWizardPage_warning_keymissing); return; } } }
Example 16
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static void checkName(RefactoringStatus status, String name, List<IMethodBinding> usedNames, IType type, boolean reUseExistingField, IField field) { if ("".equals(name)) { //$NON-NLS-1$ status.addFatalError(RefactoringCoreMessages.Checks_Choose_name); return; } boolean isStatic=false; try { isStatic= Flags.isStatic(field.getFlags()); } catch (JavaModelException e) { JavaPlugin.log(e); } status.merge(Checks.checkMethodName(name, field)); for (Iterator<IMethodBinding> iter= usedNames.iterator(); iter.hasNext(); ) { IMethodBinding method= iter.next(); String selector= method.getName(); if (selector.equals(name)) { if (!reUseExistingField) { status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_method_exists, new String[] { BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(type.getElementName()) })); } else { boolean methodIsStatic= Modifier.isStatic(method.getModifiers()); if (methodIsStatic && !isStatic) status.addWarning(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_static_method_but_nonstatic_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) })); if (!methodIsStatic && isStatic) status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_nonstatic_method_but_static_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) })); return; } } } if (reUseExistingField) status.addFatalError(Messages.format( RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_methoddoesnotexist_status_fatalError, new String[] { BasicElementLabels.getJavaElementName(name), BasicElementLabels.getJavaElementName(type.getElementName())})); }
Example 17
Source File: ExtractTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkMatchingFragments() throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); IASTFragment[] matchingFragments= getMatchingFragments(); for (int i= 0; i < matchingFragments.length; i++) { ASTNode node= matchingFragments[i].getAssociatedNode(); if (isLeftValue(node) && !isReferringToLocalVariableFromFor((Expression) node)) { String msg= RefactoringCoreMessages.ExtractTempRefactoring_assigned_to; result.addWarning(msg, JavaStatusContext.create(fCu, node)); } } return result; }
Example 18
Source File: RenameTypeParameterProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkNewElementName(String name) throws CoreException { Assert.isNotNull(name); RefactoringStatus result= Checks.checkTypeParameterName(name, fTypeParameter); if (Checks.startsWithLowerCase(name)) { result.addWarning(RefactoringCoreMessages.RenameTypeParameterRefactoring_should_start_lowercase); } if (Checks.isAlreadyNamed(fTypeParameter, name)) { result.addFatalError(RefactoringCoreMessages.RenameTypeParameterRefactoring_another_name); } IMember member= fTypeParameter.getDeclaringMember(); if (member instanceof IType) { IType type= (IType) member; if (type.getTypeParameter(name).exists()) { result.addFatalError(RefactoringCoreMessages.RenameTypeParameterRefactoring_class_type_parameter_already_defined); } } else if (member instanceof IMethod) { IMethod method= (IMethod) member; if (method.getTypeParameter(name).exists()) { result.addFatalError(RefactoringCoreMessages.RenameTypeParameterRefactoring_method_type_parameter_already_defined); } } else { JavaLanguageServerPlugin.logError("Unexpected sub-type of IMember: " + member.getClass().getName()); //$NON-NLS-1$ Assert.isTrue(false); } return result; }
Example 19
Source File: GenerateHashCodeEqualsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkHashCodeEqualsExists(ITypeBinding someType, boolean superClass) { RefactoringStatus status= new RefactoringStatus(); HashCodeEqualsInfo info= getTypeInfo(someType, true); String concreteTypeWarning= superClass ? ActionMessages.GenerateMethodAbstractAction_super_class : ActionMessages.GenerateHashCodeEqualsAction_field_type; String concreteMethWarning= (someType.isInterface() || Modifier.isAbstract(someType.getModifiers())) ? ActionMessages.GenerateHashCodeEqualsAction_interface_does_not_declare_hashCode_equals_error : ActionMessages.GenerateHashCodeEqualsAction_type_does_not_implement_hashCode_equals_error; String concreteHCEWarning= null; if (!info.foundEquals && (!info.foundHashCode)) concreteHCEWarning= ActionMessages.GenerateHashCodeEqualsAction_equals_and_hashCode; else if (!info.foundEquals) concreteHCEWarning= ActionMessages.GenerateHashCodeEqualsAction_equals; else if (!info.foundHashCode) concreteHCEWarning= ActionMessages.GenerateHashCodeEqualsAction_hashCode; if (!info.foundEquals || !info.foundHashCode) status.addWarning(Messages.format(concreteMethWarning, new String[] { Messages.format(concreteTypeWarning, BindingLabelProvider.getBindingLabel(someType, JavaElementLabels.ALL_FULLY_QUALIFIED)), concreteHCEWarning }), createRefactoringStatusContext(someType.getJavaElement())); if (superClass && (info.foundFinalEquals || info.foundFinalHashCode)) { status.addError(Messages.format(ActionMessages.GenerateMethodAbstractAction_final_method_in_superclass_error, new String[] { Messages.format(concreteTypeWarning, BasicElementLabels.getJavaElementName(someType.getQualifiedName())), ActionMessages.GenerateHashCodeEqualsAction_hashcode_or_equals }), createRefactoringStatusContext(someType.getJavaElement())); } return status; }
Example 20
Source File: RenameFieldProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private RefactoringStatus addDelegates() throws JavaModelException, CoreException { RefactoringStatus status= new RefactoringStatus(); CompilationUnitRewrite rewrite= new CompilationUnitRewrite(fField.getCompilationUnit()); rewrite.setResolveBindings(true); // add delegate for the field if (RefactoringAvailabilityTester.isDelegateCreationAvailable(fField)) { FieldDeclaration fieldDeclaration= ASTNodeSearchUtil.getFieldDeclarationNode(fField, rewrite.getRoot()); if (fieldDeclaration.fragments().size() > 1) { status.addWarning(Messages.format(RefactoringCoreMessages.DelegateCreator_cannot_create_field_delegate_more_than_one_fragment, BasicElementLabels.getJavaElementName(fField.getElementName())), JavaStatusContext.create(fField)); } else if (((VariableDeclarationFragment) fieldDeclaration.fragments().get(0)).getInitializer() == null) { status.addWarning(Messages.format(RefactoringCoreMessages.DelegateCreator_cannot_create_field_delegate_no_initializer, BasicElementLabels.getJavaElementName(fField.getElementName())), JavaStatusContext.create(fField)); } else { DelegateFieldCreator creator= new DelegateFieldCreator(); creator.setDeclareDeprecated(fDelegateDeprecation); creator.setDeclaration(fieldDeclaration); creator.setNewElementName(getNewElementName()); creator.setSourceRewrite(rewrite); creator.prepareDelegate(); creator.createEdit(); } } // add delegates for getter and setter methods // there may be getters even if the field is static final if (getGetter() != null && fRenameGetter) { addMethodDelegate(getGetter(), getNewGetterName(), rewrite); } if (getSetter() != null && fRenameSetter) { addMethodDelegate(getSetter(), getNewSetterName(), rewrite); } final CompilationUnitChange change= rewrite.createChange(true); if (change != null) { change.setKeepPreviewEdits(true); fChangeManager.manage(fField.getCompilationUnit(), change); } return status; }