本文整理汇总了Java中org.eclipse.jdt.core.dom.MethodDeclaration.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration.getModifiers方法的具体用法?Java MethodDeclaration.getModifiers怎么用?Java MethodDeclaration.getModifiers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.getModifiers方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInterfaceMethodModifiers
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
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;
}
示例2: isMainMethod
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
/**
* 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: getVisibility
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
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";
}
示例4: visit
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
@Override
public boolean visit(MethodDeclaration methodDecl) {
int modifiers = methodDecl.getModifiers();
if(Modifier.isPublic(modifiers) && !methodDecl.isConstructor() && !methodDecl.getReturnType2().isPrimitiveType()){
Block body = methodDecl.getBody();
if(body!=null){
List<Statement> statements = body.statements();
for (Statement stmnt : statements) {
if(stmnt instanceof ReturnStatement){
ReturnStatement retStmnt = (ReturnStatement)stmnt;
Expression expression = retStmnt.getExpression();
if(expression instanceof SimpleName){
SimpleName simpleExpr = (SimpleName)expression;
IBinding resolveBinding = simpleExpr.resolveBinding();
Variable variable = context.getAllBindingKeyToVariableMap(resolveBinding.getKey());
if(variable!=null){
context.removeEncapsulatedVariable(variable);
}
}
}
}
}
}
return super.visit(methodDecl);
}
示例5: visit
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public boolean visit(MethodDeclaration methodDeclaration) {
// ASTNode parentNode = methodDeclaration.getParent();
// if (!(parentNode instanceof TypeDeclaration)) {
// // ignore methods from anonymous classes
// return false;
// }
String methodSignature = AstUtils.getSignatureFromMethodDeclaration(methodDeclaration);
// if
// (methodDeclaration.getName().getIdentifier().equals("execMultiLineCommands"))
// {
// System.out.println("x");
//
// }
final RastNode method = model.createMethod(methodSignature, containerStack.peek(), sourceFilePath, methodDeclaration.isConstructor(), methodDeclaration);
List<?> modifiers = methodDeclaration.modifiers();
Set<String> annotations = extractAnnotationTypes(modifiers);
boolean deprecated = annotations.contains("Deprecated") || AstUtils.containsDeprecatedTag(methodDeclaration.getJavadoc());
if (deprecated) {
method.addStereotypes(Stereotype.DEPRECATED);
}
int methodModifiers = methodDeclaration.getModifiers();
Visibility visibility = getVisibility(methodModifiers);
boolean isStatic = (methodModifiers & Modifier.STATIC) != 0;
if (!isStatic) {
method.addStereotypes(Stereotype.TYPE_MEMBER);
}
//method.setVisibility(visibility);
extractParametersAndReturnType(model, methodDeclaration, method);
Block body = methodDeclaration.getBody();
if (body == null) {
method.addStereotypes(Stereotype.ABSTRACT);
} else {
final List<String> references = new ArrayList<String>();
body.accept(new DependenciesAstVisitor(true) {
@Override
protected void onMethodAccess(ASTNode node, IMethodBinding binding) {
String methodKey = AstUtils.getKeyFromMethodBinding(binding);
references.add(methodKey);
}
});
postProcessReferences.put(method, references);
}
return true;
}
示例6: isAbstract
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private static boolean isAbstract(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isAbstract(modifiers));
}
示例7: isFinal
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private static boolean isFinal(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isFinal(modifiers));
}
示例8: isStatic
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private static boolean isStatic(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isStatic(modifiers));
}
示例9: isSynchronized
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private static boolean isSynchronized(MethodDeclaration decl) {
int modifiers = decl.getModifiers();
return (Modifier.isSynchronized(modifiers));
}
示例10: getInfoIcon
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public static Image getInfoIcon(Object element) {
if(element instanceof Info<?>){
switch(((Info) element).getType()){
case CLASS:
ITypeBinding typeBinding = Crystal.getInstance().getTypeBindingFromName((((Info) element).getKey()));
if(typeBinding!=null){
List<ImageDescriptor> overlayIcons = new ArrayList<ImageDescriptor>();
int typeModifiers = typeBinding.getModifiers();
if(Modifier.isAbstract(typeModifiers)){
overlayIcons.add(getImageDescriptor(IMG_ABSTRACT_CO));
}else if(Modifier.isStatic(typeModifiers)){
overlayIcons.add(getImageDescriptor(IMG_STATIC_CO));
}else if(Modifier.isPrivate(typeModifiers)){
overlayIcons.add(getImageDescriptor(IMG_PRIVATE_CO));
}
Image baseImage = JavaPluginImages.get(ISharedImages.IMG_OBJS_CLASS);
DecorationOverlayIcon image = new DecorationOverlayIcon(baseImage, overlayIcons.toArray(new ImageDescriptor[0]));
return image.createImage();
}
break;
case METHOD:
MethodDeclaration methodDeclaration = ASTUtils.getMethodDeclaration(((Info) element).getKey());
if(methodDeclaration!=null){
String icon= IMG_PUBLIC_CO;
if(methodDeclaration!=null){
int modifiers = methodDeclaration.getModifiers();
if(Modifier.isPrivate(modifiers)){
icon = IMG_PRIVATE_CO;
}else if(Modifier.isProtected(modifiers)){
icon = IMG_PROTECTED_CO;
}else{
}
}
ImageDescriptor imageDescriptor = getImageDescriptor(icon);
return imageDescriptor.createImage();
}
break;
}
}
return null;
}