本文整理汇总了Java中org.eclipse.ltk.core.refactoring.RefactoringStatus.isOK方法的典型用法代码示例。如果您正苦于以下问题:Java RefactoringStatus.isOK方法的具体用法?Java RefactoringStatus.isOK怎么用?Java RefactoringStatus.isOK使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ltk.core.refactoring.RefactoringStatus
的用法示例。
在下文中一共展示了RefactoringStatus.isOK方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCallNodes
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) {
List<ASTNode> result = new ArrayList<>(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);
// We have a void return statement. The code looks like
// extracted();
// return;
if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID && !fAnalyzer.isLastStatementSelected()) {
result.add(fAST.newReturnStatement());
}
return result.toArray(new ASTNode[result.size()]);
}
示例2: initialize
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
private RefactoringStatus initialize(JavaRefactoringArguments arguments) {
final String clone = arguments.getAttribute(ATTRIBUTE_CLONE);
if (clone != null) {
fAssumeCloneReturnsSameType = Boolean.valueOf(clone).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(
Messages.format(
RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
ATTRIBUTE_CLONE));
final String leave = arguments.getAttribute(ATTRIBUTE_LEAVE);
if (leave != null) {
fLeaveUnconstrainedRaw = Boolean.valueOf(leave).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(
Messages.format(
RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
ATTRIBUTE_LEAVE));
int count = 1;
final List<IJavaElement> elements = new ArrayList<IJavaElement>();
String handle = null;
String attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
final RefactoringStatus status = new RefactoringStatus();
while ((handle = arguments.getAttribute(attribute)) != null) {
final IJavaElement element =
JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
if (element == null || !element.exists())
return JavaRefactoringDescriptorUtil.createInputFatalStatus(
element, getName(), IJavaRefactorings.INFER_TYPE_ARGUMENTS);
else elements.add(element);
count++;
attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
}
fElements = elements.toArray(new IJavaElement[elements.size()]);
if (elements.isEmpty())
return JavaRefactoringDescriptorUtil.createInputFatalStatus(
null, getName(), IJavaRefactorings.INFER_TYPE_ARGUMENTS);
if (!status.isOK()) return status;
return new RefactoringStatus();
}
示例3: checkNewElementName
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
public final RefactoringStatus checkNewElementName(String newName) {
Assert.isNotNull(newName, "new name"); // $NON-NLS-1$
RefactoringStatus status =
Checks.checkName(newName, JavaConventionsUtil.validateMethodName(newName, fMethod));
if (status.isOK() && !Checks.startsWithLowerCase(newName))
status =
RefactoringStatus.createWarningStatus(
fIsComposite
? Messages.format(
RefactoringCoreMessages.Checks_method_names_lowercase2,
new String[] {
BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()
})
: RefactoringCoreMessages.Checks_method_names_lowercase);
if (Checks.isAlreadyNamed(fMethod, newName))
status.addFatalError(
fIsComposite
? Messages.format(
RefactoringCoreMessages.RenameMethodRefactoring_same_name2,
new String[] {
BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()
})
: RefactoringCoreMessages.RenameMethodRefactoring_same_name,
JavaStatusContext.create(fMethod));
return status;
}
示例4: checkMethodName
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
/**
* Checks if the given name is a valid Java method name.
*
* @param name the java method name.
* @param context an {@link IJavaElement} or <code>null</code>
* @return a refactoring status containing the error message if the name is not a valid java
* method name.
*/
public static RefactoringStatus checkMethodName(String name, IJavaElement context) {
RefactoringStatus status =
checkName(name, JavaConventionsUtil.validateMethodName(name, context));
if (status.isOK() && !startsWithLowerCase(name))
return RefactoringStatus.createWarningStatus(
RefactoringCoreMessages.Checks_method_names_lowercase);
else return status;
}
示例5: createCallNodes
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
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);
// We have a void return statement. The code looks like
// extracted();
// return;
if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID
&& !fAnalyzer.isLastStatementSelected()) {
result.add(fAST.newReturnStatement());
}
return result.toArray(new ASTNode[result.size()]);
}
示例6: asStatus
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
private IStatus asStatus(RefactoringStatus status) {
if (status.isOK()) {
return Status.OK_STATUS;
} else {
return status.getEntryWithHighestSeverity().toStatus();
}
}
示例7: validateDescriptor
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
/** {@inheritDoc} */
public RefactoringStatus validateDescriptor() {
RefactoringStatus result = super.validateDescriptor();
if (!result.isOK()) return result;
if (fMethod == null) {
result.addFatalError("The method must not be null"); // $NON-NLS-1$
return result;
}
IJavaProject javaProject = fMethod.getJavaProject();
if (javaProject == null) {
result.addFatalError("Can not derive Java project from method"); // $NON-NLS-1$
return result;
}
String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
if (fParameters != null) {
if (fParameters.length - 1 != fMethod.getNumberOfParameters()) {
result.addFatalError(
"The number of parameters does not match the number of parameters of the method"); // $NON-NLS-1$
}
boolean hasParameterObject = false;
for (int i = 0; i < fParameters.length; i++) {
Parameter parameter = fParameters[i];
if (parameter.isCreateField()) {
String fieldName = parameter.getFieldName();
if (fieldName == null)
result.addError(
"The parameter "
+ parameter.getIndex()
+ " is marked for field creation but does not have a field"
+ " name"); // $NON-NLS-1$ //$NON-NLS-2$
else {
result.merge(
RefactoringStatus.create(
JavaConventions.validateFieldName(fieldName, sourceLevel, complianceLevel)));
}
}
if (parameter == PARAMETER_OBJECT) {
if (hasParameterObject)
result.addError("Can not have more than one parameter object"); // $NON-NLS-1$
else hasParameterObject = true;
}
}
}
if (fClassName != null) {
result.merge(
RefactoringStatus.create(
JavaConventions.validateIdentifier(fClassName, sourceLevel, complianceLevel)));
}
if (fParameterName != null) {
result.merge(
RefactoringStatus.create(
JavaConventions.validateIdentifier(fParameterName, sourceLevel, complianceLevel)));
}
if (fPackageName != null && !"".equals(fPackageName)) { // $NON-NLS-1$
result.merge(
RefactoringStatus.create(
JavaConventions.validatePackageName(fPackageName, sourceLevel, complianceLevel)));
}
return result;
}
示例8: checkMethodName
import org.eclipse.ltk.core.refactoring.RefactoringStatus; //导入方法依赖的package包/类
/**
* Checks if the given name is a valid Java method name.
*
* @param name
* the java method name.
* @param context
* an {@link IJavaElement} or <code>null</code>
* @return a refactoring status containing the error message if the name is
* not a valid java method name.
*/
public static RefactoringStatus checkMethodName(String name, IJavaElement context) {
RefactoringStatus status = checkName(name, JavaConventionsUtil.validateMethodName(name, context));
if (status.isOK() && !startsWithLowerCase(name)) {
return RefactoringStatus.createWarningStatus(RefactoringCoreMessages.Checks_method_names_lowercase);
} else {
return status;
}
}