当前位置: 首页>>代码示例>>Java>>正文


Java Modifier类代码示例

本文整理汇总了Java中com.github.javaparser.ast.Modifier的典型用法代码示例。如果您正苦于以下问题:Java Modifier类的具体用法?Java Modifier怎么用?Java Modifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Modifier类属于com.github.javaparser.ast包,在下文中一共展示了Modifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printMembers

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
private void printMembers(final NodeList<BodyDeclaration<?>> members, final Void arg) {
	BodyDeclaration<?> prev = null;

	members.sort((a, b) -> {
		if (a instanceof FieldDeclaration && b instanceof CallableDeclaration) {
			return 1;
		} else if (b instanceof FieldDeclaration && a instanceof CallableDeclaration) {
			return -1;
		} else if (a instanceof MethodDeclaration && !((MethodDeclaration) a).getModifiers().contains(Modifier.STATIC) && b instanceof ConstructorDeclaration) {
			return 1;
		} else if (b instanceof MethodDeclaration && !((MethodDeclaration) b).getModifiers().contains(Modifier.STATIC) && a instanceof ConstructorDeclaration) {
			return -1;
		} else {
			return 0;
		}
	});

	for (final BodyDeclaration<?> member : members) {
		if (prev != null && (!prev.isFieldDeclaration() || !member.isFieldDeclaration())) printer.println();
		member.accept(this, arg);
		printer.println();

		prev = member;
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:26,代码来源:SrcRemapper.java

示例2: testGetClassNameFromMethod

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
@Test
public void testGetClassNameFromMethod() {
    //Code from: https://github.com/javaparser/javaparser/wiki/Manual
    CompilationUnit cu = new CompilationUnit();
    // set the package
    cu.setPackageDeclaration(new PackageDeclaration(Name.parse("com.aspectsecurity.example")));

    // or a shortcut
    cu.setPackageDeclaration("com.aspectsecurity.example");

    // create the type declaration
    ClassOrInterfaceDeclaration type = cu.addClass("GeneratedClass");

    // create a method
    EnumSet<Modifier> modifiers = EnumSet.of(Modifier.PUBLIC);
    MethodDeclaration method = new MethodDeclaration(modifiers, new VoidType(), "main");
    modifiers.add(Modifier.STATIC);
    method.setModifiers(modifiers);
    type.addMember(method);

    assertEquals("GeneratedClass", saa.getClassNameFromMethod(method));
}
 
开发者ID:kevinfealey,项目名称:API_Endpoint_Identifier,代码行数:23,代码来源:SpringAnnotationAnalyzerUnitTest.java

示例3: castStringToModifiers

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/***
 * @param modifiers
 * @return
 */
public static List<Modifier> castStringToModifiers(String modifiers) {
    List<Modifier> castModifiers = new ArrayList<Modifier>();

    if(modifiers.toLowerCase().contains(",")) {
        String content = modifiers.substring(modifiers.indexOf("[") + 1, modifiers.indexOf("]"));
        String[] modifierList = content.split(",");

        for(String modifier : modifierList) {
            modifier = modifier.trim();
            modifier = "[" + modifier + "]";
            castModifiers.add(getModifier(modifier));
        }
    } else {
        castModifiers.add(getModifier(modifiers));
    }

    return castModifiers;
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:23,代码来源:NodeParser.java

示例4: addAttributesToCompilationUnit

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/**
 * It adds all the attributes need to be added to the existing compilation unit.
 */
private void addAttributesToCompilationUnit() {
    if(attributesToBeAdded.size() > 0) {
        ClassOrInterfaceDeclaration type = getFileType();

        attributesToBeAdded.stream().forEach(attribute -> {
            EnumSet<Modifier> modifiers = null;
            for (Modifier modifier : attribute.getAccessModifiers()) {
                modifiers = EnumSet.of(modifier);
            }

            VariableDeclarator vd = new VariableDeclarator(JavaParser.parseType(attribute.getDataType()), attribute.getName());
            FieldDeclaration fd = new FieldDeclaration();
            fd.setModifiers(modifiers);
            fd.addVariable(vd);

            type.addMember(fd);
        });
    }
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:23,代码来源:NodeViewParser.java

示例5: getAccessModifier

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/**
 * It returns the access modifier of a given sign.
 */
public static List<Modifier> getAccessModifier(String sign) {
    List<Modifier> modifiers = new ArrayList<>();

    Modifier modifier = null;

    if(sign.equals("-")) {
        modifier = Modifier.PRIVATE;
    } else if (sign.equals("#")) {
        modifier = Modifier.PROTECTED;
    } else if (sign.equals("+")) {
        modifier = Modifier.PUBLIC;
    }

    modifiers.add(modifier);

    return modifiers;
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:21,代码来源:NodeViewParser.java

示例6: addAttributesToCompilationUnit

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/**
 * It adds all the attributes need to be added to the existing compilation unit.
 */
private void addAttributesToCompilationUnit() {
    if(attributesToBeAdded.size() > 0) {
        ClassOrInterfaceDeclaration type = getFileType();

        attributesToBeAdded.stream().forEach(attribute -> {
            EnumSet<Modifier> modifiers = null;
            for (Modifier modifier : attribute.getAccessModifiers()) {
                modifiers = EnumSet.of(modifier);
            }

            VariableDeclarator vd = new VariableDeclarator(JavaParser.parseType(attribute.getDataType()), attribute.getName());
            FieldDeclaration fd = new FieldDeclaration();
            fd.setModifiers(modifiers);
            fd.addVariable(vd);

            type.addMember(fd);
            ((ClassStructure)existingAbstractStructure).addAttribute(attribute);
        });
    }
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:24,代码来源:NodeViewScratchParser.java

示例7: getParameterNames

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
private void getParameterNames(MethodDeclaration methodDeclaration, boolean isInterface) {
  final EnumSet<Modifier> modifiers = methodDeclaration.getModifiers();
  if (isInterface || modifiers.contains(Modifier.PUBLIC)) {
    String methodName = methodDeclaration.getName().getIdentifier();
    List<Parameter> parameters = methodDeclaration.getParameters();
    names.className = this.className;
    List<List<ParameterName>> parameterNames =
        names.names.computeIfAbsent(methodName, k -> new ArrayList<>(4));

    final List<ParameterName> temp = new ArrayList<>();
    for (final Parameter parameter : parameters) {
      ParameterName parameterName = new ParameterName();
      String type = parameter.getType().toString();
      String name = parameter.getName().getIdentifier();
      if (name.contains("[]")) {
        type = type + "[]";
        name = name.replace("[]", "");
      }
      parameterName.type = type;
      parameterName.name = name;
      temp.add(parameterName);
    }
    parameterNames.add(temp);
  }
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:26,代码来源:ParameterNameVisitor.java

示例8: MethodDeclaration

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
public MethodDeclaration(final EnumSet<Modifier> modifiers, 
                         final List<AnnotationExpr> annotations,
                         final List<TypeParameter> typeParameters, 
                         final Type elementType,
                         final List<ArrayBracketPair> arrayBracketPairsAfterElementType,
                         final String name,
                         final List<Parameter> parameters, 
                         final List<ArrayBracketPair> arrayBracketPairsAfterParameterList,
                         final List<ReferenceType> throws_, 
                         final BlockStmt body) {
    super(annotations);
    setModifiers(modifiers);
    setTypeParameters(typeParameters);
    setElementType(elementType);
    setName(name);
    setParameters(parameters);
    setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType);
    setArrayBracketPairsAfterParameterList(arrayBracketPairsAfterParameterList);
    setThrows(throws_);
    setBody(body);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:22,代码来源:MethodDeclaration.java

示例9: fromCode

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
public static CodeStubBuilder fromCode(String code) {
  CompilationUnit cu = JavaParser.parse(code);

  for (TypeDeclaration<?> type : cu.getTypes()) {

    if (type instanceof ClassOrInterfaceDeclaration
            && type.getModifiers().contains(Modifier.PUBLIC)) {

      String className = type.getNameAsString();
      return new CodeStubBuilder(className);
    }
  }

  throw new IllegalArgumentException("Task instance's code did not contain any public class");
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:16,代码来源:CodeStubBuilder.java

示例10: MethodStructure

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/**
 * @param accessModifiers
 * @param returnType
 * @param name
 * @param parameters
 */
public MethodStructure(List<Modifier> accessModifiers, String returnType, String name, List<ParameterStructure> parameters) {
    this.accessModifiers = accessModifiers;
    this.returnType = returnType;
    this.name = name;
    this.parameters = parameters;
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:13,代码来源:MethodStructure.java

示例11: getSignOfAccessModifier

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/**
 * It returns the sign of a given access modifier
 */
private String getSignOfAccessModifier(List<Modifier> modifiers) {
    String sign = "";
    Modifier modifier = modifiers.get(0);

    if(modifier.equals(Modifier.PRIVATE)) {
        sign = "-";
    } else if (modifier.equals(Modifier.PROTECTED)) {
        sign = "#";
    } else if (modifier.equals(Modifier.PUBLIC)) {
        sign = "+";
    }

    return sign;
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:18,代码来源:BubbleParser.java

示例12: getModifier

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/***
 * This methods return the equivalent access modifier in Modifier Class Type
 * @param modifier
 * @return the given modifier in Modifier.Class format
 */
public static Modifier getModifier(String modifier) {
    Modifier originalModifier = null;

    switch (modifier) {
        case "[PUBLIC]":
            originalModifier = Modifier.PUBLIC;
            break;
        case "[PRIVATE]":
            originalModifier = Modifier.PRIVATE;
            break;
        case "[PROTECTED]":
            originalModifier = Modifier.PROTECTED;
            break;
        case "[ABSTRACT]":
            originalModifier = Modifier.ABSTRACT;
            break;
        case "[STATIC]":
            originalModifier = Modifier.STATIC;
            break;
        case "[FINAL]":
            originalModifier = Modifier.FINAL;
            break;
        case "[SYNCHRONIZED]":
            originalModifier = Modifier.SYNCHRONIZED;
            break;
        case "[]":
            originalModifier = Modifier.PUBLIC;
            break;
        default:
            System.out.println("***** SOMETHING GOES WRONG!" + modifier);
            break;
    }

    return originalModifier;
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:41,代码来源:NodeParser.java

示例13: addMethodsToCompilationUnit

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/**
 * It adds all the methods need to be added to the existing compilation unit.
 */
private void addMethodsToCompilationUnit() {
    if(methodsToBeAdded.size() > 0) {
        ClassOrInterfaceDeclaration type = getFileType();

        methodsToBeAdded.stream().forEach(method -> {
            EnumSet<Modifier> modifiers = null;
            for (Modifier modifier : method.getAccessModifiers()) {
                modifiers = EnumSet.of(modifier);
            }

            MethodDeclaration md = new MethodDeclaration();
            md.setName(method.getName());
            md.setModifiers(modifiers);

            if (method.getReturnType().equals("void")) {
                md.setType(new VoidType());
            } else {
                md.setType(JavaParser.parseType(method.getReturnType()));
            }

            if (method.getParameters().size() > 0) {
                method.getParameters().stream().forEach(p -> {
                    Parameter param = new Parameter(JavaParser.parseType(p.getDataType()), p.getName());
                    md.addParameter(param);
                });
            }

            type.addMember(md);
        });
    }
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:35,代码来源:NodeViewParser.java

示例14: addMethodsToCompilationUnit

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
/**
 * It adds all the methods need to be added to the existing compilation unit.
 */
private void addMethodsToCompilationUnit() {
    if(methodsToBeAdded.size() > 0) {
        ClassOrInterfaceDeclaration type = getFileType();

        methodsToBeAdded.stream().forEach(method -> {
            EnumSet<Modifier> modifiers = null;
            for (Modifier modifier : method.getAccessModifiers()) {
                modifiers = EnumSet.of(modifier);
            }

            MethodDeclaration md = new MethodDeclaration();
            md.setName(method.getName());
            md.setModifiers(modifiers);

            if (method.getReturnType().equals("void")) {
                md.setType(new VoidType());
            } else {
                md.setType(JavaParser.parseType(method.getReturnType()));
            }

            if (method.getParameters().size() > 0) {
                method.getParameters().stream().forEach(p -> {
                    Parameter param = new Parameter(JavaParser.parseType(p.getDataType()), p.getName());
                    md.addParameter(param);
                });
            }

            type.addMember(md);
            ((ClassStructure)existingAbstractStructure).addMethod(method);
        });
    }
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:36,代码来源:NodeViewScratchParser.java

示例15: visit

import com.github.javaparser.ast.Modifier; //导入依赖的package包/类
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
  super.visit(n, arg);
  final EnumSet<Modifier> modifiers = n.getModifiers();
  if (!modifiers.contains(Modifier.PRIVATE)) {
    final List<BodyDeclaration<?>> members = n.getMembers();
    final SimpleName simpleName = n.getName();
    final String clazz = simpleName.getId();
    // String clazz = n.getName();
    this.className = this.pkg + '.' + clazz;
    log.debug("class {}", this.className);
    int i = 0;
    for (final BodyDeclaration<?> body : members) {
      if (body instanceof MethodDeclaration) {
        MethodDeclaration methodDeclaration = (MethodDeclaration) body;
        this.getParameterNames(methodDeclaration, n.isInterface());
        i++;
      } else if (body instanceof ConstructorDeclaration) {
        // Constructor
      } else if (body instanceof ClassOrInterfaceDeclaration) {
        final ClassOrInterfaceDeclaration classOrInterfaceDeclaration =
            (ClassOrInterfaceDeclaration) body;
        String name = classOrInterfaceDeclaration.getName().getIdentifier();
        String key = this.pkg + '.' + name;
        name = this.originClassName + '.' + name;
        for (MethodParameterNames mpn : this.parameterNamesList) {
          if (mpn != null && mpn.className != null && mpn.className.equals(key)) {
            mpn.className = name;
          }
        }
      }
    }

    if (i > 0 && this.names.className != null) {
      this.parameterNamesList.add(this.names);
      this.names = new MethodParameterNames();
    }
  }
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:40,代码来源:ParameterNameVisitor.java


注:本文中的com.github.javaparser.ast.Modifier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。