@Override protected boolean handleSelectionEndsIn(ASTNode node) { invalidSelection(RefactoringCoreMessages.StatementAnalyzer_doesNotCover, JavaStatusContext.create(fCUnit, node)); return super.handleSelectionEndsIn(node); }
@Override public boolean visit(AnonymousClassDeclaration node) { boolean result = super.visit(node); if (isFirstSelectedNode(node)) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_anonymous_type, JavaStatusContext.create(fCUnit, node)); return false; } return result; }
private boolean visitConstructorInvocation(ASTNode node, boolean superResult) { if (getSelection().getVisitSelectionMode(node) == Selection.SELECTED) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_super_or_this, JavaStatusContext.create(fCUnit, node)); return false; } return superResult; }
@Override public void endVisit(ForStatement node) { if (getSelection().getEndVisitSelectionMode(node) == Selection.AFTER) { if (node.initializers().contains(getFirstSelectedNode())) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_for_initializer, JavaStatusContext.create(fCUnit, getSelection())); } else if (node.updaters().contains(getLastSelectedNode())) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_for_updater, JavaStatusContext.create(fCUnit, getSelection())); } } super.endVisit(node); }
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; } } }
private void checkTypeInDeclaration(Type node) { if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED && getFirstSelectedNode() == node) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_variable_declaration, JavaStatusContext.create(fCUnit, getSelection())); } }
private void checkTypeInDeclaration(Type node) { if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED && getFirstSelectedNode() == node) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_variable_declaration, JavaStatusContext.create(fCUnit, getSelection())); } }
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; }
private static void addShadowsError(ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) { // Old match not found in new matches -> reference has been shadowed //TODO: should not have to filter declarations: if (oldMatch instanceof MethodDeclarationMatch || oldMatch instanceof FieldDeclarationMatch) { return; } ISourceRange range= new SourceRange(oldMatch.getOffset(), oldMatch.getLength()); RefactoringStatusContext context= JavaStatusContext.create(cu, range); String message= Messages.format(RefactoringCoreMessages.RenameAnalyzeUtil_shadows, BasicElementLabels.getFileName(cu)); result.addError(message, context); }
public static RefactoringStatus checkIfComesFromInterface(IMethod method, ITypeHierarchy hierarchy, IProgressMonitor monitor) throws JavaModelException { IMethod inInterface= MethodChecks.isDeclaredInInterface(method, hierarchy, monitor); if (inInterface == null) { return null; } RefactoringStatusContext context= JavaStatusContext.create(inInterface); String message= Messages.format(RefactoringCoreMessages.MethodChecks_implements, new String[]{JavaElementUtil.createMethodSignature(inInterface), JavaElementLabels.getElementLabel(inInterface.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)}); return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, "", RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE, inInterface); }
private void analyzeImportedTypes(IType[] types, RefactoringStatus result, IImportDeclaration imp) throws CoreException { for (int i = 0; i < types.length; i++) { //could this be a problem (same package imports)? if (JdtFlags.isPublic(types[i]) && types[i].getElementName().equals(getNewElementName())) { String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_name_conflict1, new Object[] { JavaElementLabels.getElementLabel(types[i], JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getPathLabel(getCompilationUnit(imp).getPath(), false) }); result.addError(msg, JavaStatusContext.create(imp)); } } }
private void analyzeImportedTypes(IType[] types, RefactoringStatus result, IImportDeclaration imp) throws CoreException { for (int i= 0; i < types.length; i++) { //could this be a problem (same package imports)? if (JdtFlags.isPublic(types[i]) && types[i].getElementName().equals(getNewElementName())){ String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_name_conflict1, new Object[]{ JavaElementLabels.getElementLabel(types[i], JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getPathLabel(getCompilationUnit(imp).getPath(), false)}); result.addError(msg, JavaStatusContext.create(imp)); } } }
@Override public void endVisit(EnhancedForStatement node) { if (getSelection().getEndVisitSelectionMode(node) == Selection.AFTER) { if (node.getParameter() == getFirstSelectedNode()) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_for_initializer, JavaStatusContext.create(fCUnit, getSelection())); } } super.endVisit(node); }
private RefactoringStatus checkEnclosedTypes() throws CoreException { IType enclosedType = findEnclosedType(fType, getNewElementName()); if (enclosedType == null) { return null; } String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_encloses, new String[] { BasicElementLabels.getJavaElementName(fType.getFullyQualifiedName('.')), getNewElementLabel() }); return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(enclosedType)); }
private RefactoringStatus checkEnclosingTypes() { IType enclosingType = findEnclosingType(fType, getNewElementName()); if (enclosingType == null) { return null; } String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_enclosed, new String[] { BasicElementLabels.getJavaElementName(fType.getFullyQualifiedName('.')), getNewElementLabel() }); return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(enclosingType)); }
private void addAdjustment(IMember whoToAdjust, ModifierKeyword neededVisibility, Map<IMember, IncomingMemberVisibilityAdjustment> adjustments) throws JavaModelException { ModifierKeyword currentVisibility= ModifierKeyword.fromFlagValue(JdtFlags.getVisibilityCode(whoToAdjust)); if (MemberVisibilityAdjustor.hasLowerVisibility(currentVisibility, neededVisibility) && MemberVisibilityAdjustor.needsVisibilityAdjustments(whoToAdjust, neededVisibility, adjustments)) adjustments.put(whoToAdjust, new MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment(whoToAdjust, neededVisibility, RefactoringStatus.createWarningStatus(Messages.format(MemberVisibilityAdjustor.getMessage(whoToAdjust), new String[] { MemberVisibilityAdjustor.getLabel(whoToAdjust), MemberVisibilityAdjustor.getLabel(neededVisibility) }), JavaStatusContext .create(whoToAdjust)))); }
@Override public void endVisit(VariableDeclarationExpression node) { if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED && getFirstSelectedNode() == node) { if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) { invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_resource_in_try_with_resources, JavaStatusContext.create(fCUnit, getSelection())); } } checkTypeInDeclaration(node.getType()); super.endVisit(node); }
private RefactoringStatus checkTypesInPackage() throws CoreException { IType type = Checks.findTypeInPackage(fType.getPackageFragment(), getNewElementName()); if (type == null || !type.exists()) { return null; } String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_exists, new String[] { getNewElementLabel(), JavaElementLabels.getElementLabel(fType.getPackageFragment(), JavaElementLabels.ALL_DEFAULT) }); return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(type)); }
private RefactoringStatus checkTypesImportedInCu() throws CoreException { IImportDeclaration imp = getImportedType(fType.getCompilationUnit(), getNewElementName()); if (imp == null) { return null; } String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_imported, new Object[] { getNewElementLabel(), BasicElementLabels.getPathLabel(fType.getCompilationUnit().getResource().getFullPath(), false) }); IJavaElement grandParent = imp.getParent().getParent(); if (grandParent instanceof ICompilationUnit) { return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(imp)); } return null; }
private RefactoringStatus checkTypesInCompilationUnit() { RefactoringStatus result= new RefactoringStatus(); if (! Checks.isTopLevel(fType)){ //the other case checked in checkTypesInPackage IType siblingType= fType.getDeclaringType().getType(getNewElementName()); if (siblingType.exists()){ String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_member_type_exists, new String[] { getNewElementLabel(), BasicElementLabels.getJavaElementName(fType.getDeclaringType().getFullyQualifiedName('.'))}); result.addError(msg, JavaStatusContext.create(siblingType)); } } return result; }