use of japa.parser.ast.type.Type in project jsonschema2pojo by joelittlejohn.
the class TypeUtil method buildClass.
private static JClass buildClass(JClassContainer _package, ClassOrInterfaceType c, int arrayCount) {
final String packagePrefix = (c.getScope() != null) ? c.getScope().toString() + "." : "";
JClass _class;
try {
_class = _package.owner().ref(Thread.currentThread().getContextClassLoader().loadClass(packagePrefix + c.getName()));
} catch (ClassNotFoundException e) {
_class = _package.owner().ref(packagePrefix + c.getName());
}
for (int i = 0; i < arrayCount; i++) {
_class = _class.array();
}
List<Type> typeArgs = c.getTypeArgs();
if (typeArgs != null && typeArgs.size() > 0) {
JClass[] genericArgumentClasses = new JClass[typeArgs.size()];
for (int i = 0; i < typeArgs.size(); i++) {
genericArgumentClasses[i] = buildClass(_package, (ClassOrInterfaceType) ((ReferenceType) typeArgs.get(i)).getType(), ((ReferenceType) typeArgs.get(i)).getArrayCount());
}
_class = _class.narrow(genericArgumentClasses);
}
return _class;
}
use of japa.parser.ast.type.Type in project Japid by branaway.
the class JavaSyntaxTool method hasMethod.
public static boolean hasMethod(CompilationUnit cu, final String name, final int modis, final String returnType, String paramList) {
final StringBuilder sb = new StringBuilder();
if (paramList == null)
paramList = "";
String formalParamList = addParamNamesPlaceHolder(paramList);
final List<Parameter> params = parseParams(formalParamList);
VoidVisitorAdapter visitor = new VoidVisitorAdapter() {
@Override
public void visit(MethodDeclaration n, Object arg) {
if (n.getName().equals(name)) {
int modifiers2 = n.getModifiers();
if (modifiers2 == modis) {
Type type = n.getType();
if (type.toString().equals(returnType)) {
List<Parameter> ps = n.getParameters();
if (ps == null)
ps = new ArrayList<Parameter>();
if (paramsMatch(params, ps)) {
sb.append(1);
return;
}
}
}
}
}
};
cu.accept(visitor, null);
if (sb.length() == 0)
return false;
else
return true;
}
use of japa.parser.ast.type.Type in project japid42 by branaway.
the class JavaSyntaxTool method hasMethod.
public static boolean hasMethod(CompilationUnit cu, final String name, final int modis, final String returnType, String paramList) {
final StringBuilder sb = new StringBuilder();
if (paramList == null)
paramList = "";
String formalParamList = addParamNamesPlaceHolder(paramList);
final List<Parameter> params = parseParams(formalParamList);
VoidVisitorAdapter visitor = new VoidVisitorAdapter() {
@Override
public void visit(MethodDeclaration n, Object arg) {
if (n.getName().equals(name)) {
int modifiers2 = n.getModifiers();
if (modifiers2 == modis) {
Type type = n.getType();
if (type.toString().equals(returnType)) {
List<Parameter> ps = n.getParameters();
if (ps == null)
ps = new ArrayList<Parameter>();
if (paramsMatch(params, ps)) {
sb.append(1);
return;
}
}
}
}
}
};
cu.accept(visitor, null);
if (sb.length() == 0)
return false;
else
return true;
}
Aggregations