本文整理汇总了Java中com.github.javaparser.ast.expr.NameExpr类的典型用法代码示例。如果您正苦于以下问题:Java NameExpr类的具体用法?Java NameExpr怎么用?Java NameExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了NameExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findExpressionParameters
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的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));
}
示例2: processEventParameter
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的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);
}
}
示例3: diffNode
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
private void diffNode(final Node a, final Node aParent,
final Node b, final Node bParent,
final Consumer<Quintet<Node, Node, Node, Node, DiffStatus>> diffCallback) {
if (b == null) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISSING));
} else if (a instanceof NameExpr && !Objects.equals(((NameExpr) a).getName(), ((NameExpr) b).getName())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof FieldAccessExpr && !Objects.equals(((FieldAccessExpr) a).getFieldExpr(), ((FieldAccessExpr) b).getFieldExpr())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof LiteralExpr && !Objects.equals(a, b)) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof AnnotationExpr && !Objects.equals(((AnnotationExpr) a).getName().getName(), ((AnnotationExpr) b).getName().getName())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof Parameter && !Objects.equals(((Parameter) a).getType(), ((Parameter) b).getType())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof MethodDeclaration) {
final Iterator<Parameter> iSourceParameters = ((MethodDeclaration) b).getParameters().iterator();
for (Parameter parameter : ((MethodDeclaration) a).getParameters()) {
diffNode(parameter, a, iSourceParameters.hasNext() ? iSourceParameters.next() : null, b, diffCallback);
}
introspect(a, b, diffCallback);
} else {
introspect(a, b, diffCallback);
}
}
示例4: isIntrospectionRelevantNode
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
private boolean isIntrospectionRelevantNode(Node node) {
if (node instanceof Type && node.getParentNode() instanceof MethodDeclaration) {
return false;
}
if (node instanceof Parameter && node.getParentNode() instanceof MethodDeclaration) {
return false;
}
if (!(node instanceof AnnotationExpr) && node.getParentNode() instanceof BaseParameter) {
return false;
}
if (node instanceof NameExpr && node.getParentNode() instanceof AnnotationExpr) {
return false;
}
if (node.getParentNode() instanceof FieldAccessExpr) {
return false;
}
return true;
}
示例5: MethodDeclaration
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
public MethodDeclaration(Range range,
final EnumSet<Modifier> modifiers,
final List<AnnotationExpr> annotations,
final List<TypeParameter> typeParameters,
final Type elementType,
final List<ArrayBracketPair> arrayBracketPairsAfterElementType,
final NameExpr nameExpr,
final List<Parameter> parameters,
final List<ArrayBracketPair> arrayBracketPairsAfterParameterList,
final List<ReferenceType> throws_,
final BlockStmt body) {
super(range, annotations);
setModifiers(modifiers);
setTypeParameters(typeParameters);
setElementType(elementType);
setNameExpr(nameExpr);
setParameters(parameters);
setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType);
setArrayBracketPairsAfterParameterList(arrayBracketPairsAfterParameterList);
setThrows(throws_);
setBody(body);
}
示例6: isEqual
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
/**
* Indicates whether two {@link NameExpr} expressions are equal.
* <p>
* This method is necessary given {@link NameExpr} does not offer an equals
* method.
*
* @param o1 the first entry to compare (null is acceptable)
* @param o2 the second entry to compare (null is acceptable)
* @return true if and only if both entries are identical
*/
private static boolean isEqual(final NameExpr o1, final NameExpr o2) {
if (o1 == null && o2 == null) {
return true;
}
if (o1 == null && o2 != null) {
return false;
}
if (o1 != null && o2 == null) {
return false;
}
if (o1 != null && !o1.getName().equals(o2.getName())) {
return false;
}
return o1 != null && o1.toString().equals(o2.toString());
}
示例7: isEqual
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
/**
* Indicates whether two {@link NameExpr} expressions are equal.
* <p>
* This method is necessary given {@link NameExpr} does not offer an equals
* method.
*
* @param o1 the first entry to compare (null is acceptable)
* @param o2 the second entry to compare (null is acceptable)
* @return true if and only if both entries are identical
*/
public static boolean isEqual(final NameExpr o1, final NameExpr o2) {
if (o1 == null && o2 == null) {
return true;
}
if (o1 == null && o2 != null) {
return false;
}
if (o1 != null && o2 == null) {
return false;
}
if (o1 != null && !o1.getName().equals(o2.getName())) {
return false;
}
return o1 != null && o1.toString().equals(o2.toString());
}
示例8: determineQualifiedName
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
public static String determineQualifiedName(final CompilationUnit compilationUnit,
final NameExpr nameExpr) {
final ImportDeclaration importDeclaration = getImportDeclarationFor(
compilationUnit, nameExpr);
if (importDeclaration == null) {
if (JdkJavaType.isPartOfJavaLang(nameExpr.getName())) {
return "java.lang." + nameExpr.getName();
}
String unitPackage = compilationUnit.getPackage().getName().toString();
return unitPackage.equals("") ? nameExpr.getName()
: unitPackage + "." + nameExpr.getName();
}
return null;
}
示例9: createSetter
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
/**
* Create a setter for this field, <b>will only work if this field declares only 1 identifier and if this field is
* already added to a ClassOrInterfaceDeclaration</b>
*
* @return the {@link MethodDeclaration} created
* @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a
* class or enum
*/
public MethodDeclaration createSetter() {
if (getVariables().size() != 1)
throw new IllegalStateException("You can use this only when the field declares only 1 variable name");
ClassOrInterfaceDeclaration parentClass = getParentNodeOfType(ClassOrInterfaceDeclaration.class);
EnumDeclaration parentEnum = getParentNodeOfType(EnumDeclaration.class);
if ((parentClass == null && parentEnum == null) || (parentClass != null && parentClass.isInterface()))
throw new IllegalStateException(
"You can use this only when the field is attached to a class or an enum");
VariableDeclarator variable = getVariables().get(0);
String fieldName = variable.getId().getName();
String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length());
final MethodDeclaration setter;
if (parentClass != null)
setter = parentClass.addMethod("set" + fieldNameUpper, PUBLIC);
else
setter = parentEnum.addMethod("set" + fieldNameUpper, PUBLIC);
setter.setType(VOID_TYPE);
setter.getParameters().add(new Parameter(variable.getType(), new VariableDeclaratorId(fieldName)));
BlockStmt blockStmt2 = new BlockStmt();
setter.setBody(blockStmt2);
blockStmt2.addStatement(new AssignExpr(new NameExpr("this." + fieldName), new NameExpr(fieldName), Operator.assign));
return setter;
}
示例10: processNameExpression
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
/**
* Process a name expression to determine if it exists in the context.
* If it does, and it's a local variable (from a v-for) we add it to our parameters
* @param expression The currently processed expression
* @param nameExpr The variable we are processing
* @param parameters The parameters this expression depends on
*/
private void processNameExpression(Expression expression, NameExpr nameExpr,
List<VariableInfo> parameters)
{
String name = nameExpr.getNameAsString();
if (context.hasImport(name))
{
// This is a direct Class reference, we just replace with the fully qualified name
nameExpr.setName(context.getFullyQualifiedNameForClassName(name));
return;
}
VariableInfo variableInfo = context.findVariable(name);
if (variableInfo == null)
{
throw new TemplateExpressionException("Couldn't find variable/method \""
+ name
+ "\" in the Component.\nMake sure you didn't forget the @JsProperty/@JsMethod annotation or try rerunning your Annotation processor.",
expression.toString(),
context);
}
if (variableInfo instanceof LocalVariableInfo)
{
parameters.add(variableInfo);
}
}
示例11: start
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
/**
*
* 코드 분석 시작 처리.
* @작성자 : KYJ
* @작성일 : 2017. 2. 3.
*/
public void start() {
// 동적처리에 따라 API 함수 수정.
FileUtil.consumeJavaParser(targetFile, cu -> {
NameExpr name = cu.getPackage().getName();
lblPackage.setText(name.toString());
String importStatement = cu.getImports().stream().map(im -> im.getName().toString()).collect(Collectors.joining(","));
lblImports.setText(importStatement);
Service<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
new MethodVisitor(v -> {
methodData.add(v);
}).visit(cu, null);
return null;
}
};
}
};
service.start();
} , err ->{
LOGGER.error(ValueUtil.toString(err));
});
}
示例12: createCU
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
/**
* creates the compilation unit
*/
private static CompilationUnit createCU() {
CompilationUnit cu = new CompilationUnit();
// set the package
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test")));
// create the type declaration
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass");
ASTHelper.addTypeDeclaration(cu, type);
// create a method
MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "main");
method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC));
ASTHelper.addMember(type, method);
// add a parameter to the method
Parameter param = ASTHelper.createParameter(ASTHelper.createReferenceType("String", 0), "args");
param.setVarArgs(true);
ASTHelper.addParameter(method, param);
// add a body to the method
BlockStmt block = new BlockStmt();
method.setBody(block);
// add a statement do the method body
NameExpr clazz = new NameExpr("System");
FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
MethodCallExpr call = new MethodCallExpr(field, "println");
ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!"));
ASTHelper.addStmt(block, call);
return cu;
}
示例13: visit
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的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;
}
示例14: setPair
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
private void setPair(NormalAnnotationExpr ca, String name, String value, boolean quoted) {
MemberValuePair p = findAnnotationPair(ca, name);
if(null == p) {
ca.addPair(name, quoted ? "\"" + value + "\"" : value);
} else {
p.setValue(quoted ? new StringLiteralExpr(value) : new NameExpr(value));
}
}
示例15: visit
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
@Override public void visit(AssignExpr n, Void arg) {
if(n.getOperator().equals(Operator.ASSIGN)) {
Expression target = n.getTarget();
if(isOldFieldName(target.toString())) {
n.setTarget(new NameExpr(m_fieldName));
}
}
super.visit(n, arg);
}