com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration Java Examples

The following examples show how to use com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration. 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: CommentHelper.java    From apigcc with MIT License 5 votes vote down vote up
/**
 * 解析属性的注释
 * @param it
 * @return
 */
public static Optional<Comment> getComment(ResolvedFieldDeclaration it) {
    if (it instanceof JavaParserFieldDeclaration) {
        FieldDeclaration wrappedNode = ((JavaParserFieldDeclaration) it).getWrappedNode();
        return wrappedNode.getComment();
    }
    if (it instanceof JavaParserClassDeclaration) {
        JavaParserClassDeclaration classDeclaration = (JavaParserClassDeclaration) it;
        return classDeclaration.getWrappedNode().getComment();
    }
    return Optional.empty();
}
 
Example #2
Source File: ValidationHelper.java    From apigcc with MIT License 5 votes vote down vote up
public static List<String> getValidations(ResolvedFieldDeclaration declaredField) {
    List<String> result = new ArrayList<>();
    if (declaredField instanceof JavaParserFieldDeclaration) {
        FieldDeclaration fieldDeclaration = ((JavaParserFieldDeclaration) declaredField).getWrappedNode();
        for (String value : values) {
            Optional<AnnotationExpr> optional = fieldDeclaration.getAnnotationByName(value);
            if (optional.isPresent()) {
                result.add(value);
            }
        }
    }
    return result;
}
 
Example #3
Source File: FieldHelper.java    From apigcc with MIT License 5 votes vote down vote up
public static Optional<Object> getInitializerValue(ResolvedFieldDeclaration declaredField){
    if(declaredField instanceof JavaParserFieldDeclaration){
        JavaParserFieldDeclaration field = (JavaParserFieldDeclaration) declaredField;
        return field.getVariableDeclarator().getInitializer().map(ExpressionHelper::getValue);
    }
    return Optional.empty();
}
 
Example #4
Source File: JsonPropertyHelper.java    From apigcc with MIT License 5 votes vote down vote up
/**
 * 获取Json 别名
 *
 * @param declaredField
 * @return
 */
public static Optional<String> getJsonName(ResolvedFieldDeclaration declaredField) {
    if (declaredField instanceof JavaParserFieldDeclaration) {
        FieldDeclaration fieldDeclaration = ((JavaParserFieldDeclaration) declaredField).getWrappedNode();
        return OptionalHelper.any(
                AnnotationHelper.string(fieldDeclaration, ANNOTATION_JSON_PROPERTY, "value"),
                AnnotationHelper.string(fieldDeclaration, ANNOTATION_JSON_FIELD, "name"),
                AnnotationHelper.string(fieldDeclaration, ANNOTATION_SERIALIZED_NAME, "value")
        );
    }
    return Optional.empty();
}
 
Example #5
Source File: JavaParserUtil.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * @param type
 * 		Resolved field declaration.
 *
 * @return Descriptor of the resolved field. May be {@code null}.
 */
public static String getDescriptor(ResolvedFieldDeclaration type) {
	String desc = null;
	try {
		desc =	getDescriptor(type.getType());
	} catch(UnsolvedSymbolException ex) {
		if (type instanceof JavaParserFieldDeclaration) {
			desc = getDescriptor(((JavaParserFieldDeclaration) type).getWrappedNode().getCommonType());
		}
	} catch(UnsupportedOperationException e) { /* Ignored */ }
	return desc;
}
 
Example #6
Source File: ParserTypeUtil.java    From JRemapper with MIT License 5 votes vote down vote up
/**
 * @param type
 * 		Resolved field declaration.
 *
 * @return Descriptor of the resolved field.
 */
public static String getResolvedFieldDesc(ResolvedFieldDeclaration type) {
	String desc = null;
	try {
		desc =	ParserTypeUtil.getDescriptor(type.getType());
	} catch(UnsolvedSymbolException ex) {
		if (type instanceof JavaParserFieldDeclaration) {
			desc = ParserTypeUtil.getDescriptor(((JavaParserFieldDeclaration) type).getWrappedNode().getCommonType());
		}
	} catch(UnsupportedOperationException e) {}
	return desc;
}