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;
}
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;
}
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;
}
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);
}
Aggregations