本文整理汇总了Java中org.eclipse.xtext.EcoreUtil2类的典型用法代码示例。如果您正苦于以下问题:Java EcoreUtil2类的具体用法?Java EcoreUtil2怎么用?Java EcoreUtil2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EcoreUtil2类属于org.eclipse.xtext包,在下文中一共展示了EcoreUtil2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getScriptErrors
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
@Override
protected List<Diagnostic> getScriptErrors(Script script) {
EcoreUtil.resolveAll(script.eResource());
List<Diagnostic> diagnostics = super.getScriptErrors(script);
Iterator<Expression> expressions = Iterators.filter(EcoreUtil2.eAll(script), Expression.class);
List<Diagnostic> result = Lists.<Diagnostic> newArrayList(Iterables.filter(diagnostics,
ExceptionDiagnostic.class));
while (expressions.hasNext()) {
Expression expression = expressions.next();
RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(expression);
Result<TypeRef> type = typeSystem.type(ruleEnvironment, expression);
if (type.getRuleFailedException() != null) {
Throwable cause = Throwables.getRootCause(type.getRuleFailedException());
if (!(cause instanceof RuleFailedException)) {
if (cause instanceof Exception) {
result.add(new ExceptionDiagnostic((Exception) cause));
} else {
throw new RuntimeException(cause);
}
}
}
}
validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
return result;
}
开发者ID:eclipse,项目名称:n4js,代码行数:26,代码来源:ExceptionAnalyser.java
示例2: getProbableThisTarget
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
/**
* The heuristically computed this target, but not the directly containing function, in which the expression (or any
* other object) is (indirectly) contained, may be null. This typically is an {@link ObjectLiteral}, an
* {@link N4ClassDeclaration}, or another outer {@link FunctionDefinition}. Note that for expressions contained in
* property name value pairs, it is <b>not</b> the object literal.
* <p>
* cf. ECMAScript spec 10.4.3 Entering Function Code
* </p>
*/
public static ThisTarget getProbableThisTarget(EObject location) {
if (location == null || location.eContainer() == null) {
return null;
}
final ThisArgProvider thisArgProvider = location instanceof N4MethodDeclaration ? (N4MethodDeclaration) location
: EcoreUtil2.getContainerOfType(location.eContainer(), ThisArgProvider.class);
if (thisArgProvider == null) {
return null;
}
final ThisTarget thisTarget = EcoreUtil2.getContainerOfType(thisArgProvider.eContainer(), ThisTarget.class);
if (thisTarget != null) {
ThisArgProvider indirectThisArgProvider = EcoreUtil2.getContainerOfType(thisArgProvider.eContainer(),
ThisArgProvider.class);
if (indirectThisArgProvider != null && EcoreUtil.isAncestor(thisTarget, indirectThisArgProvider)) {
return null; // nested function
}
}
return thisTarget;
}
开发者ID:eclipse,项目名称:n4js,代码行数:31,代码来源:N4JSASTUtils.java
示例3: findPrecedingStatement
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
private ControlFlowElement findPrecedingStatement(ControlFlowElement cfe) {
ControlFlowElement precedingStatement = null;
Statement stmt = EcoreUtil2.getContainerOfType(cfe, Statement.class);
if (stmt != null) {
EObject stmtContainer = stmt.eContainer();
if (stmtContainer != null && stmtContainer instanceof Block) {
Block block = (Block) stmtContainer;
EList<Statement> stmts = block.getStatements();
int index = stmts.indexOf(stmt);
if (index > 0) {
precedingStatement = stmts.get(index - 1);
}
}
}
return precedingStatement;
}
开发者ID:eclipse,项目名称:n4js,代码行数:17,代码来源:DeadCodeAnalyser.java
示例4: computeMissingApiFields
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
/**
* Computes the list of virtual AccessorTuples for missing fields.
*
* @return List of {@link VirtualApiTField}
*/
private List<AccessorTuple> computeMissingApiFields(TClass declaration) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(declaration.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonEntry compareEntry = optAdapt.get().getEntryFor(
EcoreUtil2.getContainerOfType(declaration, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(declaration);
if (typeCompare != null) {
return typeCompare.allChildren()
.filter(pce -> pce.getElementAPI() instanceof TField)
.filter(pce -> pce.getElementImpl()[0] == null) // only go for empty impl.
.map(pce -> {
TField apiField = (TField) pce.getElementAPI();
VirtualApiMissingFieldAccessorTuple ret = createVirtFieldAccessorTuple(apiField);
return ret;
})
.collect(Collectors.toList());
}
}
return emptyList();
}
开发者ID:eclipse,项目名称:n4js,代码行数:27,代码来源:ScriptApiTracker.java
示例5: collectAbstractElements
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
@Override
public void collectAbstractElements(Grammar grammar, EStructuralFeature feature,
IFollowElementAcceptor followElementAcceptor) {
for (Grammar superGrammar : grammar.getUsedGrammars()) {
collectAbstractElements(superGrammar, feature, followElementAcceptor);
}
EClass declarator = feature.getEContainingClass();
for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
for (Assignment assignment : GrammarUtil.containedAssignments(rule)) {
if (assignment.getFeature().equals(feature.getName())) {
EClassifier classifier = GrammarUtil.findCurrentType(assignment);
EClassifier compType = EcoreUtil2.getCompatibleType(declarator, classifier);
if (compType == declarator) {
followElementAcceptor.accept(assignment);
}
}
}
}
}
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:PatchedFollowElementComputer.java
示例6: rewriteKeywords
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
private static void rewriteKeywords(AbstractRule rule, N4JSKeywords keywords,
ImmutableMap.Builder<AbstractElement, Integer> builder) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Keyword) {
Keyword keyword = (Keyword) obj;
Integer type = keywords.getTokenType(keyword);
if (type != null) {
if (keyword.eContainer() instanceof EnumLiteralDeclaration) {
builder.put((AbstractElement) keyword.eContainer(), type);
} else {
builder.put(keyword, type);
}
}
}
}
}
开发者ID:eclipse,项目名称:n4js,代码行数:17,代码来源:TokenTypeRewriter.java
示例7: rewriteTypeReferences
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
private static void rewriteTypeReferences(N4JSGrammarAccess ga,
ImmutableMap.Builder<AbstractElement, Integer> builder) {
for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Assignment) {
Assignment assignment = (Assignment) obj;
AbstractElement terminal = assignment.getTerminal();
if (terminal instanceof RuleCall) {
AbstractRule calledRule = ((RuleCall) terminal).getRule();
EClassifier classifier = calledRule.getType().getClassifier();
if (classifier instanceof EClass
&& TypeRefsPackage.Literals.TYPE_REF.isSuperTypeOf((EClass) classifier)) {
builder.put(assignment, TYPE_REF_TOKEN);
}
}
}
}
}
}
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:TokenTypeRewriter.java
示例8: rewriteIdentifiers
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
ImmutableMap.Builder<AbstractElement, Integer> builder) {
ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
ga.getBindingIdentifierRule(),
ga.getIdentifierNameRule(),
ga.getIDENTIFIERRule());
for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Assignment) {
Assignment assignment = (Assignment) obj;
AbstractElement terminal = assignment.getTerminal();
int type = InternalN4JSParser.RULE_IDENTIFIER;
if (terminal instanceof CrossReference) {
terminal = ((CrossReference) terminal).getTerminal();
type = IDENTIFIER_REF_TOKEN;
}
if (terminal instanceof RuleCall) {
AbstractRule calledRule = ((RuleCall) terminal).getRule();
if (identifierRules.contains(calledRule)) {
builder.put(assignment, type);
}
}
}
}
}
}
开发者ID:eclipse,项目名称:n4js,代码行数:27,代码来源:TokenTypeRewriter.java
示例9: rewriteNumberLiterals
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
private static void rewriteNumberLiterals(N4JSGrammarAccess ga,
ImmutableMap.Builder<AbstractElement, Integer> builder) {
for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Assignment) {
Assignment assignment = (Assignment) obj;
AbstractElement terminal = assignment.getTerminal();
if (terminal instanceof RuleCall) {
AbstractRule calledRule = ((RuleCall) terminal).getRule();
EClassifier classifier = calledRule.getType().getClassifier();
if (classifier == EcorePackage.Literals.EBIG_DECIMAL) {
builder.put(assignment, NUMBER_LITERAL_TOKEN);
}
}
}
}
}
}
开发者ID:eclipse,项目名称:n4js,代码行数:19,代码来源:TokenTypeRewriter.java
示例10: referenceHasBeenFound
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
private boolean referenceHasBeenFound(Predicate<URI> targetURIs, URI refURI, EObject instanceOrProxy) {
boolean result = false;
// If the EObject is a composed member, we compare the target URIs with the URIs of the constituent members.
if (instanceOrProxy instanceof TMember && ((TMember) instanceOrProxy).isComposed()) {
TMember member = (TMember) instanceOrProxy;
if (member.isComposed()) {
for (TMember constituentMember : member.getConstituentMembers()) {
URI constituentReffURI = EcoreUtil2
.getPlatformResourceOrNormalizedURI(constituentMember);
result = result || targetURIs.apply(constituentReffURI);
}
}
} else {
// Standard case
result = targetURIs.apply(refURI);
}
return result;
}
开发者ID:eclipse,项目名称:n4js,代码行数:19,代码来源:ConcreteSyntaxAwareReferenceFinder.java
示例11: getActualDeclaredReceiverType
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
/**
* Returns the actual receiver type, which usually simply is the declared type of the receiver type. However, in
* case of classifier references, enums, or structural type references, the actual receiver may be differently
* computed.
*/
private Type getActualDeclaredReceiverType(EObject context, TypeRef receiverType, ResourceSet resourceSet) {
if (receiverType instanceof TypeTypeRef) {
final RuleEnvironment G = RuleEnvironmentExtensions.newRuleEnvironment(context);
return tsh.getStaticType(G, (TypeTypeRef) receiverType);
}
if (receiverType instanceof ThisTypeRef) {
ThisTypeRef thisTypeRef = (ThisTypeRef) receiverType;
if (thisTypeRef.isUseSiteStructuralTyping()) {
FunctionOrFieldAccessor foa = N4JSASTUtils.getContainingFunctionOrAccessor(thisTypeRef);
N4ClassifierDefinition classifier = EcoreUtil2.getContainerOfType(foa, N4ClassifierDefinition.class);
return classifier.getDefinedType();
}
}
if (receiverType instanceof FunctionTypeExpression) {
if (resourceSet == null)
return null;
// Change receiverType to implicit super class Function.
BuiltInTypeScope builtInTypeScope = BuiltInTypeScope.get(resourceSet);
TObjectPrototype functionType = builtInTypeScope.getFunctionType();
return functionType;
}
return receiverType.getDeclaredType();
}
开发者ID:eclipse,项目名称:n4js,代码行数:29,代码来源:MemberVisibilityChecker.java
示例12: shortcutIsVisible
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
private boolean shortcutIsVisible(TMember candidate, Type contextType, TModule contextModule, Type receiverType) {
/* Members of the same type are always visible */
if (receiverType == contextType && contextType == candidate.eContainer()) {
return true;
}
/*
* object literals do not constrain accessibility
*/
if (receiverType instanceof TStructuralType) {
return true;
}
/*
* Members of the same module are always visible
*/
if (contextModule == EcoreUtil2.getContainerOfType(candidate, TModule.class)) {
return true;
}
return false;
}
开发者ID:eclipse,项目名称:n4js,代码行数:21,代码来源:MemberVisibilityChecker.java
示例13: checkIsValidConstructorArgument
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
protected void checkIsValidConstructorArgument(XExpression argument, JvmType containerType) {
TreeIterator<EObject> iterator = EcoreUtil2.eAll(argument);
while(iterator.hasNext()) {
EObject partOfArgumentExpression = iterator.next();
if (partOfArgumentExpression instanceof XFeatureCall || partOfArgumentExpression instanceof XMemberFeatureCall) {
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) partOfArgumentExpression;
XExpression actualReceiver = featureCall.getActualReceiver();
if(actualReceiver instanceof XFeatureCall && ((XFeatureCall)actualReceiver).getFeature() == containerType) {
JvmIdentifiableElement feature = featureCall.getFeature();
if (feature != null && !feature.eIsProxy()) {
if (feature instanceof JvmField) {
if (!((JvmField) feature).isStatic())
error("Cannot refer to an instance field " + feature.getSimpleName() + " while explicitly invoking a constructor",
partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT);
} else if (feature instanceof JvmOperation) {
if (!((JvmOperation) feature).isStatic())
error("Cannot refer to an instance method while explicitly invoking a constructor",
partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT);
}
}
}
} else if(isLocalClassSemantics(partOfArgumentExpression)) {
iterator.prune();
}
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:27,代码来源:XbaseValidator.java
示例14: checkValidReturn
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
protected void checkValidReturn(XReturnExpression object, ITypeComputationState state) {
// if the expectation comes from a method's return type
// then it is legal, thus we must check if the return is
// contained in a throw expression
if (hasThrowableExpectation(state) &&
EcoreUtil2.getContainerOfType(object, XThrowExpression.class) != null) {
state.addDiagnostic(new EObjectDiagnosticImpl(
Severity.ERROR,
IssueCodes.INVALID_RETURN,
"Invalid return inside throw.",
object,
null,
-1,
new String[] {
}));
}
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:18,代码来源:XbaseTypeComputer.java
示例15: _toJavaExpression
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
@Override
// CHECKSTYLE:OFF
protected void _toJavaExpression(final XAbstractFeatureCall expr, final ITreeAppendable b) {
// CHECKSTYLE:ON
FormalParameter parameter = getFormalParameter(expr);
if (parameter != null) {
// No Java entities are generated for this. Replace by a call to the getter function.
b.append(generatorNaming.catalogInstanceName(parameter)).append(".").append(generatorNaming.formalParameterGetterName(parameter));
b.append("(").append(getContextImplicitVariableName(expr)).append(")");
} else {
Member member = getMember(expr);
if (member != null) {
// Something isn't quite right in the Jvm model yet... or in the xbase compiler. Don't know what it is, but even if in an inner
// class, it generates "this.foo" instead of either just "foo" or "OuterClass.this.foo". Force it to produce the latter.
CheckCatalog catalog = EcoreUtil2.getContainerOfType(member, CheckCatalog.class);
String catalogName = generatorNaming.validatorClassName(catalog);
b.append(catalogName + ".this.").append(member.getName());
return;
}
super._toJavaExpression(expr, b);
}
}
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:23,代码来源:CheckCompiler.java
示例16: testgetReferenceDescriptionForMultiValue
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
@Test public void testgetReferenceDescriptionForMultiValue() throws Exception {
with(new LangATestLanguageStandaloneSetup());
XtextResource targetResource = getResource("type C type D", "bar.langatestlanguage");
EObject typeC = targetResource.getContents().get(0).eContents().get(0);
EObject typeD = targetResource.getContents().get(0).eContents().get(1);
XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
resource.load(new StringInputStream("type A implements B,C,D type B"), null);
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
assertEquals(2,collection.size());
Iterator<IReferenceDescription> iterator = descriptions.iterator();
IReferenceDescription refDesc1 = iterator.next();
IReferenceDescription refDesc2 = iterator.next();
Main m = (Main) resource.getParseResult().getRootASTElement();
assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc1.getSourceEObjectUri(),false));
assertEquals(typeC,resource.getResourceSet().getEObject(refDesc1.getTargetEObjectUri(),false));
assertEquals(1,refDesc1.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc1.getEReference());
assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc2.getSourceEObjectUri(),false));
assertEquals(typeD,resource.getResourceSet().getEObject(refDesc2.getTargetEObjectUri(),false));
assertEquals(2,refDesc2.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc2.getEReference());
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:DefaultReferenceDescriptionTest.java
示例17: getScope
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
@Override
public IScope getScope(EObject context, EReference reference) {
if (reference == XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) {
XAnnotation annotation = EcoreUtil2.getContainerOfType(context, XAnnotation.class);
JvmType annotationType = annotation.getAnnotationType();
if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
return IScope.NULLSCOPE;
}
Iterable<JvmOperation> operations = ((JvmAnnotationType) annotationType).getDeclaredOperations();
Iterable<IEObjectDescription> descriptions = transform(operations, new Function<JvmOperation, IEObjectDescription>() {
@Override
public IEObjectDescription apply(JvmOperation from) {
return EObjectDescription.create(QualifiedName.create(from.getSimpleName()), from);
}
});
return MapBasedScope.createScope(IScope.NULLSCOPE, descriptions);
}
return super.getScope(context, reference);
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:20,代码来源:XbaseWithAnnotationsBatchScopeProvider.java
示例18: findKnownTopLevelType
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
protected JvmType findKnownTopLevelType(Class<?> rawType, Notifier context) {
if (rawType.isArray()) {
throw new IllegalArgumentException(rawType.getCanonicalName());
}
if (rawType.isPrimitive()) {
throw new IllegalArgumentException(rawType.getName());
}
ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
if (resourceSet == null) {
return null;
}
Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(rawType.getName()), true);
List<EObject> resourceContents = typeResource.getContents();
if (resourceContents.isEmpty())
return null;
JvmType type = (JvmType) resourceContents.get(0);
return type;
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:AbstractXbaseCompiler.java
示例19: getContextJvmDeclaredType
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
@Override
public JvmDeclaredType getContextJvmDeclaredType(EObject model) {
if(model != null) {
JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(model);
if(logicalContainer != null)
return EcoreUtil2.getContainerOfType(logicalContainer, JvmDeclaredType.class);
EObject currentElement = model;
do {
for(EObject jvmElement: associations.getJvmElements(currentElement)) {
if(jvmElement instanceof JvmDeclaredType)
return (JvmDeclaredType) jvmElement;
}
currentElement = currentElement.eContainer();
} while (currentElement != null);
}
return null;
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:18,代码来源:DefaultImportsConfiguration.java
示例20: getJavaLangObjectTypeRef
import org.eclipse.xtext.EcoreUtil2; //导入依赖的package包/类
protected JvmTypeReference getJavaLangObjectTypeRef(JvmType rawType, TypesFactory typesFactory) {
ResourceSet rs = EcoreUtil2.getResourceSet(rawType);
JvmParameterizedTypeReference refToObject = typesFactory.createJvmParameterizedTypeReference();
if (rs != null) {
EObject javaLangObject = rs.getEObject(javaLangObjectURI, true);
if (javaLangObject instanceof JvmType) {
JvmType objectDeclaration = (JvmType) javaLangObject;
refToObject.setType(objectDeclaration);
return refToObject;
}
}
JvmGenericType proxy = typesFactory.createJvmGenericType();
((InternalEObject)proxy).eSetProxyURI(javaLangObjectURI);
refToObject.setType(proxy);
return refToObject;
}
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XFunctionTypeRefImplCustom.java
注:本文中的org.eclipse.xtext.EcoreUtil2类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论