Beispiel #1
0
 /**
  * Returns the invocation of an element or rule accessor, including the .getType() call. Example1:
  * getFooRule().getType() Example2: getBarRule().getFooAction().getType()
  */
 public String gaTypeAccessor(final TypeRef ele) {
   String _switchResult = null;
   EObject _eContainer = ele.eContainer();
   final EObject cnt = _eContainer;
   boolean _matched = false;
   if (!_matched) {
     if (cnt instanceof AbstractElement) {
       _matched = true;
       String _gaRuleElementAccessor = this.gaRuleElementAccessor(((AbstractElement) cnt));
       _switchResult = (_gaRuleElementAccessor + ".getType()");
     }
   }
   if (!_matched) {
     if (cnt instanceof AbstractRule) {
       _matched = true;
       String _gaRuleAccessor = this.gaRuleAccessor(((AbstractRule) cnt));
       _switchResult = (_gaRuleAccessor + ".getType()");
     }
   }
   if (!_matched) {
     EObject _eContainer_1 = ele.eContainer();
     EClass _eClass = _eContainer_1.eClass();
     String _name = _eClass.getName();
     String _plus = ("<error: unknown type " + _name);
     _switchResult = (_plus + ">");
   }
   return _switchResult;
 }
 public void testMetamodel() throws Exception {
   AbstractRule rule =
       GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "OverridableParserRule2");
   assertNotNull("rule", rule);
   TypeRef ref = rule.getType();
   assertNotNull("ref", ref);
   final EClass clazz = (EClass) ref.getClassifier();
   assertNotNull("class", clazz);
   assertEquals("AType2", clazz.getName());
   assertEquals(2, clazz.getESuperTypes().size());
   Set<String> expectedNames =
       new HashSet<String>(Arrays.asList(new String[] {"AType", "RootRule"}));
   Iterator<String> iter =
       Iterables.transform(
               clazz.getESuperTypes(),
               new Function<EClass, String>() {
                 public String apply(EClass param) {
                   return param.getName();
                 }
               })
           .iterator();
   while (iter.hasNext()) {
     String name = iter.next();
     assertTrue("name = '" + name + "'", expectedNames.remove(name));
   }
   assertTrue(expectedNames.toString(), expectedNames.isEmpty());
 }
 private TypeRef copyTypeRef(final TypeRef ref) {
   if ((ref == null)) {
     return null;
   }
   final TypeRef copy = this.<TypeRef>copy(ref);
   EClassifier _classifier = ref.getClassifier();
   copy.setClassifier(_classifier);
   return copy;
 }