本文整理汇总了Java中com.github.javaparser.ast.expr.NameExpr类的典型用法代码示例。如果您正苦于以下问题:Java NameExpr类的具体用法?Java NameExpr怎么用?Java NameExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了NameExpr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:Axellience,项目名称:vue-gwt,代码行数:25,代码来源:TemplateParser.java
示例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);
}
}
开发者ID:Axellience,项目名称:vue-gwt,代码行数:25,代码来源:TemplateParser.java
示例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);
}
}
开发者ID:hubrick,项目名称:raml-maven-plugin,代码行数:26,代码来源:SpringWebValidatorMojo.java
示例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;
}
开发者ID:hubrick,项目名称:raml-maven-plugin,代码行数:24,代码来源:SpringWebValidatorMojo.java
示例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);
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:23,代码来源:MethodDeclaration.java
示例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());
}
开发者ID:BenDol,项目名称:Databind,代码行数:26,代码来源:JavaParserUtils.java
示例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());
}
开发者ID:BenDol,项目名称:Databind,代码行数:26,代码来源:NameUtil.java
示例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;
}
开发者ID:BenDol,项目名称:Databind,代码行数:17,代码来源:TypeUtil.java
示例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;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:34,代码来源:FieldDeclaration.java
示例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);
}
}
开发者ID:Axellience,项目名称:vue-gwt,代码行数:34,代码来源:TemplateParser.java
示例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));
});
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:42,代码来源:BaseInfoComposite.java
示例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;
}
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:36,代码来源:ClassCreator.java
示例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;
}
开发者ID:renatoathaydes,项目名称:osgiaas,代码行数:38,代码来源:LastStatementTypeDiscoverer.java
示例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));
}
}
开发者ID:fjalvingh,项目名称:domui,代码行数:9,代码来源:ColumnWrapper.java
示例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);
}
开发者ID:fjalvingh,项目名称:domui,代码行数:11,代码来源:ColumnWrapper.java
示例16: staticImportsAreFilteredOut
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
@Test
public void staticImportsAreFilteredOut() {
ImportDeclaration staticImport = new ImportDeclaration(UNKNOWN, new NameExpr("static java.util.Collections.singletonList"), true, false);
CompilationUnit compilationUnit = new CompilationUnit(new PackageDeclaration(new NameExpr("io.github.theangrydev.fluentbdd.assertjgenerator")), singletonList(staticImport), emptyList());
assertThat(packageNameByClassName(compilationUnit, DEFAULT_PACKAGE_NAME).packageName("singletonList")).isEqualTo(DEFAULT_PACKAGE_NAME);
}
开发者ID:theangrydev,项目名称:fluent-bdd,代码行数:9,代码来源:PackageNameByClassNameTest.java
示例17: canLookUpPackageNameByClassName
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
@Test
public void canLookUpPackageNameByClassName() {
ImportDeclaration staticImport = new ImportDeclaration(UNKNOWN, new NameExpr("org.assertj.core.api.filter.Filters"), false, false);
CompilationUnit compilationUnit = new CompilationUnit(new PackageDeclaration(new NameExpr("io.github.theangrydev.fluentbdd.assertjgenerator")), singletonList(staticImport), emptyList());
assertThat(packageNameByClassName(compilationUnit, DEFAULT_PACKAGE_NAME).packageName("Filters")).isEqualTo("org.assertj.core.api.filter");
}
开发者ID:theangrydev,项目名称:fluent-bdd,代码行数:9,代码来源:PackageNameByClassNameTest.java
示例18: visit
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
@Override
public void visit(final NameExpr n, final Object arg) {
printer.printLn("NameExpr");
printJavaComment(n.getComment(), arg);
printer.print(n.getName());
printOrphanCommentsEnding(n);
}
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:9,代码来源:ASTDumpVisitor.java
示例19: visit
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
@Override
public Node visit(NormalAnnotationExpr _n, Object _arg) {
NameExpr name = cloneNodes(_n.getName(), _arg);
List<MemberValuePair> pairs = visit(_n.getPairs(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
NormalAnnotationExpr r = new NormalAnnotationExpr(
_n.getRange(),
name, pairs
);
r.setComment(comment);
return r;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:14,代码来源:CloneVisitor.java
示例20: findNameExpression
import com.github.javaparser.ast.expr.NameExpr; //导入依赖的package包/类
public static NameExpr findNameExpression(Node node, String name) {
if (node instanceof NameExpr) {
NameExpr nameExpr = (NameExpr) node;
if (nameExpr.getName() != null && nameExpr.getName().getId().equals(name)) {
return nameExpr;
}
}
for (Node child : node.getChildNodes()) {
NameExpr res = findNameExpression(child, name);
if (res != null) {
return res;
}
}
return null;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:16,代码来源:Navigator.java
注:本文中的com.github.javaparser.ast.expr.NameExpr类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论