yoday / stab-language

Automatically exported from code.google.com/p/stab-language
Apache License 2.0
0 stars 1 forks source link

Example with Google Guice not compiling #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following Google Guice code, does not compile

using java.lang;
using java.lang.annotation;
using stab.lang;

using com.google.inject;
using com.google.inject.binder;
using com.google.inject.matcher;
using com.google.inject.name;
using com.google.inject.spi;
using com.google.inject.util;

package pt.json {

    public interface FortuneService {
        String foo();
    }

    [Singleton]
    public class FortuneServiceImpl : FortuneService {
        public String foo(){
            return "Hello";
        }
    }

    public class ChefModule: AbstractModule {
        protected override void configure(){
            bind(typeof(FortuneService))
                .to(typeof(FortuneServiceImpl))
                .in(typeof(Singleton));
        }
    }

    public class Chef {

        private FortuneService service;

        [Inject]
        public Chef([Demo] FortuneService service){
            this.service = service;
        }

        public String makeFortune(){
            return service.foo();
        }
    }

    [StaticClass]
    public class Main {

        public static void main( String[] args){
            var injector = Guice.createInjector(Stage.DEVELOPMENT, new ChefModule());
            var chef = injector.getInstance(Key.get(typeof(Chef)));

            System.out.println(chef.makeFortune());
        }
    }
}

The line ".in(typeof(Singleton));" 

returns "error 27: Identifier expected"

Original issue reported on code.google.com by ice.ta...@gmail.com on 26 Jun 2010 at 4:28

GoogleCodeExporter commented 9 years ago
'in' is a keyword. To invoke a method called 'in' you must use the verbatim 
identifier '@in'. The line becomes ".@in(typeof(Singleton));".

Original comment by stab.hac...@gmail.com on 26 Jun 2010 at 10:53