本文整理汇总了Java中japa.parser.ast.type.ClassOrInterfaceType类的典型用法代码示例。如果您正苦于以下问题:Java ClassOrInterfaceType类的具体用法?Java ClassOrInterfaceType怎么用?Java ClassOrInterfaceType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassOrInterfaceType类属于japa.parser.ast.type包,在下文中一共展示了ClassOrInterfaceType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseType
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
private JType parseType(String type, JCodeModel codeModel) {
final String text = "public class Ignored extends " + type + " {}";
try {
CompilationUnit compilationUnit = JavaParser.parse(
new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8");
final List<TypeDeclaration> typeDeclarations = compilationUnit
.getTypes();
final TypeDeclaration typeDeclaration = typeDeclarations.get(0);
final ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) typeDeclaration;
final List<ClassOrInterfaceType> _extended = classDeclaration
.getExtends();
final ClassOrInterfaceType classOrInterfaceType = _extended.get(0);
return classOrInterfaceType.accept(
this.typeToJTypeConvertingVisitor, codeModel);
} catch (ParseException pex) {
throw new IllegalArgumentException(
"Could not parse the type definition [" + type + "].", pex);
} catch (UnsupportedEncodingException uex) {
throw new UnsupportedOperationException(uex);
}
}
示例2: getResolvedName
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
public static ClassOrInterfaceType getResolvedName(final JavaType target,
final JavaType current, final CompilationUnit compilationUnit) {
final NameExpr nameExpr = JavaParserUtils.importTypeIfRequired(target,
compilationUnit.getImports(), current);
final ClassOrInterfaceType resolvedName = JavaParserUtils
.getClassOrInterfaceType(nameExpr);
if (current.getParameters() != null
&& current.getParameters().size() > 0) {
resolvedName.setTypeArgs(new ArrayList<Type>());
for (final JavaType param : current.getParameters()) {
resolvedName.getTypeArgs().add(
getResolvedName(target, param, compilationUnit));
}
}
return resolvedName;
}
示例3: importParametersForType
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
public static ReferenceType importParametersForType(
final JavaType targetType, final List<ImportDeclaration> imports,
final JavaType typeToImport) {
Validate.notNull(targetType, "Target type is required");
Validate.notNull(imports, "Compilation unit imports required");
Validate.notNull(typeToImport, "Java type to import is required");
final ClassOrInterfaceType cit = getClassOrInterfaceType(importTypeIfRequired(
targetType, imports, typeToImport));
// Add any type arguments presented for the return type
if (typeToImport.getParameters().size() > 0) {
final List<Type> typeArgs = new ArrayList<Type>();
cit.setTypeArgs(typeArgs);
for (final JavaType parameter : typeToImport
.getParameters()) {
typeArgs.add(JavaParserUtils.importParametersForType(
targetType,
imports, parameter));
}
}
return new ReferenceType(cit);
}
示例4: visit
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
@Override
public void visit(CatchClause n, Object arg)
{ int line = n.getBeginLine();
Parameter e = n.getExcept();
if(!IGNORED_METHODS.contains(currentMethod))
{ Type t = e.getType();
if(t instanceof ReferenceType)
{ Type t2 = ((ReferenceType)t).getType();
if(t2 instanceof ClassOrInterfaceType)
{ String exceptionName = ((ClassOrInterfaceType)t2).getName();
if(FORBIDDEN_EXCEPTIONS.contains(exceptionName))
{ printErr("Erreur ligne "+line+" : le catch("+exceptionName+") masque l'appel à "+CHECK_INTERRUPTION_METHOD+"()");
errorCount++;
}
}
else
{ System.err.print(">>11111111111 problème : exception non conforme ("+t2.getClass()+")");
}
}
else
{ System.err.print(">>222222222 problème : exception non conforme ("+t.getClass()+")");
}
}
e.accept(this, arg);
n.getCatchBlock().accept(this, arg);
}
示例5: visit
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
@Override
public JType visit(ClassOrInterfaceType type, JCodeModel codeModel) {
final String name = getName(type);
final JClass knownClass = this.knownClasses.get(name);
final JClass jclass = knownClass != null ? knownClass : codeModel
.ref(name);
final List<Type> typeArgs = type.getTypeArgs();
if (typeArgs == null || typeArgs.isEmpty()) {
return jclass;
} else {
final List<JClass> jtypeArgs = new ArrayList<JClass>(
typeArgs.size());
for (Type typeArg : typeArgs) {
final JType jtype = typeArg.accept(this, codeModel);
if (!(jtype instanceof JClass)) {
throw new IllegalArgumentException("Type argument ["
+ typeArg.toString() + "] is not a class.");
} else {
jtypeArgs.add((JClass) jtype);
}
}
return jclass.narrow(jtypeArgs);
}
}
示例6: getRawTypeName
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
private static String getRawTypeName(Type type) {
if (type instanceof ClassOrInterfaceType) {
return getQualifiedName((ClassOrInterfaceType) type);
}
if (type instanceof ReferenceType) {
ReferenceType refType = (ReferenceType) type;
return getRawTypeName(refType.getType()) + StringUtils.multiply("[]", refType.getArrayCount());
}
if (type instanceof PrimitiveType) {
return ((PrimitiveType) type).getType().name().toLowerCase();
}
if (type instanceof VoidType) {
return "void";
}
if (type instanceof WildcardType) {
return "java.lang.Object";
}
return type.toString();
}
示例7: visit
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
public R visit(EnumDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getImplements() != null) {
for (ClassOrInterfaceType c : n.getImplements()) {
c.accept(this, arg);
}
}
if (n.getEntries() != null) {
for (EnumConstantDeclaration e : n.getEntries()) {
e.accept(this, arg);
}
}
if (n.getMembers() != null) {
for (BodyDeclaration member : n.getMembers()) {
member.accept(this, arg);
}
}
return null;
}
示例8: visit
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
public Boolean visit(ClassOrInterfaceType n1, Node arg) {
ClassOrInterfaceType n2 = (ClassOrInterfaceType) arg;
if (!objEquals(n1.getName(), n2.getName())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getScope(), n2.getScope())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getTypeArgs(), n2.getTypeArgs())) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
示例9: visit
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
public void visit(EnumDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getImplements() != null) {
for (ClassOrInterfaceType c : n.getImplements()) {
c.accept(this, arg);
}
}
if (n.getEntries() != null) {
for (EnumConstantDeclaration e : n.getEntries()) {
e.accept(this, arg);
}
}
if (n.getMembers() != null) {
for (BodyDeclaration member : n.getMembers()) {
member.accept(this, arg);
}
}
}
示例10: addClaraHandler
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
private MethodDeclaration addClaraHandler(String id, String className) {
ensureImport(className);
String shortName = className.substring(className.lastIndexOf(".")+1);
String handlerName = generateHandlerNameFor(id, shortName);
Parameter p = new Parameter(new ClassOrInterfaceType(shortName), new VariableDeclaratorId("event"));
MethodDeclaration handler = new MethodDeclaration(
ModifierSet.PUBLIC, new VoidType(), handlerName, Collections.singletonList(p));
handler.setBody(new BlockStmt());
handler.setAnnotations(createClaraHandlerAnnotations(id));
addNotification(handler, shortName+" on "+id);
addMember(handler);
return handler;
}
示例11: hasOneParamWithType
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
private static boolean hasOneParamWithType(MethodDeclaration method, String className) {
if (method.getParameters().size()!=1) {
return false;
}
Parameter p = method.getParameters().get(0);
// TODO: could check class matching more carefully...
if (p.getType() instanceof ClassOrInterfaceType) {
ClassOrInterfaceType coit = (ClassOrInterfaceType)p.getType();
return className.endsWith("."+coit.getName());
}
else if (p.getType() instanceof ReferenceType) {
ReferenceType rt = (ReferenceType)p.getType();
return className.endsWith("."+rt.toString()); // ??
}
return false;
}
示例12: resolveType
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
public static JClass resolveType(JClassContainer _package, String typeDefinition) {
try {
FieldDeclaration fieldDeclaration = (FieldDeclaration) JavaParser.parseBodyDeclaration(typeDefinition + " foo;");
ClassOrInterfaceType c = (ClassOrInterfaceType) ((ReferenceType) fieldDeclaration.getType()).getType();
return buildClass(_package, c, 0);
} catch (ParseException e) {
throw new GenerationException(e);
}
}
示例13: buildClass
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
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;
}
示例14: getClassOrInterfaceType
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
/**
* Converts the indicated {@link NameExpr} into a
* {@link ClassOrInterfaceType}.
* <p>
* Note that no effort is made to manage imports etc.
*
* @param nameExpr to convert (required)
* @return the corresponding {@link ClassOrInterfaceType} (never null)
*/
public static ClassOrInterfaceType getClassOrInterfaceType(
final NameExpr nameExpr) {
Validate.notNull(nameExpr, "Java type required");
if (nameExpr instanceof QualifiedNameExpr) {
final QualifiedNameExpr qne = (QualifiedNameExpr) nameExpr;
if (StringUtils.isNotBlank(qne.getQualifier().getName())) {
return new ClassOrInterfaceType(qne.getQualifier().getName()
+ "." + qne.getName());
}
return new ClassOrInterfaceType(qne.getName());
}
return new ClassOrInterfaceType(nameExpr.getName());
}
示例15: getJavaTypeNow
import japa.parser.ast.type.ClassOrInterfaceType; //导入依赖的package包/类
/**
* Resolves the effective {@link JavaType} a {@link ClassOrInterfaceType}
* represents, including any type arguments.
*
* @param compilationUnitServices for package management (required)
* @param cit the class or interface type to resolve (required)
* @return the effective Java type (never null)
*/
public static JavaType getJavaTypeNow(
final CompilationUnitServices compilationUnitServices,
final ClassOrInterfaceType cit,
final Set<JavaSymbolName> typeParameters) {
Validate.notNull(compilationUnitServices,
"Compilation unit services required");
Validate.notNull(cit, "ClassOrInterfaceType required");
final JavaPackage compilationUnitPackage = compilationUnitServices
.getCompilationUnitPackage();
Validate.notNull(compilationUnitPackage,
"Compilation unit package required");
String typeName = cit.getName();
ClassOrInterfaceType scope = cit.getScope();
while (scope != null) {
typeName = scope.getName() + "." + typeName;
scope = scope.getScope();
}
final NameExpr nameExpr = getNameExpr(typeName);
final JavaType effectiveType = getJavaType(compilationUnitServices,
nameExpr, typeParameters);
// Handle any type arguments
final List<JavaType> parameterTypes = new ArrayList<JavaType>();
if (cit.getTypeArgs() != null) {
for (final Type ta : cit.getTypeArgs()) {
parameterTypes.add(getJavaType(compilationUnitServices, ta,
typeParameters));
}
}
return new JavaType(effectiveType.getFullyQualifiedTypeName(),
effectiveType.getArray(), effectiveType.getDataType(), null,
parameterTypes);
}