下面列出了org.eclipse.jdt.core.dom.MethodDeclaration#getModifiers ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private int getInterfaceMethodModifiers(ASTNode targetTypeDecl, boolean createAbstractMethod) {
// for interface and annotation members copy the modifiers from an existing member
if (targetTypeDecl instanceof TypeDeclaration) {
TypeDeclaration type= (TypeDeclaration) targetTypeDecl;
MethodDeclaration[] methodDecls= type.getMethods();
if (methodDecls.length > 0) {
if (createAbstractMethod) {
for (MethodDeclaration methodDeclaration : methodDecls) {
IMethodBinding methodBinding= methodDeclaration.resolveBinding();
if (methodBinding != null && JdtFlags.isAbstract(methodBinding)) {
return methodDeclaration.getModifiers();
}
}
}
return methodDecls[0].getModifiers() & Modifier.PUBLIC;
}
List<BodyDeclaration> bodyDecls= type.bodyDeclarations();
if (bodyDecls.size() > 0) {
return bodyDecls.get(0).getModifiers() & Modifier.PUBLIC;
}
}
return 0;
}
/**
* Returns true iff 'methodDeclaration' represents a void static method named 'main' that takes a
* single String[] parameter.
*/
private static boolean isMainMethod(MethodDeclaration methodDeclaration) {
// Is it static?
if ((methodDeclaration.getModifiers() & Modifier.STATIC) == 0) {
return false;
}
// Does it return void?
Type returnType = methodDeclaration.getReturnType2();
if (!returnType.isPrimitiveType()) {
return false;
}
if (((PrimitiveType) returnType).getPrimitiveTypeCode() != PrimitiveType.VOID) {
return false;
}
// Is it called 'main'?
if (!"main".equals(methodDeclaration.getName().getIdentifier())) {
return false;
}
// Does it have a single parameter?
if (methodDeclaration.parameters().size() != 1) {
return false;
}
// Is the parameter's type String[]?
SingleVariableDeclaration pt =
getOnlyElement((List<SingleVariableDeclaration>) methodDeclaration.parameters());
IVariableBinding vb = pt.resolveBinding();
if (vb == null) {
return false;
}
ITypeBinding tb = vb.getType();
return tb != null && "java.lang.String[]".equals(tb.getQualifiedName());
}
public void setMethodInfo(MethodDeclaration method) {
int modifiers = method.getModifiers();
if (Modifier.isAbstract(modifiers))
abstractMethod = true;
if (Modifier.isFinal(modifiers))
finalMethod = true;
if (Modifier.isStatic(modifiers))
staticMethod = true;
if (method.isConstructor())
isConstructor = true;
}
private static String getVisibility(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
if (Modifier.isPrivate(modifiers))
return "private";
if (Modifier.isProtected(modifiers))
return "protected";
if (Modifier.isPublic(modifiers))
return "public";
return "package";
}
public static boolean isUiHandler(MethodDeclaration method) {
if ((method.getModifiers() & Modifier.STATIC) != 0) {
return false;
}
if (method.isConstructor()) {
return false;
}
return (JavaASTUtils.findAnnotation(method,
UiBinderConstants.UI_HANDLER_TYPE_NAME) != null);
}
@Override
public boolean visit(MethodDeclaration node) {
if ((node.getModifiers() & Modifier.STATIC) > 0 && !node.getName().toString().equals("main")) {
methods++;
methods2++;
}
return true;
}
private static boolean isAbstract(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isAbstract(modifiers));
}
private static boolean isFinal(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isFinal(modifiers));
}
private static boolean isStatic(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isStatic(modifiers));
}
private static boolean isSynchronized(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isSynchronized(modifiers));
}
private boolean extractToUtilityClass(ITypeBinding commonSuperTypeOfSourceTypeDeclarations, MethodDeclaration methodDeclaration1, MethodDeclaration methodDeclaration2) {
return cloneFragmentsDoNotAccessFieldsOrMethods() && (ASTNodeMatcher.isTaggingInterface(commonSuperTypeOfSourceTypeDeclarations) || commonSuperTypeOfSourceTypeDeclarations.isInterface() ||
(methodDeclaration1.getModifiers() & Modifier.STATIC) != 0 || (methodDeclaration2.getModifiers() & Modifier.STATIC) != 0);
}