本文整理汇总了Java中com.github.javaparser.ast.expr.ClassExpr类的典型用法代码示例。如果您正苦于以下问题:Java ClassExpr类的具体用法?Java ClassExpr怎么用?Java ClassExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了ClassExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
public void visit(final BlockStmt n, final RoutingDefineContext arg) {
if (arg.isInRoutingDefine()) {
MethodCallExpr call = new MethodCallExpr(
ASTHelper.createNameExpr(arg.getRoutingParameter().getId().getName()),
"resource");
ReferenceType rt = ASTHelper.createReferenceType(controllerClassName, 0);
ASTHelper.addArgument(call, new ClassExpr(rt.getType()));
ASTHelper.addStmt(n, call);
} else {
super.visit(n, arg);
}
}
示例2: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override
public ResultType visit( MethodDeclaration declaration, MethodDeclaration arg ) {
List<Statement> statements = declaration.getBody().getStmts();
Statement lastStatement = statements.get( statements.size() - 1 );
if ( lastStatement instanceof ReturnStmt ) try {
Expression expr = ( ( ReturnStmt ) lastStatement ).getExpr();
if ( expr instanceof ClassExpr )
// we could return the correct class type here, but that would cause misleading auto-completions
// because the runtime of the expression is a Class without with the type parameter erased
return new ResultType( Class.class, false );
else if ( expr instanceof ObjectCreationExpr )
return new ResultType( typeDiscoverer.classForName(
( ( ObjectCreationExpr ) expr ).getType().getName() ), false );
else if ( expr instanceof ArrayCreationExpr )
return new ResultType( Array.class, false );
else if ( expr.getClass().equals( StringLiteralExpr.class ) )
return new ResultType( String.class, false );
else if ( expr.getClass().equals( NameExpr.class ) ) {
Map<String, Class<?>> typeByVariableName = typeDiscoverer.getTypesByVariableName( statements );
String name = ( ( NameExpr ) expr ).getName();
@Nullable Class<?> variableType = typeByVariableName.get( name );
if ( variableType == null ) {
// attempt to return a class matching the apparent-variable name
return new ResultType( typeDiscoverer.classForName( name ), true );
} else {
return new ResultType( variableType, false );
}
} else
return ResultType.VOID;
} catch ( ClassNotFoundException ignore ) {
// class does not exist
}
return ResultType.VOID;
}
示例3: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override
public final void visit(ClassExpr ctx, Object arg) {
if (ctx.toString().endsWith(".class")) {
for (Node node : ctx.getChildNodes()) {
if (node.toString().equals(ctx.toString().substring(0, ctx.toString().indexOf(".class")))) {
ctx.remove(node);
}
}
}
}
示例4: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override
public void visit(final ClassExpr n, final Object arg) {
printer.printLn("ClassExpr");
printJavaComment(n.getComment(), arg);
n.getType().accept(this, arg);
printer.print(".class");
}
示例5: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override
public JCTree visit(final ClassExpr n, final Object arg) {
//ARG0: JCExpression selected
// I am assuming type is ClassOrInterfaceType
JCExpression arg0 = (JCExpression) n.getType().accept(this, arg);
//ARG1: Name selector
Name arg1 = names.fromString("class");
return new AJCFieldAccess(make.Select(arg0, arg1), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
示例6: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override public Boolean visit(final ClassExpr n1, final Node arg) {
final ClassExpr n2 = (ClassExpr) arg;
if (!nodeEquals(n1.getType(), n2.getType())) {
return false;
}
return true;
}
示例7: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override
public Node visit(ClassExpr _n, Object _arg) {
Type<?> type_ = cloneNodes(_n.getType(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ClassExpr r = new ClassExpr(
_n.getRange(),
type_
);
r.setComment(comment);
return r;
}
示例8: useMvc
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
private Type useMvc(final MethodCallExpr n, final Context ctx) {
if ("use".equals(n.getName())) {
List<Expression> args = n.getArgs();
if (args.size() == 1) {
Expression arg = args.get(0);
if (arg instanceof ClassExpr) {
return arg.accept(new TypeCollector(), ctx);
}
}
}
return null;
}
示例9: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override
public void visit(ClassExpr n, Script arg) {
}
示例10: parseExpression
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
/**
*
* @param expression
* a github javaparser Expression
* @param attributes
* the list of attributes of the class,
* to potentially get a type from the name
* @param lineNumber
* the starting line number of the parse method or constructor
* @return
* an Expression structure
*/
public Expr parseExpression(Expression expression, List<Attribute> attributes, int lineNumber) {
if (expression instanceof AssignExpr) { // this.bar = "bar";
AssignExpr assExpr = (AssignExpr) expression;
return parseExpression(assExpr.getTarget(), attributes, lineNumber);
} else if (expression instanceof MethodCallExpr) {
MethodCallExpr mcEx = (MethodCallExpr) expression;
return parseMethodCallExpression(mcEx, attributes, lineNumber);
} else if (expression instanceof NameExpr) { // ident
NameExpr nEx = (NameExpr) expression;
Ident nameExpr = new Ident(nEx.getName());
return nameExpr;
} else if (expression instanceof LiteralExpr) { // basic lit
return parseLiteralExpr((LiteralExpr) expression);
} else if (expression instanceof FieldAccessExpr) {
FieldAccessExpr fieldExpr = (FieldAccessExpr) expression;
Ident ident = new Ident(ParserUtils.parseTarget(expression.toString()).get("name"));
AttributeRef attrRef = new AttributeRef(ident);
return attrRef;
} else if (expression instanceof ObjectCreationExpr) {
ObjectCreationExpr objConExpr = (ObjectCreationExpr) expression;
return parseObjectCreationExpression(objConExpr, attributes, lineNumber);
} else if (expression instanceof ArrayAccessExpr) {
ArrayAccessExpr arryExpr = (ArrayAccessExpr) expression;
return parseArrayAccessExpression(arryExpr);
} else if (expression instanceof UnaryExpr) {
UnaryExpr unExpr = (UnaryExpr) expression;
return parseUnaryExpression(unExpr, attributes, lineNumber);
} else if (expression instanceof ConditionalExpr) {
ConditionalExpr condExpr = (ConditionalExpr) expression;
return parseConditionalExpression(condExpr, attributes, lineNumber);
} else if (expression instanceof CastExpr) {
CastExpr castExpr = (CastExpr) expression;
return parseExpression(castExpr.getExpr(), attributes, lineNumber);
} else if (expression instanceof BinaryExpr) {
BinaryExpr binEx = (BinaryExpr) expression;
return parseBinaryExpression(binEx, attributes, lineNumber);
} else if (expression instanceof EnclosedExpr) {
EnclosedExpr enclosedExpr = (EnclosedExpr) expression;
return parseExpression(enclosedExpr.getInner(), attributes, lineNumber);
} else if (expression instanceof InstanceOfExpr) {
InstanceOfExpr intExpr = (InstanceOfExpr) expression;
return parseInstanceOfExpression(intExpr, attributes, lineNumber);
} else if (expression instanceof ArrayCreationExpr) {
ArrayCreationExpr arryCreaExpr = (ArrayCreationExpr) expression;
return parseArrayCreationExpression(arryCreaExpr, attributes, lineNumber);
} else if (expression instanceof ArrayInitializerExpr) {
ArrayInitializerExpr arryInEx = (ArrayInitializerExpr) expression;
return parseArrayInitializerExpression(arryInEx, attributes, lineNumber);
} else if (expression instanceof ThisExpr) {
return new Ident("this");
} else if (expression instanceof SuperExpr) {
return new Ident("super");
} else if (expression instanceof ClassExpr) {
return new Ident(expression.toString());
} else if (expression instanceof VariableDeclarationExpr) { // int foo = 42;
// should be parsed by parseVariableDeclarationExpression()
Log.e(TAG, "Unreachable case :: expression : ".concat(expression.toString()));
return null;
} else {
Log.e(TAG, "The type of expression '".concat(expression.getClass().toString()).concat("' is not managed by the parser"));
return null;
}
}
示例11: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override public Node visit(final ClassExpr n, final A arg) {
n.setType((Type) n.getType().accept(this, arg));
return n;
}
示例12: socketHintBuilder
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
private MethodCallExpr socketHintBuilder(ClassOrInterfaceType socketHintBuilderType,
StringLiteralExpr stringLiteralExpr, DefinedParamType
paramType) {
final ClassExpr classExpr = new ClassExpr(genericType);
final MethodCallExpr[] builtMethod = {new MethodCallExpr(
// Constructor call
new ObjectCreationExpr(null, socketHintBuilderType, Collections.singletonList(classExpr)),
// Identifier method
"identifier",
Collections.singletonList(stringLiteralExpr)
)};
paramType.getDefaultValue().ifPresent(defaultValue -> {
builtMethod[0] = new MethodCallExpr(
builtMethod[0],
defaultValue.getSocketBuilderInitalValueMethodNameToUse(),
Collections.singletonList(defaultValue.getDefaultValue(paramType.getLiteralDefaultValue
()))
);
builtMethod[0] = new MethodCallExpr(
builtMethod[0],
"view",
Collections.singletonList(getViewEnumElement(defaultValue.getViewType()))
);
defaultValue.getDomainValue().ifPresent(domain -> {
builtMethod[0] = new MethodCallExpr(
builtMethod[0],
"domain",
Collections.singletonList(domain)
);
});
});
return new MethodCallExpr(
builtMethod[0],
"build"
);
}
示例13: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override public void visit(final ClassExpr n, final A arg) {
visitComment(n.getComment(), arg);
n.getType().accept(this, arg);
}
示例14: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override public Node visit(final ClassExpr n, final A arg) {
visitComment(n, arg);
n.setType((Type) n.getType().accept(this, arg));
return n;
}
示例15: visit
import com.github.javaparser.ast.expr.ClassExpr; //导入依赖的package包/类
@Override
public Object visit(final ClassExpr n, final Context ctx) {
return n.accept(new TypeCollector(), ctx);
}