本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTNode.METHOD_DECLARATION屬性的典型用法代碼示例。如果您正苦於以下問題:Java ASTNode.METHOD_DECLARATION屬性的具體用法?Java ASTNode.METHOD_DECLARATION怎麽用?Java ASTNode.METHOD_DECLARATION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.eclipse.jdt.core.dom.ASTNode
的用法示例。
在下文中一共展示了ASTNode.METHOD_DECLARATION屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: perform
/**
* Computes the maximum number of local variable declarations in the given
* body declaration.
*
* @param declaration
* the body declaration. Must either be a method declaration, or
* an initializer, or a field declaration.
* @return the maximum number of local variables
*/
public static int perform(BodyDeclaration declaration) {
Assert.isTrue(declaration != null);
switch (declaration.getNodeType()) {
case ASTNode.METHOD_DECLARATION:
case ASTNode.FIELD_DECLARATION:
case ASTNode.INITIALIZER:
return internalPerform(declaration);
default:
throw new IllegalArgumentException(declaration.toString());
}
}
示例2: getOrderPreference
private static int getOrderPreference(BodyDeclaration member, MemberSortOrder sortOrder) {
int memberType= member.getNodeType();
int modifiers= member.getModifiers();
switch (memberType) {
case ASTNode.TYPE_DECLARATION:
case ASTNode.ENUM_DECLARATION :
case ASTNode.ANNOTATION_TYPE_DECLARATION :
return sortOrder.getCategoryIndex(MemberSortOrder.TYPE_INDEX) * 2;
case ASTNode.FIELD_DECLARATION:
if (Modifier.isStatic(modifiers)) {
int index = sortOrder.getCategoryIndex(MemberSortOrder.STATIC_FIELDS_INDEX) * 2;
if (Modifier.isFinal(modifiers)) {
return index; // first final static, then static
}
return index + 1;
}
return sortOrder.getCategoryIndex(MemberSortOrder.FIELDS_INDEX) * 2;
case ASTNode.INITIALIZER:
if (Modifier.isStatic(modifiers)) {
return sortOrder.getCategoryIndex(MemberSortOrder.STATIC_INIT_INDEX) * 2;
}
return sortOrder.getCategoryIndex(MemberSortOrder.INIT_INDEX) * 2;
case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
return sortOrder.getCategoryIndex(MemberSortOrder.METHOD_INDEX) * 2;
case ASTNode.METHOD_DECLARATION:
if (Modifier.isStatic(modifiers)) {
return sortOrder.getCategoryIndex(MemberSortOrder.STATIC_METHODS_INDEX) * 2;
}
if (((MethodDeclaration) member).isConstructor()) {
return sortOrder.getCategoryIndex(MemberSortOrder.CONSTRUCTORS_INDEX) * 2;
}
return sortOrder.getCategoryIndex(MemberSortOrder.METHOD_INDEX) * 2;
default:
return 100;
}
}
示例3: isInvalidNode
/**
* Tests whether the node to be replaced is invalid.
*
* @return true if the node is invalid, false otherwise
*
*/
public boolean isInvalidNode() {
ASTNode first = fNodes.get(0);
ASTNode candidate = first.getParent();
if (candidate == null) {
return false;
}
// return invalid if the opening and closing parenthesis of the method signature is part of the node to be replaced
if (candidate.getNodeType() == ASTNode.METHOD_DECLARATION) {
return true;
}
return false;
}
示例4: initReturnType
private void initReturnType(ImportRewrite rewriter) {
AST ast = fEnclosingBodyDeclaration.getAST();
fReturnType = null;
fReturnTypeBinding = null;
switch (fReturnKind) {
case ACCESS_TO_LOCAL:
VariableDeclaration declaration = ASTNodes.findVariableDeclaration(fReturnValue, fEnclosingBodyDeclaration);
fReturnType = ASTNodeFactory.newType(ast, declaration, rewriter, new ContextSensitiveImportRewriteContext(declaration, rewriter));
if (declaration.resolveBinding() != null) {
fReturnTypeBinding = declaration.resolveBinding().getType();
}
break;
case EXPRESSION:
Expression expression = (Expression) getFirstSelectedNode();
if (expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
fExpressionBinding = ((ClassInstanceCreation) expression).getType().resolveBinding();
} else {
fExpressionBinding = expression.resolveTypeBinding();
}
if (fExpressionBinding != null) {
if (fExpressionBinding.isNullType()) {
getStatus().addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_null_type, JavaStatusContext.create(fCUnit, expression));
} else {
ITypeBinding normalizedBinding = Bindings.normalizeForDeclarationUse(fExpressionBinding, ast);
if (normalizedBinding != null) {
ImportRewriteContext context = new ContextSensitiveImportRewriteContext(fEnclosingBodyDeclaration, rewriter);
fReturnType = rewriter.addImport(normalizedBinding, ast, context, TypeLocation.RETURN_TYPE);
fReturnTypeBinding = normalizedBinding;
}
}
} else {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
getStatus().addError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_determine_return_type, JavaStatusContext.create(fCUnit, expression));
}
break;
case RETURN_STATEMENT_VALUE:
LambdaExpression enclosingLambdaExpr = ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
if (enclosingLambdaExpr != null) {
fReturnType = ASTNodeFactory.newReturnType(enclosingLambdaExpr, ast, rewriter, null);
IMethodBinding methodBinding = enclosingLambdaExpr.resolveMethodBinding();
fReturnTypeBinding = methodBinding != null ? methodBinding.getReturnType() : null;
} else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
fReturnType = ((MethodDeclaration) fEnclosingBodyDeclaration).getReturnType2();
fReturnTypeBinding = fReturnType != null ? fReturnType.resolveBinding() : null;
}
break;
default:
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
if (fReturnType == null) {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
}