use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.
the class RenameVirtualMethodProcessor method doCheckFinalConditions.
@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext checkContext) throws CoreException {
try {
//$NON-NLS-1$
pm.beginTask("", 9);
RefactoringStatus result = new RefactoringStatus();
result.merge(super.doCheckFinalConditions(new SubProgressMonitor(pm, 7), checkContext));
if (result.hasFatalError())
return result;
final IMethod method = getMethod();
final IType declaring = method.getDeclaringType();
final ITypeHierarchy hierarchy = getCachedHierarchy(declaring, new SubProgressMonitor(pm, 1));
final String name = getNewElementName();
if (declaring.isInterface()) {
if (isSpecialCase())
result.addError(RefactoringCoreMessages.RenameMethodInInterfaceRefactoring_special_case);
pm.worked(1);
IMethod[] relatedMethods = relatedTypeDeclaresMethodName(new SubProgressMonitor(pm, 1), method, name);
for (int i = 0; i < relatedMethods.length; i++) {
IMethod relatedMethod = relatedMethods[i];
RefactoringStatusContext context = JavaStatusContext.create(relatedMethod);
result.addError(RefactoringCoreMessages.RenameMethodInInterfaceRefactoring_already_defined, context);
}
} else {
if (classesDeclareOverridingNativeMethod(hierarchy.getAllSubtypes(declaring))) {
result.addError(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_requieres_renaming_native, //$NON-NLS-1$
new String[] { BasicElementLabels.getJavaElementName(method.getElementName()), "UnsatisfiedLinkError" }));
}
IMethod[] hierarchyMethods = hierarchyDeclaresMethodName(new SubProgressMonitor(pm, 1), hierarchy, 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())) {
result.addError(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_hierarchy_declares2, BasicElementLabels.getJavaElementName(name)), context);
} else {
result.addWarning(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_hierarchy_declares1, BasicElementLabels.getJavaElementName(name)), context);
}
}
}
fCachedHierarchy = null;
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.
the class RenameTypeProcessor method analyseEnclosedTypes.
private RefactoringStatus analyseEnclosedTypes() throws CoreException {
final ISourceRange typeRange = fType.getSourceRange();
final RefactoringStatus result = new RefactoringStatus();
CompilationUnit cuNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fType.getCompilationUnit(), false);
cuNode.accept(new ASTVisitor() {
@Override
public boolean visit(TypeDeclaration node) {
// enums and annotations can't be local
if (node.getStartPosition() <= typeRange.getOffset())
return true;
if (node.getStartPosition() > typeRange.getOffset() + typeRange.getLength())
return true;
if (getNewElementName().equals(node.getName().getIdentifier())) {
RefactoringStatusContext context = JavaStatusContext.create(fType.getCompilationUnit(), node);
String msg = null;
if (node.isLocalTypeDeclaration()) {
msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_local_type, new String[] { JavaElementUtil.createSignature(fType), getNewElementLabel() });
} else if (node.isMemberTypeDeclaration()) {
msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_member_type, new String[] { JavaElementUtil.createSignature(fType), getNewElementLabel() });
}
if (msg != null)
result.addError(msg, context);
}
MethodDeclaration[] methods = node.getMethods();
for (int i = 0; i < methods.length; i++) {
if (Modifier.isNative(methods[i].getModifiers())) {
RefactoringStatusContext context = JavaStatusContext.create(fType.getCompilationUnit(), methods[i]);
String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_enclosed_type_native, BasicElementLabels.getJavaElementName(node.getName().getIdentifier()));
result.addWarning(msg, context);
}
}
return true;
}
});
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.
the class RenamePackageProcessor method checkTypeNameConflicts.
private RefactoringStatus checkTypeNameConflicts(ICompilationUnit iCompilationUnit, Set<String> topLevelTypeNames) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
IType[] types = iCompilationUnit.getTypes();
for (int i = 0; i < types.length; i++) {
String name = types[i].getElementName();
if (topLevelTypeNames.contains(name)) {
String[] keys = { getElementLabel(iCompilationUnit.getParent()), getElementLabel(types[i]) };
String msg = Messages.format(RefactoringCoreMessages.RenamePackageRefactoring_contains_type, keys);
RefactoringStatusContext context = JavaStatusContext.create(types[i]);
result.addError(msg, context);
}
}
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.
the class MethodChecks method checkIfOverridesAnother.
public static RefactoringStatus checkIfOverridesAnother(IMethod method, ITypeHierarchy hierarchy) throws JavaModelException {
IMethod overrides = MethodChecks.overridesAnotherMethod(method, hierarchy);
if (overrides == null)
return null;
RefactoringStatusContext context = JavaStatusContext.create(overrides);
String message = Messages.format(RefactoringCoreMessages.MethodChecks_overrides, new String[] { JavaElementUtil.createMethodSignature(overrides), JavaElementLabels.getElementLabel(overrides.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD, overrides);
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext in project che by eclipse.
the class MethodChecks method checkIfComesFromInterface.
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, Corext.getPluginId(), RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE, inInterface);
}
Aggregations