本文整理汇总了Java中com.github.javaparser.ast.expr.NameExpr.getName方法的典型用法代码示例。如果您正苦于以下问题:Java NameExpr.getName方法的具体用法?Java NameExpr.getName怎么用?Java NameExpr.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.expr.NameExpr
的用法示例。
在下文中一共展示了NameExpr.getName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: getClassOrInterfaceType
import com.github.javaparser.ast.expr.NameExpr; //导入方法依赖的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());
}
示例3: visit
import com.github.javaparser.ast.expr.NameExpr; //导入方法依赖的package包/类
@Override
public Node visit(NameExpr _n, Object _arg) {
Comment comment = cloneNodes(_n.getComment(), _arg);
NameExpr r = new NameExpr(
_n.getRange(),
_n.getName()
);
r.setComment(comment);
return r;
}
示例4: 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;
}
示例5: parseExpression
import com.github.javaparser.ast.expr.NameExpr; //导入方法依赖的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;
}
}