本文整理匯總了Java中com.github.javaparser.ast.body.MethodDeclaration.getAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodDeclaration.getAnnotations方法的具體用法?Java MethodDeclaration.getAnnotations怎麽用?Java MethodDeclaration.getAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.javaparser.ast.body.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.getAnnotations方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public void visit(MethodDeclaration n, Optional<PackageDeclaration> clazzPackage) {
/* CHECK METHOD-LEVEL ANNOTATIONS FOR URL AND HTTP METHOD */
// We found a new method to look at
logger.debug("Method Name: " + n.getName());
String methodClazzName = getClassNameFromMethod(n);
// Get all annotations on method
NodeList<AnnotationExpr> nodeList = n.getAnnotations();
for (AnnotationExpr annotation : nodeList) {
// Found an annotation on the method
logger.debug("Found annotation: " + annotation.getNameAsString());
if (annotation.getNameAsString().equals("RequestMapping")) {
String packageName = "";
if (clazzPackage.isPresent()) {
packageName = clazzPackage.get().getNameAsString();
}
Endpoint newEndpoint = handleRequestMappingFound(annotation, packageName, methodClazzName);
// Check method parameters since we have a RequestMapping
newEndpoint.setParams(handleMethodParameters(n.getParameters()));
SpringAPIIdentifier.addEndpoint(newEndpoint);
}
}
super.visit(n, clazzPackage);
}
示例2: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
/**
* Increment method and parameter count
*
* @param declaration
* @param collector
*/
@Override
public void visit(MethodDeclaration declaration, Collector collector) {
for (AnnotationExpr annotation: declaration.getAnnotations()) {
if (annotation.getName().equals("Override"))
collector.incrementMetric("Overridden Methods");
}
if (declaration.toString().startsWith("public")) {
collector.incrementMetric("Public Methods");
}
if (declaration.toString().startsWith("private")) {
collector.incrementMetric("Private Methods");
}
if (declaration.toString().startsWith("protected")) {
collector.incrementMetric("Protected Methods");
}
if (!declaration.hasComment()) {
collector.incrementMetric("Methods without Javadoc");
}
collector.incrementMetric("Methods");
collector.incrementMetric("Parameters", declaration.getParameters().size());
super.visit(declaration, collector);
}
示例3: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public void visit(MethodDeclaration method, EligibilityResult result) {
List<AnnotationExpr> annotations = method.getAnnotations();
boolean methodHasResponseBodyAnnotation = annotations.stream().filter(annotation -> annotation.getName().getName().equals("ResponseBody")).findAny().isPresent();
boolean methodHasRequestMappingAnnotation = annotations.stream().filter(annotation -> annotation.getName().getName().equals("RequestMapping")).findAny().isPresent();
if (!methodHasResponseBodyAnnotation && methodHasRequestMappingAnnotation) {
result.setEligible(false);
} else {
methodsToRemoveAnnotationFrom.add(method);
super.visit(method, result);
}
}
示例4: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public void visit(final MethodDeclaration n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (final AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getTypeParameters() != null) {
for (final TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
}
n.getType().accept(this, arg);
if (n.getParameters() != null) {
for (final Parameter p : n.getParameters()) {
p.accept(this, arg);
}
}
if (n.getThrows() != null) {
for (final ReferenceType name : n.getThrows()) {
name.accept(this, arg);
}
}
if (n.getBody() != null) {
n.getBody().accept(this, arg);
}
}
示例5: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public void visit(final MethodDeclaration n, final A arg) {
jw.write(n);
visitComment(n.getComment(), arg);
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (final AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getTypeParameters() != null) {
for (final TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
}
n.getType().accept(this, arg);
if (n.getParameters() != null) {
for (final Parameter p : n.getParameters()) {
p.accept(this, arg);
}
}
if (n.getThrows() != null) {
for (final ReferenceType name : n.getThrows()) {
name.accept(this, arg);
}
}
if (n.getBody() != null) {
n.getBody().accept(this, arg);
}
}
示例6: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public Node visit(final MethodDeclaration n, final A arg) {
if (n.getJavaDoc() != null) {
n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg));
}
final List<AnnotationExpr> annotations = n.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.size(); i++) {
annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
}
removeNulls(annotations);
}
final List<TypeParameter> typeParameters = n.getTypeParameters();
if (typeParameters != null) {
for (int i = 0; i < typeParameters.size(); i++) {
typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg));
}
removeNulls(typeParameters);
}
n.setType((Type) n.getType().accept(this, arg));
final List<Parameter> parameters = n.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
parameters.set(i, (Parameter) parameters.get(i).accept(this, arg));
}
removeNulls(parameters);
}
final List<ReferenceType> throwz = n.getThrows();
if (throwz != null) {
for (int i = 0; i < throwz.size(); i++) {
throwz.set(i, (ReferenceType) throwz.get(i).accept(this, arg));
}
removeNulls(throwz);
}
if (n.getBody() != null) {
n.setBody((BlockStmt) n.getBody().accept(this, arg));
}
return n;
}
示例7: 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;
}
示例8: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public Node visit(final MethodDeclaration n, final A arg) {
visitComment(n, arg);
final List<AnnotationExpr> annotations = n.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.size(); i++) {
annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
}
removeNulls(annotations);
}
final List<TypeParameter> typeParameters = n.getTypeParameters();
if (typeParameters != null) {
for (int i = 0; i < typeParameters.size(); i++) {
typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg));
}
removeNulls(typeParameters);
}
n.setElementType((Type) n.getElementType().accept(this, arg));
final List<Parameter> parameters = n.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
parameters.set(i, (Parameter) parameters.get(i).accept(this, arg));
}
removeNulls(parameters);
}
final List<ReferenceType> throwz = n.getThrows();
if (throwz != null) {
for (int i = 0; i < throwz.size(); i++) {
throwz.set(i, (ReferenceType) throwz.get(i).accept(this, arg));
}
removeNulls(throwz);
}
if (n.getBody() != null) {
n.setBody((BlockStmt) n.getBody().accept(this, arg));
}
return n;
}
示例9: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public void visit(final MethodDeclaration n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (final AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getTypeParameters() != null) {
for (final TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
}
n.getType().accept(this, arg);
if (n.getParameters() != null) {
for (final Parameter p : n.getParameters()) {
p.accept(this, arg);
}
}
if (n.getThrows() != null) {
for (final NameExpr name : n.getThrows()) {
name.accept(this, arg);
}
}
if (n.getBody() != null) {
n.getBody().accept(this, arg);
}
}
示例10: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public Node visit(final MethodDeclaration n, final A arg) {
if (n.getJavaDoc() != null) {
n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg));
}
final List<AnnotationExpr> annotations = n.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.size(); i++) {
annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
}
removeNulls(annotations);
}
final List<TypeParameter> typeParameters = n.getTypeParameters();
if (typeParameters != null) {
for (int i = 0; i < typeParameters.size(); i++) {
typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg));
}
removeNulls(typeParameters);
}
n.setType((Type) n.getType().accept(this, arg));
final List<Parameter> parameters = n.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
parameters.set(i, (Parameter) parameters.get(i).accept(this, arg));
}
removeNulls(parameters);
}
final List<NameExpr> throwz = n.getThrows();
if (throwz != null) {
for (int i = 0; i < throwz.size(); i++) {
throwz.set(i, (NameExpr) throwz.get(i).accept(this, arg));
}
removeNulls(throwz);
}
if (n.getBody() != null) {
n.setBody((BlockStmt) n.getBody().accept(this, arg));
}
return n;
}
示例11: handleMethodDeclaration
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
private void handleMethodDeclaration(MethodDeclaration md) {
String name = md.getName().asString();
//-- We're only interested in getter/setters of a property.
Type type;
String propertyName;
boolean isSetter = false;
if(name.startsWith("get") || name.startsWith("is")) {
if(md.getParameters().size() != 0)
return;
type = md.getType();
if(type.equals(new VoidType()))
return;
int len = name.startsWith("is") ? 2 : 3;
propertyName = name.substring(len);
} else if(name.startsWith("set")) {
if(md.getParameters().size() != 1)
return;
type = md.getParameter(0).getType();
isSetter = true;
propertyName = name.substring(3);
} else
return;
if("opentopublic".equalsIgnoreCase(propertyName)) {
System.out.println("GOTCHA");
}
//-- Decode a property name
ColumnWrapper cw = findColumnByPropertyName(propertyName);
if(null == cw) {
cw = new ColumnWrapper(this);
m_allColumnWrappers.add(cw);
cw.setPropertyName(Introspector.decapitalize(propertyName));
}
cw.setPropertyType(type);
if(isSetter)
cw.setSetter(md);
else
cw.setGetter(md);
for(AnnotationExpr annotationExpr : md.getAnnotations()) {
handleDatabaseAnnotation(cw, annotationExpr);
}
}
示例12: 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();
}
}