當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractRule.getType方法代碼示例

本文整理匯總了Java中org.eclipse.xtext.AbstractRule.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java AbstractRule.getType方法的具體用法?Java AbstractRule.getType怎麽用?Java AbstractRule.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.xtext.AbstractRule的用法示例。


在下文中一共展示了AbstractRule.getType方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getOrComputeReturnType

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private TypeRef getOrComputeReturnType(AbstractRule rule) {
	TypeRef result = rule.getType();
	if (result == null) {
		EClassifier classifier = getClassifierFor(rule);
		if (classifier == null) {
			if (rule.getName() == null)
				return null;
			result = getTypeRef(rule.getName());
		} else
			result = getTypeRef(classifier);
		if (result.getMetamodel() == null) {
			AbstractMetamodelDeclaration bestMatch = null;
			for (AbstractMetamodelDeclaration decl : grammar.getMetamodelDeclarations()) {
				if (decl instanceof GeneratedMetamodel && Strings.isEmpty(decl.getAlias())) {
					bestMatch = decl;
					break;
				}
			}
			if (result.getMetamodel() == null)
				result.setMetamodel(bestMatch);
		}
		rule.setType(result);
	}
	return result;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:26,代碼來源:Xtext2EcoreTransformer.java

示例2: acceptRuleCall

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
protected void acceptRuleCall(RuleCall rc, Object value, String token, int index, INode node) {
	CrossReference crossRef = GrammarUtil.containingCrossReference(rc);
	if (crossRef != null) {
		if (rc.getRule() instanceof ParserRule)
			sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index,
					getCompositeNode(node));
		else if (rc.getRule() instanceof TerminalRule)
			sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, getLeafNode(node));
		else if (rc.getRule() instanceof EnumRule)
			sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, getCompositeNode(node));
	} else {
		if (rc.getRule() instanceof ParserRule) {
			AbstractRule rule = rc.getRule();
			if (rule.getType() != null && rule.getType().getClassifier() instanceof EClass)
				acceptEObjectRuleCall(rc, (EObject) value, getCompositeNode(node));
			else
				sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, getCompositeNode(node));
		} else if (rc.getRule() instanceof TerminalRule)
			sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, getLeafNode(node));
		else if (rc.getRule() instanceof EnumRule)
			sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, getCompositeNode(node));
	}
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:24,代碼來源:SequenceFeeder.java

示例3: testMetamodel

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test 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>(){
		@Override
		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());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:23,代碼來源:InheritanceTest.java

示例4: getClassifierFor

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
EClassifier getClassifierFor(AbstractRule rule) {
	if (rule.getType() != null && rule.getType().getClassifier() != null)
		return rule.getType().getClassifier();
	if (rule instanceof TerminalRule || rule instanceof ParserRule && DatatypeRuleUtil.isDatatypeRule((ParserRule) rule)) {
		return GrammarUtil.findEString(grammar);
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:9,代碼來源:Xtext2EcoreTransformer.java

示例5: findEClassifierInfo

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private EClassifierInfo findEClassifierInfo(AbstractRule rule) {
	final TypeRef typeRef = getOrComputeReturnType(rule);
	if (typeRef == null)
		throw new NullPointerException();
	if (rule.getType() != typeRef)
		throw new IllegalStateException();
	return eClassifierInfos.getInfo(typeRef);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:9,代碼來源:Xtext2EcoreTransformer.java

示例6: caseRuleCall

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
public Boolean caseRuleCall(RuleCall object) {
	EClassifier wasType = currentType;
	AbstractRule calledRule = object.getRule();
	if (currentType == null) {
		if (calledRule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) calledRule)) {
			ParserRule parserRule = (ParserRule) calledRule;
			if (parserRule.isFragment()) {
				if (context.getType() != null)
					currentType = context.getType().getClassifier();
				if (!parserRule.isWildcard()) {
					doSwitch(parserRule);
				}
			} else {
				TypeRef returnType = calledRule.getType();
				if (returnType != null) {
					currentType = returnType.getClassifier();
				}
			}
		}
	} else if (isFragmentButNotWildcard(calledRule)) {
		doSwitch(calledRule);
	}
	if (object == stopElement)
		return true;
	if (GrammarUtil.isOptionalCardinality(object))
		currentType = getCompatibleType(currentType, wasType, object);
	return false;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:30,代碼來源:CurrentTypeFinder.java

示例7: testTypesOfImplicitSuperGrammar

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testTypesOfImplicitSuperGrammar() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: myFeature=INT;");
  _builder.newLine();
  final String xtextGrammar = _builder.toString();
  EObject _model = this.getModel(xtextGrammar);
  final Grammar grammar = ((Grammar) _model);
  final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
  transformer.removeGeneratedPackages();
  transformer.transform();
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  TypeRef type = rule.getType();
  Assert.assertNotNull(type);
  Assert.assertNotNull(transformer.getEClassifierInfos().getInfo(type));
  AbstractMetamodelDeclaration _get = GrammarUtil.allMetamodelDeclarations(grammar).get(1);
  final ReferencedMetamodel referenced = ((ReferencedMetamodel) _get);
  Assert.assertNotNull(referenced);
  Assert.assertEquals("ecore", referenced.getAlias());
  Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced, "EString"));
  Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced, "EInt"));
  EClassifierInfos parentInfos = IterableExtensions.<EClassifierInfos>head(transformer.getEClassifierInfos().getParents());
  Assert.assertNotNull(parentInfos.getInfo(referenced, "EString"));
  Assert.assertNotNull(parentInfos.getInfo(referenced, "EInt"));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:30,代碼來源:Xtext2EcoreTransformerTest.java

示例8: deriveTypeHierarchy

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private boolean deriveTypeHierarchy() {
	boolean result = true;
	for (AbstractRule rule : grammar.getRules()) {
		try {
			EClassifierInfo generatedEClass = findOrCreateEClassifierInfo(rule);
			if (generatedEClass != null || !isWildcardFragment(rule)) {
				if (rule instanceof ParserRule) {
					ParserRule parserRule = (ParserRule) rule;
					if (parserRule.getAlternatives() != null) {
						if (!GrammarUtil.isDatatypeRule(parserRule)) {
							deriveTypesAndHierarchy(parserRule, generatedEClass, parserRule.getAlternatives());
						} else {
							checkSupertypeOfOverriddenDatatypeRule(rule);
						}
					}
				} else if (rule instanceof TerminalRule) {
					if (rule.getType() != null) {
						if (!(rule.getType().getClassifier() instanceof EDataType))
							throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable,
									"Return type of a terminal rule must be an EDataType.", rule.getType());
						checkSupertypeOfOverriddenDatatypeRule(rule);
					}
				} else if (rule instanceof EnumRule) {
					if (rule.getType() != null) {
						if (!(rule.getType().getClassifier() instanceof EEnum))
							throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable,
									"Return type of an enum rule must be an EEnum.", rule.getType());
						checkSupertypeOfOverriddenDatatypeRule(rule);
					}
				} else {
					throw new IllegalStateException("Unknown rule type: " + rule.eClass().getName());
				}
			}
			if (isWildcardFragment(rule)) {
				for (Grammar usedGrammar: grammar.getUsedGrammars()) {
					deriveTypeHierarchyFromOverridden((ParserRule) rule, usedGrammar);
				}
			}
		}
		catch (TransformationException e) {
			reportError(e);
			result = false;
		}
	}
	return result;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:47,代碼來源:Xtext2EcoreTransformer.java

示例9: deriveTypeHierarchyFromOverridden

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private boolean deriveTypeHierarchyFromOverridden(ParserRule rule, Grammar grammar) throws TransformationException {
	AbstractRule parentRule = GrammarUtil.findRuleForName(grammar, rule.getName());
	if (parentRule != null) {
		if (parentRule != rule && parentRule instanceof ParserRule) {
			ParserRule casted = (ParserRule) parentRule;
			if (casted.isFragment() != rule.isFragment()) {
				if (rule.isFragment()) {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"A fragment rule cannot override a production rule.", rule);
				} else {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"Only fragment rule can override other fragment rules.", rule);
				}
			}
			if (casted.isWildcard() != rule.isWildcard()) {
				if (rule.isWildcard()) {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"A wildcard fragment rule cannot override a typed fragment rule.", rule);
				} else {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"Only wildcard fragment rules can override other wildcard fragments.", rule);
				}
			}
			if (rule.isFragment() && !rule.isWildcard() && parentRule.getType() != null) {
				if (rule.getType().getClassifier() != parentRule.getType().getClassifier()) {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"Overriding fragment rules cannot redeclare their type.", rule.getType());
				}
			}
			checkParameterLists(rule, casted);
		}
		if (parentRule.getType() != null && parentRule != rule) {			
			if (parentRule.getType().getClassifier() instanceof EDataType)
				throw new TransformationException(TransformationErrorCode.InvalidSupertype,
						"Cannot inherit from datatype rule and return another type.", rule.getType());
			EClassifierInfo parentTypeInfo = eClassifierInfos.getInfoOrNull(parentRule.getType());
			if (parentTypeInfo == null)
				throw new TransformationException(TransformationErrorCode.InvalidSupertype,
						"Cannot determine return type of overridden rule.", rule.getType());
			addSuperType(rule, rule.getType(), parentTypeInfo);
			return true;
		}
	}
	return false;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:46,代碼來源:Xtext2EcoreTransformer.java

示例10: caseAbstractRule

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
public EClassifier caseAbstractRule(AbstractRule object) {
	if (object.getType() != null)
		return doSwitch(object.getType());
	return null;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:7,代碼來源:ElementTypeCalculator.java

示例11: isNamed

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
protected boolean isNamed(final EObject element) {
  boolean _xblockexpression = false;
  {
    TypeRef _switchResult = null;
    boolean _matched = false;
    if (element instanceof AbstractRule) {
      _matched=true;
      _switchResult = ((AbstractRule)element).getType();
    }
    if (!_matched) {
      if (element instanceof RuleCall) {
        _matched=true;
        AbstractRule _rule = ((RuleCall)element).getRule();
        TypeRef _type = null;
        if (_rule!=null) {
          _type=_rule.getType();
        }
        _switchResult = _type;
      }
    }
    if (!_matched) {
      if (element instanceof Action) {
        _matched=true;
        _switchResult = ((Action)element).getType();
      }
    }
    final TypeRef type = _switchResult;
    EClassifier _classifier = null;
    if (type!=null) {
      _classifier=type.getClassifier();
    }
    final EClassifier classifier = _classifier;
    EStructuralFeature _xifexpression = null;
    if ((classifier instanceof EClass)) {
      _xifexpression = ((EClass)classifier).getEStructuralFeature("name");
    }
    final EStructuralFeature feature = _xifexpression;
    boolean _and = false;
    boolean _and_1 = false;
    if (!((feature instanceof EAttribute) && (!feature.isMany()))) {
      _and_1 = false;
    } else {
      EClassifier _eType = null;
      if (feature!=null) {
        _eType=feature.getEType();
      }
      Class<?> _instanceClass = null;
      if (_eType!=null) {
        _instanceClass=_eType.getInstanceClass();
      }
      boolean _tripleNotEquals = (_instanceClass != null);
      _and_1 = _tripleNotEquals;
    }
    if (!_and_1) {
      _and = false;
    } else {
      boolean _isAssignableFrom = String.class.isAssignableFrom(feature.getEType().getInstanceClass());
      _and = _isAssignableFrom;
    }
    _xblockexpression = _and;
  }
  return _xblockexpression;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:64,代碼來源:IdeaPluginGenerator.java


注:本文中的org.eclipse.xtext.AbstractRule.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。