com.github.javaparser.resolution.Resolvable Java Examples

The following examples show how to use com.github.javaparser.resolution.Resolvable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpressionHelper.java    From apigcc with MIT License 6 votes vote down vote up
/**
 * 解析表达式,获取表达式的值
 * TODO 更复杂的表达式解析
 * @param expr
 * @return
 */
public static Object getValue(Expression expr) {
    if (expr.isStringLiteralExpr()) {
        return expr.asStringLiteralExpr().getValue();
    }
    if (expr.isIntegerLiteralExpr()) {
        return expr.asIntegerLiteralExpr().getValue();
    }
    if (expr.isDoubleLiteralExpr()) {
        return expr.asDoubleLiteralExpr().getValue();
    }
    if (expr.isLongLiteralExpr()) {
        return expr.asLongLiteralExpr().getValue();
    }
    if (expr.isBooleanLiteralExpr()) {
        return expr.asBooleanLiteralExpr().getValue();
    }
    if (expr.isArrayInitializerExpr()) {
        return expr.asArrayInitializerExpr().getValues().stream().map(ExpressionHelper::getValue).collect(Collectors.toList());
    }
    if (expr instanceof Resolvable) {
        return String.valueOf(resolve((Resolvable) expr));
    }
    return expr.toString();
}
 
Example #2
Source File: ExpressionHelper.java    From apigcc with MIT License 6 votes vote down vote up
public static List<String> getStringValues(Expression expression){
    List<String> results = new ArrayList<>();
    if(expression.isStringLiteralExpr()){
        results.add(expression.asStringLiteralExpr().getValue());
    }else if(expression.isArrayInitializerExpr()) {
        NodeList<Expression> values = expression.asArrayInitializerExpr().getValues();
        for (Expression value : values) {
            results.addAll(getStringValues(value));
        }
    }else if(expression instanceof Resolvable){
        results.add(String.valueOf(resolve((Resolvable)expression)));
    }else{
        results.add(expression.toString());
    }
    return results;
}
 
Example #3
Source File: JavaParserUtil.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * @param code
 * 		Code wrapper.
 * @param pos
 * 		Position of caret.
 *
 * @return Node of supported type at position.
 */
private static Node getSelectedNode(SourceCode code, TwoDimensional.Position pos) {
	// Abort if no analyzed code to parse
	if (code == null)
		return null;
	// Get node at row/column
	Node node = code.getVerboseNodeAt(pos.getMajor() + 1, pos.getMinor());
	// Go up a level until node type is supported
	while(node != null) {
		if(node instanceof Resolvable || node instanceof InitializerDeclaration)
			break;
		Optional<Node> parent = node.getParentNode();
		if(!parent.isPresent())
			break;
		node = parent.get();
	}
	return node;
}
 
Example #4
Source File: ExpressionHelper.java    From apigcc with MIT License 5 votes vote down vote up
public static String getStringValue(Expression expression){
    if(expression.isStringLiteralExpr()){
        return expression.asStringLiteralExpr().getValue();
    }else if(expression.isArrayInitializerExpr()){
        NodeList<Expression> values = expression.asArrayInitializerExpr().getValues();
        if(values.size()>0){
            return getStringValue(values.get(0));
        }
    }else if(expression instanceof Resolvable){
        return String.valueOf(resolve((Resolvable)expression));
    }
    return expression.toString();
}