Code Monkey home page Code Monkey logo

Comments (6)

gallandarakhneorg avatar gallandarakhneorg commented on August 15, 2024

Solution may be to change the code of FeatureCallCompiler:

    private static boolean isConstantExpression(JvmAnnotationReference reference) {
        for (final JvmAnnotationValue annotationValue: reference.getValues()) {
            if ("constantExpression".equals(annotationValue.getValueName())) {
                return ((JvmBooleanAnnotationValue) annotationValue).getValues().get(0).booleanValue();
            }
        }
        return false;
    }

    @Override
    protected void featureCalltoJavaExpression(final XAbstractFeatureCall call, ITreeAppendable output,
            boolean isExpressionContext) {
        if (call instanceof XAssignment) {
            assignmentToJavaExpression((XAssignment) call, output, isExpressionContext);
        } else {
            if (needMultiAssignment(call)) {
                appendLeftOperand(call, output, isExpressionContext).append(" = "); //$NON-NLS-1$
            }

            ITreeAppendable child = output;
            final JvmAnnotationReference annotationRef = this.expressionHelper.findInlineAnnotation(call);
            if (annotationRef == null || !isConstantExpression(annotationRef)) {
                final boolean hasReceiver = appendReceiver(call, output, isExpressionContext);
                if (hasReceiver) {
                    output.append("."); //$NON-NLS-1$
                    child = appendTypeArguments(call, output);
                }
            }
            appendFeatureCall(call, child);
        }
    }

The idea is to skip the receiver when the inline expression is constant.

May I create a pull request?

from xtext-extras.

spoenemann avatar spoenemann commented on August 15, 2024

May I create a pull request?

Yes.

from xtext-extras.

svenefftinge avatar svenefftinge commented on August 15, 2024

I don't really get what your intend is here, but @Inline is not meant to be used outside of the xbase lib and is made to work on static methods only.
Could you explain your use case?

from xtext-extras.

gallandarakhneorg avatar gallandarakhneorg commented on August 15, 2024

Dear @svenefftinge

I am using @Inline in two contexts:

  • I am using @Inline in my Java libraries (http://www.arakhne.org/afc) in order to enable better Java code generation when using the library functions from my DSL language.
  • And my DSL compiler is detecting "simple" functions (with only a return statement) for generating the @Inline annotation and attaching it to the generated Java function.

It should be nice to enable the use of @Inline annotation outside xbase lib (indeed it is almost ready to be used), because it is a nice feature for helping the xbase-based generators to generate better Java code.

Nevertheless, even if I'm using @Inline outside its planned scope, I have discovered inconsistency in the meaning of the @Inline parameters from my point of view, as I have explained in this issue.

I have added patches for solving this in my DSL compiler, and it's working fine.

from xtext-extras.

svenefftinge avatar svenefftinge commented on August 15, 2024

Thank you. I wanted to understand what the purpose of your use of 'constantExpression' is, since a constant expression by definition can not come from an instance, it doesn't make sense to me to allow it on non-static members.

Also see https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28

from xtext-extras.

gallandarakhneorg avatar gallandarakhneorg commented on August 15, 2024

For an example of @Inline usefull usage for non-static functions:

class X {
   @Inline(value="f($1,2)")
    def int f(int a) {
        return f(a, 2);
     }
    def int f(int a, int b) {
    }
}

from xtext-extras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.