Search in sources :

Example 1 with ClosureSignatureHint

use of groovy.transform.stc.ClosureSignatureHint in project groovy-core by groovy.

the class StaticTypeCheckingVisitor method getSignaturesFromHint.

private List<ClassNode[]> getSignaturesFromHint(final ClosureExpression expression, final MethodNode selectedMethod, final Expression hintClass, final Expression options) {
    // initialize hints
    List<ClassNode[]> closureSignatures = null;
    try {
        ClassLoader transformLoader = getTransformLoader();
        @SuppressWarnings("unchecked") Class<? extends ClosureSignatureHint> hint = (Class<? extends ClosureSignatureHint>) transformLoader.loadClass(hintClass.getText());
        ClosureSignatureHint hintInstance = hint.newInstance();
        closureSignatures = hintInstance.getClosureSignatures(selectedMethod instanceof ExtensionMethodNode ? ((ExtensionMethodNode) selectedMethod).getExtensionMethodNode() : selectedMethod, typeCheckingContext.source, typeCheckingContext.compilationUnit, convertToStringArray(options), expression);
    } catch (ClassNotFoundException e) {
        throw new GroovyBugError(e);
    } catch (InstantiationException e) {
        throw new GroovyBugError(e);
    } catch (IllegalAccessException e) {
        throw new GroovyBugError(e);
    }
    return closureSignatures;
}
Also used : ClosureSignatureHint(groovy.transform.stc.ClosureSignatureHint) GroovyBugError(org.codehaus.groovy.GroovyBugError)

Example 2 with ClosureSignatureHint

use of groovy.transform.stc.ClosureSignatureHint in project groovy by apache.

the class StaticTypeCheckingVisitor method getSignaturesFromHint.

private List<ClassNode[]> getSignaturesFromHint(final MethodNode mn, final Expression hintType, final Expression options, final ASTNode usage) {
    // load hint class using compiler's classloader
    String hintTypeName = hintType.getText();
    try {
        @SuppressWarnings("unchecked") Class<? extends ClosureSignatureHint> hintClass = (Class<? extends ClosureSignatureHint>) getTransformLoader().loadClass(hintTypeName);
        List<ClassNode[]> closureSignatures = hintClass.getDeclaredConstructor().newInstance().getClosureSignatures(mn instanceof ExtensionMethodNode ? ((ExtensionMethodNode) mn).getExtensionMethodNode() : mn, typeCheckingContext.getSource(), typeCheckingContext.getCompilationUnit(), convertToStringArray(options), usage);
        return closureSignatures;
    } catch (ReflectiveOperationException e) {
        throw new GroovyBugError(e);
    }
}
Also used : ClosureSignatureHint(groovy.transform.stc.ClosureSignatureHint) GroovyBugError(org.codehaus.groovy.GroovyBugError) ClassHelper.getNextSuperClass(org.codehaus.groovy.ast.ClassHelper.getNextSuperClass) StaticTypeCheckingSupport.toMethodParametersString(org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.toMethodParametersString) StaticTypeCheckingSupport.isParameterizedWithString(org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isParameterizedWithString) StaticTypeCheckingSupport.isParameterizedWithGStringOrGStringString(org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isParameterizedWithGStringOrGStringString)

Example 3 with ClosureSignatureHint

use of groovy.transform.stc.ClosureSignatureHint in project groovy by apache.

the class StaticTypeCheckingVisitor method getSignaturesFromHint.

private List<ClassNode[]> getSignaturesFromHint(final ClosureExpression expression, final MethodNode selectedMethod, final Expression hintClass, final Expression options) {
    // initialize hints
    List<ClassNode[]> closureSignatures;
    try {
        ClassLoader transformLoader = getTransformLoader();
        @SuppressWarnings("unchecked") Class<? extends ClosureSignatureHint> hint = (Class<? extends ClosureSignatureHint>) transformLoader.loadClass(hintClass.getText());
        ClosureSignatureHint hintInstance = hint.newInstance();
        closureSignatures = hintInstance.getClosureSignatures(selectedMethod instanceof ExtensionMethodNode ? ((ExtensionMethodNode) selectedMethod).getExtensionMethodNode() : selectedMethod, typeCheckingContext.source, typeCheckingContext.compilationUnit, convertToStringArray(options), expression);
    } catch (ClassNotFoundException e) {
        throw new GroovyBugError(e);
    } catch (InstantiationException e) {
        throw new GroovyBugError(e);
    } catch (IllegalAccessException e) {
        throw new GroovyBugError(e);
    }
    return closureSignatures;
}
Also used : ClosureSignatureHint(groovy.transform.stc.ClosureSignatureHint) GroovyBugError(org.codehaus.groovy.GroovyBugError)

Aggregations

ClosureSignatureHint (groovy.transform.stc.ClosureSignatureHint)3 GroovyBugError (org.codehaus.groovy.GroovyBugError)3 ClassHelper.getNextSuperClass (org.codehaus.groovy.ast.ClassHelper.getNextSuperClass)1 StaticTypeCheckingSupport.isParameterizedWithGStringOrGStringString (org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isParameterizedWithGStringOrGStringString)1 StaticTypeCheckingSupport.isParameterizedWithString (org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isParameterizedWithString)1 StaticTypeCheckingSupport.toMethodParametersString (org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.toMethodParametersString)1