本文整理汇总了Java中japa.parser.ast.body.ModifierSet类的典型用法代码示例。如果您正苦于以下问题:Java ModifierSet类的具体用法?Java ModifierSet怎么用?Java ModifierSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModifierSet类属于japa.parser.ast.body包,在下文中一共展示了ModifierSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJavaMethods
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private void getJavaMethods (ArrayList<JavaMethod> methods, TypeDeclaration type) {
classStack.push(type);
if (type.getMembers() != null) {
for (BodyDeclaration member : type.getMembers()) {
if (member instanceof ClassOrInterfaceDeclaration || member instanceof EnumDeclaration) {
getJavaMethods(methods, (TypeDeclaration)member);
} else {
if (member instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration)member;
if (!ModifierSet.hasModifier(((MethodDeclaration)member).getModifiers(), ModifierSet.NATIVE)) continue;
methods.add(createMethod(method));
}
}
}
}
classStack.pop();
}
示例2: isGetterMethod
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private boolean isGetterMethod(MethodDeclaration method)
{
if ((method.getBody() != null) && (method.getBody().getStmts() != null))
{
LinkedList<String> attNames = getAttributesNames();
if (attNames.size() == 0)
return false;
List<Statement> stmts = method.getBody().getStmts();
for (Statement stmt : stmts)
for (String name : attNames)
if ((stmt.toString().matches("(.*)return(\\s+)" + name + "(\\s*);")) && (method.getModifiers() == ModifierSet.PUBLIC) && (method.getParameters() == null))
return true;
}
return false;
}
示例3: isSetterMethod
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private boolean isSetterMethod(MethodDeclaration method)
{
if ((method.getBody() != null) && (method.getBody().getStmts() != null))
{
LinkedList<String> attNames = getAttributesNames();
if (attNames.size() == 0)
return false;
List<Statement> stmts = method.getBody().getStmts();
for (Statement stmt : stmts)
for (String name : attNames)
if ((method.getModifiers() == ModifierSet.PUBLIC) && (method.getParameters() != null) && (method.getParameters().size() == 1) && (method.getType().equals(new VoidType())) && (stmt.toString().matches("(.*)"+name+"(\\s*)=(.*)"+method.getParameters().get(0).getId().getName()+"(.*);")))
return true;
}
return false;
}
示例4: addAttachSkeleton
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private void addAttachSkeleton() {
List<Parameter> params = Collections.emptyList();
MethodDeclaration method = new MethodDeclaration(
ModifierSet.PUBLIC, new VoidType(), "attach", params);
AnnotationExpr override = new MarkerAnnotationExpr(new NameExpr("Override"));
method.setAnnotations(Collections.singletonList(override));
BlockStmt block = new BlockStmt();
Expression e = new MethodCallExpr(new SuperExpr(), "attach");
List<Statement> sts = Collections.singletonList((Statement)new ExpressionStmt(e));
block.setStmts(sts);
method.setBody(block);
if (getType().getMembers()==null) {
getType().setMembers(new LinkedList<BodyDeclaration>());
}
getType().getMembers().add(method);
}
示例5: addOnBecomingVisibleMethod
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
@SuppressWarnings("unused")
private void addOnBecomingVisibleMethod() {
List<Parameter> params = Collections.emptyList();
MethodDeclaration method = new MethodDeclaration(
ModifierSet.PUBLIC, new VoidType(), "onBecomingVisible", params);
AnnotationExpr override = new MarkerAnnotationExpr(new NameExpr("Override"));
method.setAnnotations(Collections.singletonList(override));
BlockStmt block = new BlockStmt();
Expression e = new MethodCallExpr(new SuperExpr(), "onBecomingVisible");
List<Statement> sts = Collections.singletonList((Statement)new ExpressionStmt(e));
block.setStmts(sts);
method.setBody(block);
if (getType().getMembers()==null) {
getType().setMembers(new LinkedList<BodyDeclaration>());
}
getType().getMembers().add(method);
}
示例6: addClaraHandler
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private MethodDeclaration addClaraHandler(String id, String className) {
ensureImport(className);
String shortName = className.substring(className.lastIndexOf(".")+1);
String handlerName = generateHandlerNameFor(id, shortName);
Parameter p = new Parameter(new ClassOrInterfaceType(shortName), new VariableDeclaratorId("event"));
MethodDeclaration handler = new MethodDeclaration(
ModifierSet.PUBLIC, new VoidType(), handlerName, Collections.singletonList(p));
handler.setBody(new BlockStmt());
handler.setAnnotations(createClaraHandlerAnnotations(id));
addNotification(handler, shortName+" on "+id);
addMember(handler);
return handler;
}
示例7: getJdkModifier
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
/**
* Converts a Java Parser modifier integer into a JDK {@link Modifier}
* integer.
*
* @param modifiers the Java Parser int
* @return the equivalent JDK int
*/
public static int getJdkModifier(final int modifiers) {
int result = 0;
if (ModifierSet.isAbstract(modifiers)) {
result |= Modifier.ABSTRACT;
}
if (ModifierSet.isFinal(modifiers)) {
result |= Modifier.FINAL;
}
if (ModifierSet.isNative(modifiers)) {
result |= Modifier.NATIVE;
}
if (ModifierSet.isPrivate(modifiers)) {
result |= Modifier.PRIVATE;
}
if (ModifierSet.isProtected(modifiers)) {
result |= Modifier.PROTECTED;
}
if (ModifierSet.isPublic(modifiers)) {
result |= Modifier.PUBLIC;
}
if (ModifierSet.isStatic(modifiers)) {
result |= Modifier.STATIC;
}
if (ModifierSet.isStrictfp(modifiers)) {
result |= Modifier.STRICT;
}
if (ModifierSet.isSynchronized(modifiers)) {
result |= Modifier.SYNCHRONIZED;
}
if (ModifierSet.isTransient(modifiers)) {
result |= Modifier.TRANSIENT;
}
if (ModifierSet.isVolatile(modifiers)) {
result |= Modifier.VOLATILE;
}
return result;
}
示例8: canFieldBeAnnotated
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
public static boolean canFieldBeAnnotated(FieldDeclaration node) {
final TypeDeclaration dclr = (TypeDeclaration) node.getParentNode();
if (!ModifierSet.isStatic(node.getModifiers()) && dclr.getParentNode() instanceof CompilationUnit) {
//handling nested classes
return true;
}
return false;
}
示例9: buildUnit
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
public static void buildUnit() {
CompilationUnit compUnit = new CompilationUnit();
compUnit.setPackage(new PackageDeclaration(ASTHelper
.createNameExpr("compiladores.aula")));
// create the type declaration
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(
ModifierSet.PUBLIC, false, "AulaJavaParser");
ASTHelper.addTypeDeclaration(compUnit, type);
// create a method
MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC,
ASTHelper.VOID_TYPE, "main");
method.setModifiers(ModifierSet.addModifier(method.getModifiers(),
ModifierSet.STATIC));
ASTHelper.addMember(type, method);
// add a parameter to the method
Parameter param = ASTHelper.createParameter(
ASTHelper.createReferenceType("String", 0), "args");
param.setVarArgs(true); //makes the parameter a ",,," array
ASTHelper.addParameter(method, param);
// add a body to the method
BlockStmt block = new BlockStmt();
method.setBody(block);
// add a statement do the method body
NameExpr clazz = new NameExpr("System");
FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
MethodCallExpr call = new MethodCallExpr(field, "println");
ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!"));
ASTHelper.addStmt(block, call);
System.out.println(compUnit.toString());
}
示例10: createMethod
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private JavaMethod createMethod (MethodDeclaration method) {
String className = classStack.peek().getName();
String name = method.getName();
boolean isStatic = ModifierSet.hasModifier(method.getModifiers(), ModifierSet.STATIC);
String returnType = method.getType().toString();
ArrayList<Argument> arguments = new ArrayList<Argument>();
if (method.getParameters() != null) {
for (Parameter parameter : method.getParameters()) {
arguments.add(new Argument(getArgumentType(parameter), parameter.getId().getName()));
}
}
return new JavaMethod(className, name, isStatic, returnType, null, arguments, method.getBeginLine(), method.getEndLine());
}
示例11: visit
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
@Override
public void visit(MethodDeclaration n, Scope arg) {
String name = Scope.computeMethodName(n);
if (arg.methods.containsKey(name)) {
throw new SemanticException("attempting to redefine method " + name + " on line " + n.getBeginLine());
}
// Create a sub-scope then put this method in scope.
Scope subScope = new Scope(ModifierSet.isStatic(n.getModifiers()) ?
Scope.Type.STATIC :
Scope.Type.INSTANCE);
subScope.backs.add(arg);
arg.methods.put(name, n.getType().toString());
super.visit(n, subScope);
n.setData(arg);
}
示例12: printModifiers
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private void printModifiers(int modifiers) {
if (ModifierSet.isPrivate(modifiers)) {
printer.print("private ");
}
if (ModifierSet.isProtected(modifiers)) {
printer.print("protected ");
}
if (ModifierSet.isPublic(modifiers)) {
printer.print("public ");
}
if (ModifierSet.isAbstract(modifiers)) {
printer.print("abstract ");
}
if (ModifierSet.isStatic(modifiers)) {
printer.print("static ");
}
if (ModifierSet.isFinal(modifiers)) {
printer.print("final ");
}
if (ModifierSet.isNative(modifiers)) {
printer.print("native ");
}
if (ModifierSet.isStrictfp(modifiers)) {
printer.print("strictfp ");
}
if (ModifierSet.isSynchronized(modifiers)) {
printer.print("synchronized ");
}
if (ModifierSet.isTransient(modifiers)) {
printer.print("transient ");
}
if (ModifierSet.isVolatile(modifiers)) {
printer.print("volatile ");
}
}
示例13: isRootField
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private static boolean isRootField(FieldDeclaration field) {
if (field.getVariables().size() != 1
|| !"root"
.equals(field.getVariables().get(0).getId().getName())) {
return false;
}
field.getModifiers();
return ModifierSet.hasModifier(field.getModifiers(),
ModifierSet.PRIVATE) && hasAnnotation(field, "AutoGenerated");
}
示例14: createClass
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
private void createClass(String name) {
ensureImport("org.vaadin.mideaas.MideaasComponent");
ClassOrInterfaceDeclaration decl =
new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, name);
decl.setExtends(Collections.singletonList(new ClassOrInterfaceType("MideaasComponent")));
cu.setTypes(Collections.singletonList((TypeDeclaration)decl));
}
示例15: createClassTouchkit
import japa.parser.ast.body.ModifierSet; //导入依赖的package包/类
@SuppressWarnings("unused")
private void createClassTouchkit(String name) {
ensureImport("org.vaadin.mideaas.MideaasNavigationView");
ClassOrInterfaceDeclaration decl =
new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, name);
decl.setExtends(Collections.singletonList(new ClassOrInterfaceType("MideaasNavigationView")));
cu.setTypes(Collections.singletonList((TypeDeclaration)decl));
}