当前位置: 首页>>代码示例>>Java>>正文


Java NameExpr.getName方法代码示例

本文整理汇总了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;
}
 
开发者ID:BenDol,项目名称:Databind,代码行数:17,代码来源:TypeUtil.java

示例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());
}
 
开发者ID:BenDol,项目名称:Databind,代码行数:23,代码来源:JavaParserUtils.java

示例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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:12,代码来源:CloneVisitor.java

示例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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:16,代码来源:Navigator.java

示例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;
    }
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:76,代码来源:Parser.java


注:本文中的com.github.javaparser.ast.expr.NameExpr.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。