use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameNonVirtualMethodProcessor method doCheckFinalConditions.
//----------- preconditions --------------
@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext checkContext) throws CoreException {
try {
//$NON-NLS-1$
pm.beginTask("", 3);
RefactoringStatus result = new RefactoringStatus();
result.merge(super.doCheckFinalConditions(new SubProgressMonitor(pm, 1), checkContext));
if (result.hasFatalError())
return result;
final IMethod method = getMethod();
final IType declaring = method.getDeclaringType();
final String name = getNewElementName();
IMethod[] hierarchyMethods = hierarchyDeclaresMethodName(new SubProgressMonitor(pm, 1), declaring.newTypeHierarchy(new SubProgressMonitor(pm, 1)), method, name);
for (int i = 0; i < hierarchyMethods.length; i++) {
IMethod hierarchyMethod = hierarchyMethods[i];
RefactoringStatusContext context = JavaStatusContext.create(hierarchyMethod);
if (Checks.compareParamTypes(method.getParameterTypes(), hierarchyMethod.getParameterTypes())) {
String message = Messages.format(RefactoringCoreMessages.RenamePrivateMethodRefactoring_hierarchy_defines, new String[] { BasicElementLabels.getJavaElementName(declaring.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(name) });
result.addError(message, context);
} else {
String message = Messages.format(RefactoringCoreMessages.RenamePrivateMethodRefactoring_hierarchy_defines2, new String[] { BasicElementLabels.getJavaElementName(declaring.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(name) });
result.addWarning(message, context);
}
}
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenamePackageProcessor method checkNewElementName.
public RefactoringStatus checkNewElementName(String newName) throws CoreException {
//$NON-NLS-1$
Assert.isNotNull(newName, "new name");
RefactoringStatus result = Checks.checkPackageName(newName, fPackage);
if (result.hasFatalError())
return result;
if (Checks.isAlreadyNamed(fPackage, newName)) {
result.addFatalError(RefactoringCoreMessages.RenamePackageRefactoring_another_name);
return result;
}
result.merge(checkPackageInCurrentRoot(newName));
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenamePackageProcessor method checkTypeNameConflicts.
private RefactoringStatus checkTypeNameConflicts(IPackageFragmentRoot root, String newName, Set<String> topLevelTypeNames) throws CoreException {
IPackageFragment otherPack = root.getPackageFragment(newName);
if (fPackage.equals(otherPack))
return null;
ICompilationUnit[] cus = otherPack.getCompilationUnits();
RefactoringStatus result = new RefactoringStatus();
for (int i = 0; i < cus.length; i++) {
result.merge(checkTypeNameConflicts(cus[i], topLevelTypeNames));
}
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameAnalyzeUtil method analyzeLocalRenames.
/**
* This method analyzes a set of local variable renames inside one cu. It checks whether
* any new compile errors have been introduced by the rename(s) and whether the correct
* node(s) has/have been renamed.
*
* @param analyzePackages the LocalAnalyzePackages containing the information about the local renames
* @param cuChange the TextChange containing all local variable changes to be applied.
* @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit
* @param recovery whether statements and bindings recovery should be performed when parsing the changed CU
* @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found
* @throws CoreException thrown if there was an error greating the preview content of the change
*/
public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
ICompilationUnit compilationUnit = (ICompilationUnit) oldCUNode.getJavaElement();
String newCuSource = cuChange.getPreviewContent(new NullProgressMonitor());
CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null);
result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode));
if (result.hasError())
return result;
for (int i = 0; i < analyzePackages.length; i++) {
ASTNode enclosing = getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode);
// get new declaration
IRegion newRegion = RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange);
ASTNode newDeclaration = NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength());
Assert.isTrue(newDeclaration instanceof Name);
VariableDeclaration declaration = getVariableDeclaration((Name) newDeclaration);
Assert.isNotNull(declaration);
SimpleName[] problemNodes = ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange);
result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes));
}
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class InlineTempRefactoring method checkInitialConditions.
/*
* @see Refactoring#checkActivation(IProgressMonitor)
*/
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
try {
//$NON-NLS-1$
pm.beginTask("", 1);
RefactoringStatus result = Checks.validateModifiesFiles(ResourceUtil.getFiles(new ICompilationUnit[] { fCu }), getValidationContext());
if (result.hasFatalError())
return result;
VariableDeclaration declaration = getVariableDeclaration();
result.merge(checkSelection(declaration));
if (result.hasFatalError())
return result;
result.merge(checkInitializer(declaration));
return result;
} finally {
pm.done();
}
}
Aggregations