本文整理匯總了Java中com.github.javaparser.ast.body.MethodDeclaration.getModifiers方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodDeclaration.getModifiers方法的具體用法?Java MethodDeclaration.getModifiers怎麽用?Java MethodDeclaration.getModifiers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.javaparser.ast.body.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.getModifiers方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getParameterNames
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的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);
}
}
示例2: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public Node visit(MethodDeclaration _n, Object _arg) {
JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
Type type_ = cloneNodes(_n.getType(), _arg);
List<Parameter> parameters = visit(_n.getParameters(), _arg);
List<ReferenceType> throws_ = visit(_n.getThrows(), _arg);
BlockStmt block = cloneNodes(_n.getBody(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
MethodDeclaration r = new MethodDeclaration(
_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
_n.getModifiers(), annotations, typeParameters, type_, _n.getName(), parameters, _n.getArrayCount(), throws_, block
);
r.setComment(comment);
return r;
}
示例3: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public Node visit(MethodDeclaration _n, Object _arg) {
JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
Type type_ = cloneNodes(_n.getType(), _arg);
List<Parameter> parameters = visit(_n.getParameters(), _arg);
List<NameExpr> throws_ = visit(_n.getThrows(), _arg);
BlockStmt block = cloneNodes(_n.getBody(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
MethodDeclaration r = new MethodDeclaration(
_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
_n.getModifiers(), annotations, typeParameters, type_, _n.getName(), parameters, _n.getArrayCount(), throws_, block
);
r.setComment(comment);
return r;
}
示例4: parseMethodInfo
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
public static MethodInfo parseMethodInfo(ClassInfo containedClass, SourceInfo sourceInfo, MethodDeclaration methodDecl) {
// Log.d(TAG, "method name: %s, returnType: %s", methodDecl.name, methodDecl.getReturnType());
if (containedClass != null && methodDecl.getType() != null) {
MethodInfo methodInfo = new MethodInfo();
String methodName = methodDecl.getName();
methodName = containedClass.getQualifiedName() + "." + methodName;
Type returnType = TypeParser.parseType(sourceInfo, methodDecl.getType(), methodDecl.getType().toString());
methodInfo.setMethodName(methodName);
methodInfo.setReturnType(returnType);
if (methodDecl.getModifiers() != 0) {
methodInfo.addAllModifiers(Modifier.parseModifiersFromFlags(methodDecl.getModifiers()));
}
Log.d(TAG, "parseMethodInfo, methodName: %s, returnType: %s", methodName, returnType);
// parse parameters
if (methodDecl.getParameters() != null && methodDecl.getParameters().size() > 0) {
for (Parameter parameter : methodDecl.getParameters()) {
Type paramType = TypeParser.parseType(sourceInfo, parameter.getType(), parameter.getType().toString());
methodInfo.addParamType(paramType);
Log.d(TAG, "parseMethodInfo, parameter type: %s", paramType);
}
}
// parse annotaion
if (methodDecl.getAnnotations() != null && methodDecl.getAnnotations().size() > 0) {
for (AnnotationExpr annotation : methodDecl.getAnnotations()) {
AnnotationModifier annotationModifier = AnnotationModifierParser.parseAnnotation(sourceInfo, annotation);
methodInfo.putAnnotation(annotationModifier);
}
}
return methodInfo;
}
return null;
}
示例5: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public Node visit(MethodDeclaration _n, Object _arg) {
List<AnnotationExpr> annotations_ = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters_ = visit(_n.getTypeParameters(), _arg);
Type<?> type_ = cloneNodes(_n.getElementType(), _arg);
NameExpr nameExpr_ = cloneNodes(_n.getNameExpr(), _arg);
List<Parameter> parameters_ = visit(_n.getParameters(), _arg);
List<ReferenceType> throws_ = visit(_n.getThrows(), _arg);
BlockStmt block_ = cloneNodes(_n.getBody(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
List<ArrayBracketPair> arrayBracketPairsAfterElementType_ = visit(_n.getArrayBracketPairsAfterElementType(), _arg);
List<ArrayBracketPair> arrayBracketPairsAfterParameterList_ = visit(_n.getArrayBracketPairsAfterParameterList(), _arg);
MethodDeclaration r = new MethodDeclaration(
_n.getRange(),
_n.getModifiers(),
annotations_,
typeParameters_,
type_,
arrayBracketPairsAfterElementType_,
nameExpr_,
parameters_,
arrayBracketPairsAfterParameterList_,
throws_,
block_
);
r.setComment(comment);
return r;
}
示例6: buildMethodAST
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
/**
* The standard factory method to get an enhanced AST from a method
* @param methodDec Method declaration object as per javaparser
* @return An enhanced AST, which can be converted to a JSON
*/
public void buildMethodAST(MethodDeclaration methodDec){
try{
this.text = printAndExtractText(methodDec);
// Get all thrown Exceptions
for(ReferenceType type: methodDec.getThrows()){
this.exceptions.add(type.toString());
}
this.name = methodDec.getName();
Node parent = methodDec.getParentNode();
if (parent instanceof ClassOrInterfaceDeclaration){
this.className = ((ClassOrInterfaceDeclaration) parent).getName();
}
this.modifier = methodDec.getModifiers();
this.returnType = methodDec.getType().toString();
this.paramTypes = getParamTypes(methodDec);
// Get Annotations
for(AnnotationExpr annotExpr: methodDec.getAnnotations()){
this.annotations.add(annotExpr.getName().toString());
}
// If JavaDocs present, extract them
if (methodDec.getJavaDoc() != null){
this.javaDoc = cleanDocumentation(methodDec.getJavaDoc().getContent());
}
this.comments = extractContainedComments(methodDec);
// These are in-line comments just before the method definitition
if (methodDec.getComment() != null){
if (this.comments == null){
this.comments = "";
}
this.comments += methodDec.getComment().getContent();
}
// Recursively loop through child nodes and make a dictionary
this.parseBody(methodDec.getBody());
this.extractHighLevelConcepts();
} catch (Exception ex){
ex.printStackTrace();
}
}
示例7: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public Boolean visit(final MethodDeclaration n1, final Node arg) {
final MethodDeclaration n2 = (MethodDeclaration) arg;
// javadoc are checked at CompilationUnit
if (n1.getModifiers() != n2.getModifiers()) {
return Boolean.FALSE;
}
if (n1.getArrayCount() != n2.getArrayCount()) {
return Boolean.FALSE;
}
if (!objEquals(n1.getName(), n2.getName())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getType(), n2.getType())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getBody(), n2.getBody())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getParameters(), n2.getParameters())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getThrows(), n2.getThrows())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getTypeParameters(), n2.getTypeParameters())) {
return Boolean.FALSE;
}
if(n1.isDefault() != n2.isDefault()){
return Boolean.FALSE;
}
return Boolean.TRUE;
}