use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method getResultUpdaterSupportedExpression.
/**
* Create a <b>resultUpdater</b> <code>CastExpr</code>
* @param normalizationMethod
* @return
*/
static MethodReferenceExpr getResultUpdaterSupportedExpression(final RegressionModel.NormalizationMethod normalizationMethod) {
final String thisExpressionMethodName = String.format("update%sResult", normalizationMethod.name());
final CastExpr castExpr = new CastExpr();
final String doubleClassName = Double.class.getSimpleName();
final ClassOrInterfaceType consumerType = getTypedClassOrInterfaceTypeByTypeNames(SerializableFunction.class.getCanonicalName(), Arrays.asList(doubleClassName, doubleClassName));
castExpr.setType(consumerType);
castExpr.setExpression(KiePMMLRegressionTable.class.getSimpleName());
final MethodReferenceExpr toReturn = new MethodReferenceExpr();
toReturn.setScope(castExpr);
toReturn.setIdentifier(thisExpressionMethodName);
return toReturn;
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.
the class KiePMMLScorecardModelFactory method setConstructor.
static void setConstructor(final ScorecardCompilationDTO compilationDTO, final ClassOrInterfaceDeclaration modelTemplate, final String fullCharacteristicsClassName) {
KiePMMLModelFactoryUtils.init(compilationDTO, modelTemplate);
final ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, modelTemplate.getName())));
final BlockStmt body = constructorDeclaration.getBody();
final ExplicitConstructorInvocationStmt superStatement = CommonCodegenUtils.getExplicitConstructorInvocationStmt(body).orElseThrow(() -> new KiePMMLException(String.format(MISSING_CONSTRUCTOR_IN_BODY, body)));
ClassOrInterfaceType characteristicsClass = parseClassOrInterfaceType(fullCharacteristicsClassName);
ObjectCreationExpr characteristicsReference = new ObjectCreationExpr();
characteristicsReference.setType(characteristicsClass);
superStatement.setArgument(2, characteristicsReference);
superStatement.setArgument(3, getExpressionForObject(compilationDTO.getInitialScore()));
superStatement.setArgument(4, getExpressionForObject(compilationDTO.isUseReasonCodes()));
REASONCODE_ALGORITHM reasoncodeAlgorithm = compilationDTO.getREASONCODE_ALGORITHM();
NameExpr reasonCodeExpr = new NameExpr(REASONCODE_ALGORITHM.class.getName() + "." + reasoncodeAlgorithm.name());
superStatement.setArgument(5, reasonCodeExpr);
superStatement.setArgument(6, getExpressionForObject(compilationDTO.getBaselineScore()));
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class JointJavacJavaParserVisitor method visitMemberSelect.
@Override
public Void visitMemberSelect(MemberSelectTree javacTree, Node javaParserNode) {
if (javaParserNode instanceof FieldAccessExpr) {
FieldAccessExpr node = (FieldAccessExpr) javaParserNode;
processMemberSelect(javacTree, node);
javacTree.getExpression().accept(this, node.getScope());
} else if (javaParserNode instanceof Name) {
Name node = (Name) javaParserNode;
processMemberSelect(javacTree, node);
assert node.getQualifier().isPresent();
javacTree.getExpression().accept(this, node.getQualifier().get());
} else if (javaParserNode instanceof ClassOrInterfaceType) {
ClassOrInterfaceType node = (ClassOrInterfaceType) javaParserNode;
processMemberSelect(javacTree, node);
assert node.getScope().isPresent();
javacTree.getExpression().accept(this, node.getScope().get());
} else if (javaParserNode instanceof ClassExpr) {
ClassExpr node = (ClassExpr) javaParserNode;
processMemberSelect(javacTree, node);
javacTree.getExpression().accept(this, node.getType());
} else if (javaParserNode instanceof ThisExpr) {
ThisExpr node = (ThisExpr) javaParserNode;
processMemberSelect(javacTree, node);
assert node.getTypeName().isPresent();
javacTree.getExpression().accept(this, node.getTypeName().get());
} else if (javaParserNode instanceof SuperExpr) {
SuperExpr node = (SuperExpr) javaParserNode;
processMemberSelect(javacTree, node);
assert node.getTypeName().isPresent();
javacTree.getExpression().accept(this, node.getTypeName().get());
} else {
throwUnexpectedNodeType(javacTree, javaParserNode);
}
return null;
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class AnnotationFileParser method annotate.
/**
* Add to formal parameter {@code atype}:
*
* <ol>
* <li>the annotations from {@code typeDef}, and
* <li>any type annotations that parsed as declaration annotations (i.e., type annotations in
* {@code declAnnos}).
* </ol>
*
* @param atype annotated type to which to add annotations
* @param typeDef parsed type
* @param declAnnos annotations stored on the declaration of the variable with this type, or null
* @param astNode where to report errors
*/
private void annotate(AnnotatedTypeMirror atype, Type typeDef, @Nullable NodeList<AnnotationExpr> declAnnos, NodeWithRange<?> astNode) {
if (atype.getKind() == TypeKind.ARRAY) {
if (typeDef instanceof ReferenceType) {
annotateAsArray((AnnotatedArrayType) atype, (ReferenceType) typeDef, declAnnos, astNode);
} else {
warn(astNode, "expected ReferenceType but found: " + typeDef);
}
return;
}
clearAnnotations(atype, typeDef);
// Primary annotations for the type of a variable declaration are not stored in typeDef, but
// rather as declaration annotations (passed as declAnnos to this method). But, if typeDef
// is not the type of a variable, then the primary annotations are stored in typeDef.
NodeList<AnnotationExpr> primaryAnnotations;
if (typeDef.getAnnotations().isEmpty() && declAnnos != null) {
primaryAnnotations = declAnnos;
} else {
primaryAnnotations = typeDef.getAnnotations();
}
if (atype.getKind() != TypeKind.WILDCARD) {
// The primary annotation on a wildcard applies to the super or extends bound and
// are added below.
annotate(atype, primaryAnnotations, astNode);
}
switch(atype.getKind()) {
case DECLARED:
ClassOrInterfaceType declType = unwrapDeclaredType(typeDef);
if (declType == null) {
break;
}
AnnotatedDeclaredType adeclType = (AnnotatedDeclaredType) atype;
// Process type arguments.
if (declType.getTypeArguments().isPresent() && !declType.getTypeArguments().get().isEmpty() && !adeclType.getTypeArguments().isEmpty()) {
if (declType.getTypeArguments().get().size() != adeclType.getTypeArguments().size()) {
warn(astNode, String.format("Mismatch in type argument size between %s (%d) and %s (%d)", declType, declType.getTypeArguments().get().size(), adeclType, adeclType.getTypeArguments().size()));
break;
}
for (int i = 0; i < declType.getTypeArguments().get().size(); ++i) {
annotate(adeclType.getTypeArguments().get(i), declType.getTypeArguments().get().get(i), null, astNode);
}
}
break;
case WILDCARD:
AnnotatedWildcardType wildcardType = (AnnotatedWildcardType) atype;
// Ensure that the file also has a wildcard type, report an error otherwise
if (!typeDef.isWildcardType()) {
// We throw an error here, as otherwise we are just getting a generic cast error
// on the very next line.
warn(astNode, "Wildcard type <" + atype + "> does not match type in stubs file" + filename + ": <" + typeDef + ">" + " while parsing " + typeBeingParsed);
return;
}
WildcardType wildcardDef = (WildcardType) typeDef;
if (wildcardDef.getExtendedType().isPresent()) {
annotate(wildcardType.getExtendsBound(), wildcardDef.getExtendedType().get(), null, astNode);
annotate(wildcardType.getSuperBound(), primaryAnnotations, astNode);
} else if (wildcardDef.getSuperType().isPresent()) {
annotate(wildcardType.getSuperBound(), wildcardDef.getSuperType().get(), null, astNode);
annotate(wildcardType.getExtendsBound(), primaryAnnotations, astNode);
} else {
annotate(atype, primaryAnnotations, astNode);
}
break;
case TYPEVAR:
// Add annotations from the declaration of the TypeVariable
AnnotatedTypeVariable typeVarUse = (AnnotatedTypeVariable) atype;
Types typeUtils = processingEnv.getTypeUtils();
for (AnnotatedTypeVariable typePar : typeParameters) {
if (typeUtils.isSameType(typePar.getUnderlyingType(), atype.getUnderlyingType())) {
atypeFactory.replaceAnnotations(typePar.getUpperBound(), typeVarUse.getUpperBound());
atypeFactory.replaceAnnotations(typePar.getLowerBound(), typeVarUse.getLowerBound());
}
}
break;
default:
}
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class AnnotationTransferVisitor method visit.
@Override
public void visit(TypeParameter target, AnnotatedTypeMirror type) {
AnnotatedTypeVariable annotatedTypeVar = (AnnotatedTypeVariable) type;
NodeList<ClassOrInterfaceType> bounds = target.getTypeBound();
if (bounds.size() == 1) {
bounds.get(0).accept(this, annotatedTypeVar.getUpperBound());
}
}
Aggregations