本文整理匯總了Java中com.github.javaparser.ast.body.MethodDeclaration.getParameters方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodDeclaration.getParameters方法的具體用法?Java MethodDeclaration.getParameters怎麽用?Java MethodDeclaration.getParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.javaparser.ast.body.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.getParameters方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: MethodNode
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
MethodNode( MethodDeclaration metDec)
{
super();
this.metDec = metDec;
type = metDec.getType();
if(metDec.isPrivate())
modifier = "- ";
else if(metDec.isPublic())
modifier = "+ ";
else if(metDec.isProtected())
modifier = "# ";
else
modifier = "~ ";
nodeName = modifier + metDec.getName() + "(";
if (metDec.getParameters() != null)
{
parameters = new ArrayList<Parameter>(metDec.getParameters());
for (Parameter p : parameters)
nodeName = nodeName + " " + p + ", ";
if (nodeName.lastIndexOf(',') > 0 )
nodeName = nodeName.substring(0, nodeName.lastIndexOf(','));
}
nodeName = nodeName + ") : " + type.toString();
}
示例2: hasMain
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
/**
* A method to check whether the file has a main method in it or not
* @param file a parameter to take the file to check
* @return true if the file has a main method; false, if it hasn't
*/
public boolean hasMain( File file) {
int index = getRow( file);
if (index != -1) {
MutableTreeNode node = ((MutableTreeNode) rootNode.getChildAt(index));
if (node instanceof ClassNode) {
for (int i = 0; i < ((ClassNode) node).getChildCount(); i++) {
TreeNode treeNode = (((ClassNode) node).getChildAt(i));
if (treeNode instanceof MethodNode) {
MethodDeclaration metDec = ((MethodNode) treeNode).metDec;
if (metDec.getNameAsString().equals("main") &&
metDec.isPublic() && metDec.isStatic()) {
ArrayList<Parameter> parameters = new ArrayList<Parameter>(metDec.getParameters());
if (parameters.size() == 1 && parameters.get(0).toString().startsWith("String[]"))
return true;
}
}
}
}
}
return false;
}
示例3: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public void visit(MethodDeclaration method, Object arg) {
if (isInModuleStack.isEmpty() || !isInModuleStack.peek()) {
return;
}
if (!hasProvideAnnotation(method)) {
return;
}
String type = method.getType().toString();
if (hasIntoSetAnnotation(method)) {
type = "Set<" + type + ">";
}
for (Parameter parameter : method.getParameters()) {
builder.addDependency(type, parameter.getType().toString());
}
}
示例4: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
public void visit(MethodDeclaration n, Object arg) {
MethodDVO methodDVO = new MethodDVO();
methodDVO.setMethodName(n.getName());
methodDVO.setVisivility(GargoyleJavaParser.toStringVisibility(n.getModifiers()));
methodDVO.setDescription(n.getComment() != null ? n.getComment().toString() : "");
ArrayList<MethodParameterDVO> methodParameterDVOList = new ArrayList<>();
methodDVO.setMethodParameterDVOList(methodParameterDVOList);
List<Parameter> parameters = n.getParameters();
for (Parameter p : parameters) {
// String string2 = p.toString();
VariableDeclaratorId id2 = p.getId();
String varName = id2.getName();
Type type = p.getType();
String typeName = type.toString();
Comment comment = p.getComment();
methodParameterDVOList.add(new MethodParameterDVO(varName, typeName, "", comment == null ? "" : comment.toString()));
}
onMethodDVOVisite.accept(methodDVO);
super.visit(n, arg);
}
示例5: 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);
}
}
示例6: isSignatureMatched
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
private boolean isSignatureMatched(MethodDeclaration targetMethod, MethodDeclaration sourceMethod) {
final List<Parameter> targetParams = targetMethod.getParameters();
final List<Parameter> sourceParams = sourceMethod.getParameters();
if (targetParams.size() != sourceParams.size()) {
return false;
}
final List<Type> targetParameterTypes = targetParams.stream()
.map(Parameter::getType)
.collect(toList());
final List<Type> sourceParameterTypes = sourceParams.stream()
.map(Parameter::getType)
.collect(toList());
return targetParameterTypes.equals(sourceParameterTypes);
}
示例7: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public void visit(MethodDeclaration n, String arg) {
// here you can access the attributes of the method.
// this method will be called for all methods in this
// CompilationUnit, including inner class methods
int parameterCount;
if (n.getParameters() != null) {
parameterCount = n.getParameters().size();
} else {
parameterCount = 0;
}
String javaDocContent = "";
if (n.getComment() != null && n.getComment().getContent() != null) {
javaDocContent = n.getComment().getContent().replaceAll("\\n *\\* *", "\n ");
}
if (StringUtils.hasText(javaDocContent)) {
javaDoc.setJavaDoc(n.getName(), parameterCount, javaDocContent);
}
}
示例8: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override public void visit(final MethodDeclaration n, final A arg) {
visitComment(n.getComment(), arg);
visitAnnotations(n, arg);
if (n.getTypeParameters() != null) {
for (final TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
}
n.getElementType().accept(this, arg);
n.getNameExpr().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);
}
}
示例9: visit
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
@Override
public void visit(MethodDeclaration n, Context arg) {
StringBuilder sb = new StringBuilder();
sb.append('(');
for (Parameter p : n.getParameters()) {
sb.append(toDesc(p.getType(), arg));
}
sb.append(')');
sb.append(toDesc(n.getType(), arg));
String name = n.getName().getIdentifier();
String desc = sb.toString();
MethodInstance m = arg.mapped ? arg.cls.getMappedMethod(name, desc) : arg.cls.getMethod(name, desc);
System.out.println("mth "+n.getName().getIdentifier()+" = "+m+" at "+n.getRange());
if (m != null) {
/*if (m.hasMappedName()) {
n.getName().setIdentifier(m.getMappedName());
}*/
handleComment(m.getMappedComment(), n);
} else {
System.out.println("(not found)");
}
n.getBody().ifPresent(l -> l.accept(this, arg));
/*n.getType().accept(this, arg);
n.getParameters().forEach(p -> p.accept(this, arg));
n.getThrownExceptions().forEach(p -> p.accept(this, arg));
n.getTypeParameters().forEach(p -> p.accept(this, arg));
n.getAnnotations().forEach(p -> p.accept(this, arg));*/
}
示例10: index
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
public void index(MethodDeclaration methodDeclaration, int typeId) {
List<Parameter> parameters = methodDeclaration.getParameters();
String name = methodDeclaration.getNameAsString();
int methodId = methodDao.save(new Method(name,
methodDeclaration.isPublic(), methodDeclaration.isStatic(), methodDeclaration.isFinal(), methodDeclaration.isAbstract(), false, typeId));
for (Parameter parameter : parameters) {
parameterIndexer.index(parameter, methodId);
}
}
示例11: methodSpec
import com.github.javaparser.ast.body.MethodDeclaration; //導入方法依賴的package包/類
private MethodSpec methodSpec(MethodDeclaration methodDeclaration, String thenMethodPrefix) throws ClassNotFoundException {
PackageNameByClassName packageNames = PackageNameByClassName.packageNameByClassName(compilationUnit, ASSERTJ_API_PACKAGE);
List<TypeVariableName> rawTypeVariableNames = methodDeclaration.getTypeParameters().stream()
.map(typeParameter -> TypeVariableName.get(typeParameter.getName()))
.collect(toList());
TypeNameDetermination typeNameDetermination = typeNameDetermination(rawTypeVariableNames, packageNames);
List<TypeVariableName> boundTypeVariableNames = methodDeclaration.getTypeParameters().stream()
.map(typeParameter -> typeVariableName(typeParameter, typeNameDetermination))
.collect(toList());
TypeName returnTypeName = typeNameDetermination.determineTypeName(methodDeclaration.getType());
String methodName = methodDeclaration.getName().replace(ASSERT_THAT_METHOD_PREFIX, thenMethodPrefix);
MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
.addModifiers(PUBLIC, DEFAULT)
.addCode(thenMethodCodeEmitter.code(methodDeclaration, thenMethodPrefix))
.addJavadoc(javadocEmitter.javadoc(thenMethodPrefix, methodDeclaration.getJavaDoc()))
.returns(returnTypeName);
boundTypeVariableNames.forEach(builder::addTypeVariable);
if (methodDeclaration.getParameters().stream().anyMatch(this::isSuppressWarningsUnchecked)) {
builder.addAnnotation(AnnotationSpec.get(SUPPRESS_WARNINGS_UNCHECKED));
}
for (Parameter parameter : methodDeclaration.getParameters()) {
builder.addParameter(typeNameDetermination.determineTypeName(parameter.getType()), parameter.getName());
}
return builder.build();
}
示例12: 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);
}
}
示例13: 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);
}
}
示例14: 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;
}
示例15: 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;
}