use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class IntroduceFactoryRefactoring method checkFinalConditions.
/*
* @see org.eclipse.jdt.internal.corext.refactoring.base.Refactoring#checkInput(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask(RefactoringCoreMessages.IntroduceFactory_checking_preconditions, 1);
RefactoringStatus result = new RefactoringStatus();
if (fFactoryClassName != null)
result.merge(setFactoryClass(fFactoryClassName));
if (result.hasFatalError())
return result;
fArgTypes = fCtorBinding.getParameterTypes();
fCtorIsVarArgs = fCtorBinding.isVarargs();
fAllCallsTo = findAllCallsTo(fCtorBinding, pm, result);
fFormalArgNames = findCtorArgNames();
ICompilationUnit[] affectedFiles = collectAffectedUnits(fAllCallsTo);
result.merge(Checks.validateModifiesFiles(ResourceUtil.getFiles(affectedFiles), getValidationContext()));
if (fCallSitesInBinaryUnits)
result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_callSitesInBinaryClass));
if (Modifier.isAbstract(fCtorBinding.getDeclaringClass().getModifiers())) {
result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_abstractClass));
}
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class IntroduceFactoryRefactoring method setFactoryClass.
/**
* Sets the class on which the generated factory method is to be placed.
* @param fullyQualifiedTypeName an <code>IType</code> referring to an existing class
* @return return the resulting status
*/
public RefactoringStatus setFactoryClass(String fullyQualifiedTypeName) {
IType factoryType;
try {
factoryType = findFactoryClass(fullyQualifiedTypeName);
if (factoryType == null)
return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceFactory_noSuchClass, BasicElementLabels.getJavaElementName(fullyQualifiedTypeName)));
if (factoryType.isAnnotation())
return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantPutFactoryMethodOnAnnotation);
if (factoryType.isInterface())
return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantPutFactoryMethodOnInterface);
} catch (JavaModelException e) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantCheckForInterface);
}
ICompilationUnit factoryUnitHandle = factoryType.getCompilationUnit();
if (factoryType.isBinary())
return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantPutFactoryInBinaryClass);
else {
try {
if (!fFactoryUnitHandle.equals(factoryUnitHandle)) {
fFactoryCU = getASTFor(factoryUnitHandle);
fFactoryUnitHandle = factoryUnitHandle;
}
fFactoryOwningClass = (AbstractTypeDeclaration) ASTNodes.getParent(NodeFinder.perform(fFactoryCU, factoryType.getNameRange()), AbstractTypeDeclaration.class);
String factoryPkg = factoryType.getPackageFragment().getElementName();
String ctorPkg = fCtorOwningClass.resolveBinding().getPackage().getName();
if (!factoryPkg.equals(ctorPkg))
fConstructorVisibility = Modifier.PUBLIC;
else if (fFactoryOwningClass != fCtorOwningClass)
// No such thing as Modifier.PACKAGE...
fConstructorVisibility = 0;
if (fFactoryOwningClass != fCtorOwningClass)
// No such thing as Modifier.PACKAGE...
fConstructorVisibility = 0;
} catch (JavaModelException e) {
return RefactoringStatus.createFatalErrorStatus(e.getMessage());
}
return new RefactoringStatus();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class IntroduceIndirectionRefactoring method adjustVisibility.
private RefactoringStatus adjustVisibility(IMember whoToAdjust, ModifierKeyword neededVisibility, boolean alsoIncreaseEnclosing, IProgressMonitor monitor) throws CoreException {
Map<IMember, IncomingMemberVisibilityAdjustment> adjustments;
if (isRewriteKept(whoToAdjust.getCompilationUnit()))
adjustments = fIntermediaryAdjustments;
else
adjustments = new HashMap<IMember, IncomingMemberVisibilityAdjustment>();
int existingAdjustments = adjustments.size();
addAdjustment(whoToAdjust, neededVisibility, adjustments);
if (alsoIncreaseEnclosing)
while (whoToAdjust.getDeclaringType() != null) {
whoToAdjust = whoToAdjust.getDeclaringType();
addAdjustment(whoToAdjust, neededVisibility, adjustments);
}
boolean hasNewAdjustments = (adjustments.size() - existingAdjustments) > 0;
if (hasNewAdjustments && ((whoToAdjust.isReadOnly() || whoToAdjust.isBinary())))
return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_update_binary_target_visibility, new String[] { JavaElementLabels.getElementLabel(whoToAdjust, JavaElementLabels.ALL_DEFAULT) }), JavaStatusContext.create(whoToAdjust));
RefactoringStatus status = new RefactoringStatus();
// Don't create a rewrite if it is not necessary
if (!hasNewAdjustments)
return status;
try {
monitor.beginTask(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting, 2);
Map<ICompilationUnit, CompilationUnitRewrite> rewrites;
if (!isRewriteKept(whoToAdjust.getCompilationUnit())) {
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(whoToAdjust.getCompilationUnit());
rewrite.setResolveBindings(false);
rewrites = new HashMap<ICompilationUnit, CompilationUnitRewrite>();
rewrites.put(whoToAdjust.getCompilationUnit(), rewrite);
status.merge(rewriteVisibility(adjustments, rewrites, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
rewrite.attachChange((CompilationUnitChange) fTextChangeManager.get(whoToAdjust.getCompilationUnit()), true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
}
} finally {
monitor.done();
}
return status;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ExtractTempRefactoring method checkInitialConditions.
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
try {
//$NON-NLS-1$
pm.beginTask("", 6);
RefactoringStatus result = Checks.validateModifiesFiles(ResourceUtil.getFiles(new ICompilationUnit[] { fCu }), getValidationContext());
if (result.hasFatalError())
return result;
if (fCompilationUnitNode == null) {
fCompilationUnitNode = RefactoringASTParser.parseWithASTProvider(fCu, true, new SubProgressMonitor(pm, 3));
} else {
pm.worked(3);
}
result.merge(checkSelection(new SubProgressMonitor(pm, 3)));
if (!result.hasFatalError() && isLiteralNodeSelected())
fReplaceAllOccurrences = false;
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ExtractTempRefactoring method checkMatchingFragments.
private RefactoringStatus checkMatchingFragments() throws JavaModelException {
RefactoringStatus result = new RefactoringStatus();
IASTFragment[] matchingFragments = getMatchingFragments();
for (int i = 0; i < matchingFragments.length; i++) {
ASTNode node = matchingFragments[i].getAssociatedNode();
if (isLeftValue(node) && !isReferringToLocalVariableFromFor((Expression) node)) {
String msg = RefactoringCoreMessages.ExtractTempRefactoring_assigned_to;
result.addWarning(msg, JavaStatusContext.create(fCu, node));
}
}
return result;
}
Aggregations