Search in sources :

Example 16 with ImportDescr

use of org.drools.compiler.lang.descr.ImportDescr in project drools by kiegroup.

the class RuleParserTest method testCompilationUnit.

@Test
public void testCompilationUnit() throws Exception {
    final String source = "package foo; import com.foo.Bar; import com.foo.Baz;";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals("foo", pkg.getName());
    assertEquals(2, pkg.getImports().size());
    ImportDescr impdescr = pkg.getImports().get(0);
    assertEquals("com.foo.Bar", impdescr.getTarget());
    assertEquals(source.indexOf("import " + impdescr.getTarget()), impdescr.getStartCharacter());
    assertEquals(source.indexOf("import " + impdescr.getTarget()) + ("import " + impdescr.getTarget()).length(), impdescr.getEndCharacter());
    impdescr = pkg.getImports().get(1);
    assertEquals("com.foo.Baz", impdescr.getTarget());
    assertEquals(source.indexOf("import " + impdescr.getTarget()), impdescr.getStartCharacter());
    assertEquals(source.indexOf("import " + impdescr.getTarget()) + ("import " + impdescr.getTarget()).length(), impdescr.getEndCharacter());
}
Also used : ImportDescr(org.drools.compiler.lang.descr.ImportDescr) FunctionImportDescr(org.drools.compiler.lang.descr.FunctionImportDescr) AccumulateImportDescr(org.drools.compiler.lang.descr.AccumulateImportDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Aggregations

ImportDescr (org.drools.compiler.lang.descr.ImportDescr)16 FunctionImportDescr (org.drools.compiler.lang.descr.FunctionImportDescr)10 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)8 AccumulateImportDescr (org.drools.compiler.lang.descr.AccumulateImportDescr)7 AbstractClassTypeDeclarationDescr (org.drools.compiler.lang.descr.AbstractClassTypeDeclarationDescr)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)2 AttributeDescr (org.drools.compiler.lang.descr.AttributeDescr)2 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)2 EnumDeclarationDescr (org.drools.compiler.lang.descr.EnumDeclarationDescr)2 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)2 TypeDeclarationDescr (org.drools.compiler.lang.descr.TypeDeclarationDescr)2 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)2 Iterator (java.util.Iterator)1