org.eclipse.jdt.core.dom.MethodDeclaration#getModifiers ( )源码实例Demo

下面列出了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());
}
 
源代码3 项目: DesigniteJava   文件: SM_Method.java
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;
}
 
源代码4 项目: SnowGraph   文件: JavaASTVisitor.java
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";
}
 
源代码5 项目: gwt-eclipse-plugin   文件: UiBinderUtilities.java
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);
}
 
源代码6 项目: compiler   文件: Testq12.java
@Override
public boolean visit(MethodDeclaration node) {
	if ((node.getModifiers() & Modifier.STATIC) > 0 && !node.getName().toString().equals("main")) {
		methods++;
		methods2++;
	}
	return true;
}
 
源代码7 项目: SnowGraph   文件: JavaASTVisitor.java
private static boolean isAbstract(MethodDeclaration decl) {
    int modifiers = decl.getModifiers();
    return (Modifier.isAbstract(modifiers));
}
 
源代码8 项目: SnowGraph   文件: JavaASTVisitor.java
private static boolean isFinal(MethodDeclaration decl) {
    int modifiers = decl.getModifiers();
    return (Modifier.isFinal(modifiers));
}
 
源代码9 项目: SnowGraph   文件: JavaASTVisitor.java
private static boolean isStatic(MethodDeclaration decl) {
    int modifiers = decl.getModifiers();
    return (Modifier.isStatic(modifiers));
}
 
源代码10 项目: SnowGraph   文件: JavaASTVisitor.java
private static boolean isSynchronized(MethodDeclaration decl) {
    int modifiers = decl.getModifiers();
    return (Modifier.isSynchronized(modifiers));
}
 
源代码11 项目: JDeodorant   文件: PreconditionExaminer.java
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);
}