Logo Search packages:      
Sourcecode: janino version File versions  Download package

IClass.IInvocable org::codehaus::janino::UnitCompiler::findMostSpecificIInvocable ( Locatable  l,
final IInvocable[]  iInvocables,
Rvalue[]  arguments 
) throws CompileException [inline, private]

Determine the arguments' types, determine the applicable invocables and choose the most specific invocable.

Parameters:
iInvocables Length must be greater than zero
Returns:
The selected IClass.IInvocable
Exceptions:
CompileException 

Definition at line 5715 of file UnitCompiler.java.

References org::codehaus::janino::IClass::getDeclaringIClass(), and org::codehaus::janino::IClass::INT.

                              {

        // Determine arguments' types.
        final IClass[] argumentTypes = new IClass[arguments.length];
        for (int i = 0; i < arguments.length; ++i) {
            argumentTypes[i] = this.getType(arguments[i]);
        }

        IInvocable ii = this.findMostSpecificIInvocable(l, iInvocables, argumentTypes, false);
        if (ii != null) return ii;

        ii = this.findMostSpecificIInvocable(l, iInvocables, argumentTypes, true);
        if (ii != null) return ii;
        
        // Report a nice compile error.
        StringBuffer sb = new StringBuffer("No applicable constructor/method found for ");
        if (argumentTypes.length == 0) {
            sb.append("zero actual parameters");
        } else {
            sb.append("actual parameters \"").append(argumentTypes[0]);
            for (int i = 1; i < argumentTypes.length; ++i) {
                sb.append(", ").append(argumentTypes[i]);
            }
            sb.append("\"");
        }
        sb.append("; candidates are: ").append('"' + iInvocables[0].toString() + '"');
        for (int i = 1; i < iInvocables.length; ++i) {
            sb.append(", ").append('"' + iInvocables[i].toString() + '"');
        }
        this.compileError(sb.toString(), l.getLocation());

        // Well, returning a "fake" IInvocable is a bit tricky, because the iInvocables
        // can be of different types.
        if (iInvocables[0] instanceof IClass.IConstructor) {
            return iInvocables[0].getDeclaringIClass().new IConstructor() {
                public IClass[] getParameterTypes()   { return argumentTypes; }
                public Access   getAccess()           { return Access.PUBLIC; }
                public IClass[] getThrownExceptions() { return new IClass[0]; }
            };
        } else
        if (iInvocables[0] instanceof IClass.IMethod) {
            return iInvocables[0].getDeclaringIClass().new IMethod() {
                public boolean  isStatic()            { return true; }
                public boolean  isAbstract()          { return false; }
                public IClass   getReturnType()       { return IClass.INT; }
                public String   getName()             { return ((IClass.IMethod) iInvocables[0]).getName(); }
                public Access   getAccess()           { return Access.PUBLIC; }
                public IClass[] getParameterTypes()   { return argumentTypes; }
                public IClass[] getThrownExceptions() { return new IClass[0]; }
            };
        } else
        {
            return iInvocables[0];
        }
    }


Generated by  Doxygen 1.6.0   Back to index