use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameFieldProcessor method addDelegates.
private RefactoringStatus addDelegates() throws JavaModelException, CoreException {
RefactoringStatus status = new RefactoringStatus();
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(fField.getCompilationUnit());
rewrite.setResolveBindings(true);
// add delegate for the field
if (RefactoringAvailabilityTester.isDelegateCreationAvailable(fField)) {
FieldDeclaration fieldDeclaration = ASTNodeSearchUtil.getFieldDeclarationNode(fField, rewrite.getRoot());
if (fieldDeclaration.fragments().size() > 1) {
status.addWarning(Messages.format(RefactoringCoreMessages.DelegateCreator_cannot_create_field_delegate_more_than_one_fragment, BasicElementLabels.getJavaElementName(fField.getElementName())), JavaStatusContext.create(fField));
} else if (((VariableDeclarationFragment) fieldDeclaration.fragments().get(0)).getInitializer() == null) {
status.addWarning(Messages.format(RefactoringCoreMessages.DelegateCreator_cannot_create_field_delegate_no_initializer, BasicElementLabels.getJavaElementName(fField.getElementName())), JavaStatusContext.create(fField));
} else {
DelegateFieldCreator creator = new DelegateFieldCreator();
creator.setDeclareDeprecated(fDelegateDeprecation);
creator.setDeclaration(fieldDeclaration);
creator.setNewElementName(getNewElementName());
creator.setSourceRewrite(rewrite);
creator.prepareDelegate();
creator.createEdit();
}
}
// there may be getters even if the field is static final
if (getGetter() != null && fRenameGetter)
addMethodDelegate(getGetter(), getNewGetterName(), rewrite);
if (getSetter() != null && fRenameSetter)
addMethodDelegate(getSetter(), getNewSetterName(), rewrite);
final CompilationUnitChange change = rewrite.createChange(true);
if (change != null) {
change.setKeepPreviewEdits(true);
fChangeManager.manage(fField.getCompilationUnit(), change);
}
return status;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameLocalVariableProcessor method initialize.
private RefactoringStatus initialize(JavaRefactoringArguments extended) {
final String handle = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
if (handle != null) {
final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false);
if (element != null && element.exists()) {
if (element.getElementType() == IJavaElement.COMPILATION_UNIT) {
fCu = (ICompilationUnit) element;
} else if (element.getElementType() == IJavaElement.LOCAL_VARIABLE) {
fLocalVariable = (ILocalVariable) element;
fCu = (ICompilationUnit) fLocalVariable.getAncestor(IJavaElement.COMPILATION_UNIT);
if (fCu == null)
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.RENAME_LOCAL_VARIABLE);
} else
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.RENAME_LOCAL_VARIABLE);
} else
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.RENAME_LOCAL_VARIABLE);
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
final String name = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
if (//$NON-NLS-1$
name != null && !"".equals(name))
setNewElementName(name);
else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
if (fCu != null && fLocalVariable == null) {
final String selection = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION);
if (selection != null) {
int offset = -1;
int length = -1;
final StringTokenizer tokenizer = new StringTokenizer(selection);
if (tokenizer.hasMoreTokens())
offset = Integer.valueOf(tokenizer.nextToken()).intValue();
if (tokenizer.hasMoreTokens())
length = Integer.valueOf(tokenizer.nextToken()).intValue();
if (offset >= 0 && length >= 0) {
try {
final IJavaElement[] elements = fCu.codeSelect(offset, length);
if (elements != null) {
for (int index = 0; index < elements.length; index++) {
final IJavaElement element = elements[index];
if (element instanceof ILocalVariable)
fLocalVariable = (ILocalVariable) element;
}
}
if (fLocalVariable == null)
return JavaRefactoringDescriptorUtil.createInputFatalStatus(null, getProcessorName(), IJavaRefactorings.RENAME_LOCAL_VARIABLE);
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { selection, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION }));
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION));
}
final String references = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES);
if (references != null) {
fUpdateReferences = Boolean.valueOf(references).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES));
return new RefactoringStatus();
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus 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.RefactoringStatus in project che by eclipse.
the class RenameTypeParameterProcessor method checkNewElementName.
public RefactoringStatus checkNewElementName(String name) throws CoreException {
Assert.isNotNull(name);
RefactoringStatus result = Checks.checkTypeParameterName(name, fTypeParameter);
if (Checks.startsWithLowerCase(name))
result.addWarning(RefactoringCoreMessages.RenameTypeParameterRefactoring_should_start_lowercase);
if (Checks.isAlreadyNamed(fTypeParameter, name))
result.addFatalError(RefactoringCoreMessages.RenameTypeParameterRefactoring_another_name);
IMember member = fTypeParameter.getDeclaringMember();
if (member instanceof IType) {
IType type = (IType) member;
if (type.getTypeParameter(name).exists())
result.addFatalError(RefactoringCoreMessages.RenameTypeParameterRefactoring_class_type_parameter_already_defined);
} else if (member instanceof IMethod) {
IMethod method = (IMethod) member;
if (method.getTypeParameter(name).exists())
result.addFatalError(RefactoringCoreMessages.RenameTypeParameterRefactoring_method_type_parameter_already_defined);
} else {
//$NON-NLS-1$
JavaPlugin.logErrorMessage("Unexpected sub-type of IMember: " + member.getClass().getName());
Assert.isTrue(false);
}
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class JavaRenameProcessor method checkFinalConditions.
@Override
public final RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException {
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
RefactoringStatus result = doCheckFinalConditions(pm, context);
if (result.hasFatalError())
return result;
IFile[] changed = getChangedFiles();
for (int i = 0; i < changed.length; i++) {
deltaFactory.change(changed[i]);
}
fRenameModifications = computeRenameModifications();
fRenameModifications.buildDelta(deltaFactory);
fRenameModifications.buildValidateEdits((ValidateEditChecker) context.getChecker(ValidateEditChecker.class));
return result;
}
Aggregations