Search in sources :

Example 11 with RefactoringStatusContext

use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.

the class PromoteTempToFieldRefactoring method checkClashesWithExistingFields.

private RefactoringStatus checkClashesWithExistingFields() {
    FieldDeclaration[] existingFields = getFieldDeclarations();
    for (int i = 0; i < existingFields.length; i++) {
        FieldDeclaration declaration = existingFields[i];
        VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[]) declaration.fragments().toArray(new VariableDeclarationFragment[declaration.fragments().size()]);
        for (int j = 0; j < fragments.length; j++) {
            VariableDeclarationFragment fragment = fragments[j];
            if (fFieldName.equals(fragment.getName().getIdentifier())) {
                //cannot conflict with more than 1 name
                RefactoringStatusContext context = JavaStatusContext.create(fCu, fragment);
                return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_Name_conflict_with_field, context);
            }
        }
    }
    return null;
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 12 with RefactoringStatusContext

use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.

the class RefactoringAnalyzeUtil method reportProblemNodes.

public static RefactoringStatus reportProblemNodes(String modifiedWorkingCopySource, SimpleName[] problemNodes) {
    RefactoringStatus result = new RefactoringStatus();
    for (int i = 0; i < problemNodes.length; i++) {
        RefactoringStatusContext context = new JavaStringStatusContext(modifiedWorkingCopySource, SourceRangeFactory.create(problemNodes[i]));
        result.addError(Messages.format(RefactoringCoreMessages.RefactoringAnalyzeUtil_name_collision, BasicElementLabels.getJavaElementName(problemNodes[i].getIdentifier())), context);
    }
    return result;
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) JavaStringStatusContext(org.eclipse.jdt.internal.corext.refactoring.base.JavaStringStatusContext)

Example 13 with RefactoringStatusContext

use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.

the class RenameTypeProcessor method checkConflictingTypes.

private RefactoringStatus checkConflictingTypes(IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    IJavaSearchScope scope = RefactoringScopeFactory.create(fType);
    SearchPattern pattern = SearchPattern.createPattern(getNewElementName(), IJavaSearchConstants.TYPE, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    ICompilationUnit[] cusWithReferencesToConflictingTypes = RefactoringSearchEngine.findAffectedCompilationUnits(pattern, scope, pm, result);
    if (cusWithReferencesToConflictingTypes.length == 0)
        return result;
    ICompilationUnit[] cusWithReferencesToRenamedType = getCus(fReferences);
    Set<ICompilationUnit> conflicts = getIntersection(cusWithReferencesToRenamedType, cusWithReferencesToConflictingTypes);
    if (cusWithReferencesToConflictingTypes.length > 0) {
        cus: for (ICompilationUnit cu : cusWithReferencesToConflictingTypes) {
            String packageName = fType.getPackageFragment().getElementName();
            if (((IPackageFragment) cu.getParent()).getElementName().equals(packageName)) {
                boolean hasOnDemandImport = false;
                IImportDeclaration[] imports = cu.getImports();
                for (IImportDeclaration importDecl : imports) {
                    if (importDecl.isOnDemand()) {
                        hasOnDemandImport = true;
                    } else {
                        String importName = importDecl.getElementName();
                        int packageLength = importName.length() - getNewElementName().length() - 1;
                        if (packageLength > 0 && importName.endsWith(getNewElementName()) && importName.charAt(packageLength) == '.') {
                            // explicit import from another package => no problem
                            continue cus;
                        }
                    }
                }
                if (hasOnDemandImport) {
                    // the renamed type in the same package will shadow the *-imported type
                    conflicts.add(cu);
                }
            }
        }
    }
    for (ICompilationUnit conflict : conflicts) {
        RefactoringStatusContext context = JavaStatusContext.create(conflict);
        String message = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_another_type, new String[] { getNewElementLabel(), BasicElementLabels.getFileName(conflict) });
        result.addError(message, context);
    }
    return result;
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IImportDeclaration(org.eclipse.jdt.core.IImportDeclaration)

Example 14 with RefactoringStatusContext

use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.

the class InlineTempRefactoring method checkAssignments.

private RefactoringStatus checkAssignments(VariableDeclaration decl) {
    TempAssignmentFinder assignmentFinder = new TempAssignmentFinder(decl);
    getASTRoot().accept(assignmentFinder);
    if (!assignmentFinder.hasAssignments())
        return new RefactoringStatus();
    ASTNode firstAssignment = assignmentFinder.getFirstAssignment();
    int start = firstAssignment.getStartPosition();
    int length = firstAssignment.getLength();
    ISourceRange range = new SourceRange(start, length);
    RefactoringStatusContext context = JavaStatusContext.create(fCu, range);
    String message = Messages.format(RefactoringCoreMessages.InlineTempRefactoring_assigned_more_once, BasicElementLabels.getJavaElementName(decl.getName().getIdentifier()));
    return RefactoringStatus.createFatalErrorStatus(message, context);
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) ASTNode(org.eclipse.jdt.core.dom.ASTNode) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

RefactoringStatusContext (org.eclipse.ltk.core.refactoring.RefactoringStatusContext)14 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)9 IMethod (org.eclipse.jdt.core.IMethod)4 ISourceRange (org.eclipse.jdt.core.ISourceRange)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 IType (org.eclipse.jdt.core.IType)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)2 SourceRange (org.eclipse.jdt.core.SourceRange)2 FieldDeclarationMatch (org.eclipse.jdt.core.search.FieldDeclarationMatch)2 MethodDeclarationMatch (org.eclipse.jdt.core.search.MethodDeclarationMatch)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IImportDeclaration (org.eclipse.jdt.core.IImportDeclaration)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)1 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)1 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)1