本文整理汇总了Java中com.github.javaparser.ast.expr.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于com.github.javaparser.ast.expr包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypesByVariableName
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
Map<String, Class<?>> getTypesByVariableName( List<Statement> statements ) {
Map<String, Class<?>> typeByVariableName = new HashMap<>();
for (Statement statement : statements) {
if ( statement instanceof ExpressionStmt ) {
Expression expression = ( ( ExpressionStmt ) statement ).getExpression();
if ( expression instanceof VariableDeclarationExpr ) {
VariableDeclarationExpr varExpression = ( VariableDeclarationExpr ) expression;
@Nullable Class<?> type = typeOf( varExpression.getType() );
if ( type != null ) {
for (VariableDeclarator var : varExpression.getVars()) {
typeByVariableName.put( var.getId().getName(), type );
}
}
}
}
}
return typeByVariableName;
}
示例2: printArguments
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
private void printArguments(final NodeList<Expression> args, final Void arg) {
printer.print("(");
Position cursorRef = printer.getCursor();
if (!isNullOrEmpty(args)) {
for (final Iterator<Expression> i = args.iterator(); i.hasNext(); ) {
final Expression e = i.next();
e.accept(this, arg);
if (i.hasNext()) {
printer.print(",");
if (configuration.isColumnAlignParameters()) {
printer.wrapToColumn(cursorRef.column);
} else {
printer.print(" ");
}
}
}
}
printer.print(")");
}
示例3: resolveTypesUsingImports
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
/**
* Resolve all the types in the expression.
* This will replace the Class with the full qualified name using the template imports.
* @param expression A Java expression from the Template
*/
private void resolveTypesUsingImports(Expression expression)
{
if (expression instanceof NodeWithType)
{
NodeWithType nodeWithType = ((NodeWithType) expression);
nodeWithType.setType(getQualifiedName(nodeWithType.getType()));
}
// Recurse downward in the expression
expression
.getChildNodes()
.stream()
.filter(Expression.class::isInstance)
.map(Expression.class::cast)
.forEach(this::resolveTypesUsingImports);
}
示例4: resolveStaticMethodsUsingImports
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
/**
* Resolve static method calls using static imports
* @param expression The expression to resolve
*/
private void resolveStaticMethodsUsingImports(Expression expression)
{
if (expression instanceof MethodCallExpr)
{
MethodCallExpr methodCall = ((MethodCallExpr) expression);
String methodName = methodCall.getName().getIdentifier();
if (!methodCall.getScope().isPresent() && context.hasStaticMethod(methodName))
{
methodCall.setName(context.getFullyQualifiedNameForMethodName(methodName));
}
}
// Recurse downward in the expression
expression
.getChildNodes()
.stream()
.filter(Expression.class::isInstance)
.map(Expression.class::cast)
.forEach(this::resolveStaticMethodsUsingImports);
}
示例5: findExpressionParameters
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
/**
* Find all the parameters this expression depends on.
* This is either the local variables (from a v-for loop) or the $event variable.
* @param expression An expression from the Template
* @param parameters The parameters this expression depends on
*/
private void findExpressionParameters(Expression expression, List<VariableInfo> parameters)
{
if (expression instanceof NameExpr)
{
NameExpr nameExpr = ((NameExpr) expression);
if ("$event".equals(nameExpr.getNameAsString()))
processEventParameter(expression, nameExpr, parameters);
else
processNameExpression(expression, nameExpr, parameters);
}
expression
.getChildNodes()
.stream()
.filter(Expression.class::isInstance)
.map(Expression.class::cast)
.forEach(exp -> findExpressionParameters(exp, parameters));
}
示例6: processEventParameter
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
/**
* Process the $event variable passed on v-on. This variable must have a valid cast in front.
* @param expression The currently processed expression
* @param nameExpr The variable we are processing
* @param parameters The parameters this expression depends on
*/
private void processEventParameter(Expression expression, NameExpr nameExpr,
List<VariableInfo> parameters)
{
if (nameExpr.getParentNode().isPresent() && nameExpr
.getParentNode()
.get() instanceof CastExpr)
{
CastExpr castExpr = (CastExpr) nameExpr.getParentNode().get();
parameters.add(new VariableInfo(castExpr.getType().toString(), "$event"));
}
else
{
throw new TemplateExpressionException(
"\"$event\" should always be casted to it's intended type. Example: @click=\"doSomething((NativeEvent) $event)\".",
expression.toString(),
context);
}
}
示例7: solve
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
private void solve(Node node) {
if (node instanceof ClassOrInterfaceDeclaration) {
solveTypeDecl((ClassOrInterfaceDeclaration) node);
} else if (node instanceof Expression) {
if ((getParentNode(node) instanceof ImportDeclaration) || (getParentNode(node) instanceof Expression)
|| (getParentNode(node) instanceof MethodDeclaration)
|| (getParentNode(node) instanceof PackageDeclaration)) {
// skip
} else if ((getParentNode(node) instanceof Statement) || (getParentNode(node) instanceof VariableDeclarator)) {
try {
ResolvedType ref = JavaParserFacade.get(typeSolver).getType(node);
out.println(" Line " + node.getRange().get().begin.line + ") " + node + " ==> " + ref.describe());
ok++;
} catch (UnsupportedOperationException upe) {
unsupported++;
err.println(upe.getMessage());
throw upe;
} catch (RuntimeException re) {
ko++;
err.println(re.getMessage());
throw re;
}
}
}
}
示例8: visit
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
@Override public Node visit(final MethodCallExpr n, final A arg) {
if (n.getScope() != null) {
n.setScope((Expression) n.getScope().accept(this, arg));
}
final List<Type> typeArgs = n.getTypeArgs();
if (typeArgs != null) {
for (int i = 0; i < typeArgs.size(); i++) {
typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg));
}
removeNulls(typeArgs);
}
final List<Expression> args = n.getArgs();
if (args != null) {
for (int i = 0; i < args.size(); i++) {
args.set(i, (Expression) args.get(i).accept(this, arg));
}
removeNulls(args);
}
return n;
}
示例9: solve
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
private void solve(Node node) {
if (node instanceof ClassOrInterfaceDeclaration) {
solveTypeDecl((ClassOrInterfaceDeclaration) node);
} else if (node instanceof Expression) {
if ((getParentNode(node) instanceof ImportDeclaration) || (getParentNode(node) instanceof Expression)
|| (getParentNode(node) instanceof MethodDeclaration)
|| (getParentNode(node) instanceof PackageDeclaration)) {
// skip
} else if ((getParentNode(node) instanceof Statement) || (getParentNode(node) instanceof VariableDeclarator)) {
try {
Type ref = JavaParserFacade.get(typeSolver).getType(node);
out.println(" Line " + node.getRange().get().begin.line + ") " + node + " ==> " + ref.describe());
ok++;
} catch (UnsupportedOperationException upe) {
unsupported++;
err.println(upe.getMessage());
throw upe;
} catch (RuntimeException re) {
ko++;
err.println(re.getMessage());
throw re;
}
}
}
}
示例10: solveSymbolAsValue
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
@Override
public Optional<Value> solveSymbolAsValue(String name, TypeSolver typeSolver) {
for (Expression expr : wrappedNode.getResources()) {
if (expr instanceof VariableDeclarationExpr) {
for (VariableDeclarator v : ((VariableDeclarationExpr)expr).getVariables()) {
if (v.getName().getIdentifier().equals(name)) {
JavaParserSymbolDeclaration decl = JavaParserSymbolDeclaration.localVar(v, typeSolver);
return Optional.of(Value.from(decl));
}
}
}
}
if (getParentNode(wrappedNode) instanceof BlockStmt) {
return StatementContext.solveInBlockAsValue(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbolAsValue(name, typeSolver);
}
}
示例11: visit
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
@Override
public Node visit(ExplicitConstructorInvocationStmt _n, Object _arg) {
List<Type<?>> typeArguments_ = visit(_n.getTypeArguments(), _arg);
Expression expr_ = cloneNodes(_n.getExpr(), _arg);
List<Expression> args_ = visit(_n.getArgs(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ExplicitConstructorInvocationStmt r = new ExplicitConstructorInvocationStmt(
_n.getRange(),
typeArguments_,
_n.isThis(),
expr_,
args_
);
r.setComment(comment);
return r;
}
示例12: visit
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
@Override
public void visit(final TryStmt n, final Void arg) {
if (canAddNewLine(n)) printer.println();
printJavaComment(n.getComment(), arg);
printer.print("try ");
if (!n.getResources().isEmpty()) {
printer.print("(");
Iterator<Expression> resources = n.getResources().iterator();
boolean first = true;
while (resources.hasNext()) {
resources.next().accept(this, arg);
if (resources.hasNext()) {
printer.print(";");
printer.println();
if (first) {
printer.indent();
}
}
first = false;
}
if (n.getResources().size() > 1) {
printer.unindent();
}
printer.print(") ");
}
n.getTryBlock().accept(this, arg);
for (final CatchClause c : n.getCatchClauses()) {
c.accept(this, arg);
}
if (n.getFinallyBlock().isPresent()) {
printer.print(" finally ");
n.getFinallyBlock().get().accept(this, arg);
}
if (getNext(n) != null) printer.println();
}
示例13: getVisitorFactory
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
@Override
public Function<PrettyPrinterConfiguration, PrettyPrintVisitor> getVisitorFactory() {
return configuration -> new PrettyPrintVisitor(configuration) {
@Override
public void visit(ArrayInitializerExpr n, Void arg) {
if (arrayLiteralMembersOnSeparateLines) {
if (configuration.isPrintJavaDoc()) {
n.getComment().ifPresent(c -> c.accept(this, arg));
}
printer.print("{");
if (!isNullOrEmpty(n.getValues())) {
printer.println();
printer.indent();
for (final Iterator<Expression> i = n.getValues().iterator(); i.hasNext(); ) {
final Expression expr = i.next();
expr.accept(this, arg);
if (i.hasNext()) {
printer.println(",");
}
}
printer.println();
printer.unindent();
}
printer.print("}");
} else {
super.visit(n, arg);
}
}
};
}
示例14: processJavaExpression
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
/**
* Process the given string as a Java expression.
* @param expressionString A valid Java expression
* @return A processed expression, should be placed in the HTML in place of the original
* expression
*/
private TemplateExpression processJavaExpression(String expressionString)
{
Expression expression;
try
{
expression = JavaParser.parseExpression(expressionString);
}
catch (ParseProblemException parseException)
{
throw new TemplateExpressionException(
"Couldn't parse Expression, make sure it is valid Java.",
expressionString,
context,
parseException);
}
resolveTypesUsingImports(expression);
resolveStaticMethodsUsingImports(expression);
checkMethodNames(expression);
// Find the parameters used by the expression
List<VariableInfo> expressionParameters = new LinkedList<>();
findExpressionParameters(expression, expressionParameters);
// If there is a cast first, we use this as the type of our expression
if (currentProp == null)
expression = getTypeFromCast(expression);
// Update the expression as it might have been changed
expressionString = expression.toString();
// Add the resulting expression to our result
return result.addExpression(expressionString,
currentExpressionReturnType,
currentProp == null,
expressionParameters);
}
示例15: getLeftmostExpression
import com.github.javaparser.ast.expr.Expression; //导入依赖的package包/类
private Expression getLeftmostExpression(Expression expression)
{
if (expression instanceof BinaryExpr)
return getLeftmostExpression(((BinaryExpr) expression).getLeft());
return expression;
}