use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class IntroduceFactoryRefactoring method setNewMethodName.
/**
* Sets the name to be used for the generated factory method.<br>
* Returns a <code>RefactoringStatus</code> that indicates whether the
* given name is valid for the new factory method.
* @param newMethodName the name to be used for the generated factory method
* @return the resulting status
*/
public RefactoringStatus setNewMethodName(String newMethodName) {
Assert.isNotNull(newMethodName);
fNewMethodName = newMethodName;
RefactoringStatus stat = Checks.checkMethodName(newMethodName, fCUHandle);
stat.merge(isUniqueMethodName(newMethodName));
return stat;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ExtractMethodRefactoring method checkParameterNames.
/**
* Checks if the parameter names are valid.
* @return validation status
*/
public RefactoringStatus checkParameterNames() {
RefactoringStatus result = new RefactoringStatus();
for (Iterator<ParameterInfo> iter = fParameterInfos.iterator(); iter.hasNext(); ) {
ParameterInfo parameter = iter.next();
result.merge(Checks.checkIdentifier(parameter.getNewName(), fCUnit));
for (Iterator<ParameterInfo> others = fParameterInfos.iterator(); others.hasNext(); ) {
ParameterInfo other = others.next();
if (parameter != other && other.getNewName().equals(parameter.getNewName())) {
result.addError(Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_error_sameParameter, BasicElementLabels.getJavaElementName(other.getNewName())));
return result;
}
}
if (parameter.isRenamed() && fUsedNames.contains(parameter.getNewName())) {
result.addError(Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_error_nameInUse, BasicElementLabels.getJavaElementName(parameter.getNewName())));
return result;
}
}
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ExtractMethodRefactoring method checkFinalConditions.
/* (non-Javadoc)
* Method declared in Refactoring
*/
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
pm.beginTask(RefactoringCoreMessages.ExtractMethodRefactoring_checking_new_name, 2);
pm.subTask(EMPTY);
RefactoringStatus result = checkMethodName();
result.merge(checkParameterNames());
result.merge(checkVarargOrder());
pm.worked(1);
if (pm.isCanceled())
throw new OperationCanceledException();
BodyDeclaration node = fAnalyzer.getEnclosingBodyDeclaration();
if (node != null) {
fAnalyzer.checkInput(result, fMethodName, fDestination);
pm.worked(1);
}
pm.done();
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ExtractMethodRefactoring method createCallNodes.
//---- Code generation -----------------------------------------------------------------------
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) {
List<ASTNode> result = new ArrayList<ASTNode>(2);
IVariableBinding[] locals = fAnalyzer.getCallerLocals();
for (int i = 0; i < locals.length; i++) {
result.add(createDeclaration(locals[i], null));
}
MethodInvocation invocation = fAST.newMethodInvocation();
invocation.setName(fAST.newSimpleName(fMethodName));
ASTNode typeNode = ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration());
RefactoringStatus status = new RefactoringStatus();
while (fDestination != typeNode) {
fAnalyzer.checkInput(status, fMethodName, typeNode);
if (!status.isOK()) {
SimpleName destinationTypeName = fAST.newSimpleName(ASTNodes.getEnclosingType(fDestination).getName());
if ((modifiers & Modifier.STATIC) == 0) {
ThisExpression thisExpression = fAST.newThisExpression();
thisExpression.setQualifier(destinationTypeName);
invocation.setExpression(thisExpression);
} else {
invocation.setExpression(destinationTypeName);
}
break;
}
typeNode = typeNode.getParent();
}
List<Expression> arguments = invocation.arguments();
for (int i = 0; i < fParameterInfos.size(); i++) {
ParameterInfo parameter = fParameterInfos.get(i);
arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter)));
}
if (fLinkedProposalModel != null) {
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(fRewriter.track(invocation.getName()), false);
}
ASTNode call;
int returnKind = fAnalyzer.getReturnKind();
switch(returnKind) {
case ExtractMethodAnalyzer.ACCESS_TO_LOCAL:
IVariableBinding binding = fAnalyzer.getReturnLocal();
if (binding != null) {
VariableDeclarationStatement decl = createDeclaration(getMappedBinding(duplicate, binding), invocation);
call = decl;
} else {
Assignment assignment = fAST.newAssignment();
assignment.setLeftHandSide(ASTNodeFactory.newName(fAST, getMappedBinding(duplicate, fAnalyzer.getReturnValue()).getName()));
assignment.setRightHandSide(invocation);
call = assignment;
}
break;
case ExtractMethodAnalyzer.RETURN_STATEMENT_VALUE:
ReturnStatement rs = fAST.newReturnStatement();
rs.setExpression(invocation);
call = rs;
break;
default:
call = invocation;
}
if (call instanceof Expression && !fAnalyzer.isExpressionSelected()) {
call = fAST.newExpressionStatement((Expression) call);
}
result.add(call);
// return;
if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID && !fAnalyzer.isLastStatementSelected()) {
result.add(fAST.newReturnStatement());
}
return result.toArray(new ASTNode[result.size()]);
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class IntroduceIndirectionRefactoring method setIntermediaryTypeName.
/**
* @param fullyQualifiedTypeName the fully qualified name of the intermediary method
* @return status for type name. Use {@link #setIntermediaryMethodName(String)} to check for overridden methods.
*/
public RefactoringStatus setIntermediaryTypeName(String fullyQualifiedTypeName) {
IType target = null;
try {
if (fullyQualifiedTypeName.length() == 0)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_type_not_selected_error);
// find type (now including secondaries)
target = getProject().findType(fullyQualifiedTypeName, new NullProgressMonitor());
if (target == null || !target.exists())
return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_type_does_not_exist_error, BasicElementLabels.getJavaElementName(fullyQualifiedTypeName)));
if (target.isAnnotation())
return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_annotation);
if (target.isInterface() && !(JavaModelUtil.is18OrHigher(target.getJavaProject()) && JavaModelUtil.is18OrHigher(getProject())))
return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_on_interface);
} catch (JavaModelException e) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_unable_determine_declaring_type);
}
if (target.isReadOnly())
return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_readonly);
if (target.isBinary())
return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_create_in_binary);
fIntermediaryType = target;
return new RefactoringStatus();
}
Aggregations