本文整理汇总了Java中org.eclipse.xtext.EcoreUtil2.getContainerOfType方法的典型用法代码示例。如果您正苦于以下问题:Java EcoreUtil2.getContainerOfType方法的具体用法?Java EcoreUtil2.getContainerOfType怎么用?Java EcoreUtil2.getContainerOfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.EcoreUtil2
的用法示例。
在下文中一共展示了EcoreUtil2.getContainerOfType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例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;
}
示例4: 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[] {
}));
}
}
示例5: 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);
}
示例6: _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);
}
}
示例7: addFQNs
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
private void addFQNs(EObject object) {
if (object instanceof TMember || object instanceof TEnumLiteral) {
Type t = EcoreUtil2.getContainerOfType(object.eContainer(), Type.class);
typesOrModulesToFind.add(qualifiedNameProvider.getFullyQualifiedName(t));
} else if (object instanceof Type) {
typesOrModulesToFind.add(qualifiedNameProvider.getFullyQualifiedName(object));
} else if (object instanceof TModule) {
typesOrModulesToFind.add(qualifiedNameProvider.getFullyQualifiedName(object));
}
if (object instanceof IdentifiableElement) {
typesOrModulesToFind.add(qualifiedNameProvider
.getFullyQualifiedName(((IdentifiableElement) object).getContainingModule()));
}
}
示例8: getRootTypeRef
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
* Type references may be nested within other type references, e.g. the members of a union type. This method will
* return the outermost type reference that contains the given type reference but is not itself contained in another
* type reference, or the given type reference if it is not contained in another type reference.
* <p>
* Returns <code>null</code> if given <code>null</code>.
*/
public static TypeRef getRootTypeRef(TypeRef typeRef) {
if (typeRef != null) {
while (true) {
final TypeRef nextOuter = EcoreUtil2.getContainerOfType(typeRef.eContainer(), TypeRef.class);
if (nextOuter == null)
break;
typeRef = nextOuter;
}
}
return typeRef;
}
示例9: getScope
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
* Same as {@link #getScope(IdentifiableElement)}, but takes any kind of AST node. Flag <code>isBlockScoped</code>
* can be used to determine whether the scope for "block scoped" elements should be returned (i.e. let, const) or
* the scope for ordinarily scoped elements (e.g. var).
*/
public static VariableEnvironmentElement getScope(EObject astNode, boolean isBlockScoped) {
VariableEnvironmentElement scope = EcoreUtil2.getContainerOfType(astNode, VariableEnvironmentElement.class);
if (!isBlockScoped) {
while (scope != null && scope.appliesOnlyToBlockScopedElements()) {
scope = EcoreUtil2.getContainerOfType(scope.eContainer(), VariableEnvironmentElement.class);
}
}
return scope;
}
示例10: getContainingExpression
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
* The parent expression, in which an expression is contained, may be null
*/
public static Expression getContainingExpression(EObject eobj) {
if (eobj == null || eobj.eContainer() == null) {
return null;
}
return EcoreUtil2.getContainerOfType(eobj.eContainer(), Expression.class);
}
示例11: findScript
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/** Searches the script node in the given input. */
private Script findScript(Object input) {
if (input instanceof ResourceSet) {
ResourceSet rs = (ResourceSet) input;
if (!rs.getResources().isEmpty()) {
Resource res = rs.getResources().get(0);
EList<EObject> contents = res.getContents();
if (!contents.isEmpty()) {
Script script = EcoreUtil2.getContainerOfType(contents.get(0), Script.class);
return script;
}
}
}
return null;
}
示例12: getContainingFunction
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
* The function or method in which the expression is (indirectly) contained, may be null In most cases it is
* recommended to call {@link #getContainingFunctionOrAccessor(EObject)} instead.
*/
public static FunctionDefinition getContainingFunction(EObject eobj) {
if (eobj == null || eobj.eContainer() == null) {
return null;
}
return EcoreUtil2.getContainerOfType(eobj.eContainer(), FunctionDefinition.class);
}
示例13: getContainingFunctionOrAccessor
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
* The function or method in which the given location is (indirectly) contained, may be null. If a function or
* method is passed in, it won't be returned itself but the next outer function or method will be returned (so, this
* method behaves differently than {@link EcoreUtil2#getContainerOfType(EObject, Class)}).
*/
public static FunctionOrFieldAccessor getContainingFunctionOrAccessor(EObject eobj) {
if (eobj == null || eobj.eContainer() == null) {
return null;
}
return EcoreUtil2.getContainerOfType(eobj.eContainer(), FunctionOrFieldAccessor.class);
}
示例14: tau
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
* Convenience method. Infers the context of <code>element</code> using the {@link org.eclipse.xtext.EcoreUtil2}
* class.<br/>
* <br/>
* WARNING: does not handle all cases yet!<br/>
* TODO refactor uses of #tau() methods to have general approach of deriving rule env from AST node
*/
public TypeRef tau(TypableElement element, EObject astNodeForContext) {
TypeDefiningElement tde = EcoreUtil2.getContainerOfType(astNodeForContext, TypeDefiningElement.class);
TypeRef context = null;
if (tde != null) {
context = TypeUtils.createTypeRef(tde.getDefinedType());
}
return tau(element, context);
}
示例15: isInternalCheckProtectedVisibile
import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
/**
* Unified internal check for visibility focusing on protected-stage only. Used in
* {@link #isProtectedVisible(Type, TModule, Type, TMember, boolean)} and
* {@link #isProtectedInternalVisible(Type, TModule, Type, TMember, boolean)}
*
* <p>
* Preconditions:
* <ol>
* <li>contextType != declaredReceiverType
* </ol>
*
* @param contextModule
* module where the access is issued.
* @param contextType
* containing type where the access is issued, eg. the container-type of the method, can be null if
* access happens on top-level
* @param member
* member to access.
* @param declaredReceiverType
* type on which the member will be accessed on. Not necessarily the definition type of the member but
* one of it's sub-types.
* @param supercall
* true if super-keyword was used.
*/
private boolean isInternalCheckProtectedVisibile(Type contextType, TModule contextModule,
Type declaredReceiverType, TMember member, boolean supercall) {
// Protected means, that the context-type is a sub-type of the receiver-type
if (contextType == null) {
// not type information available, maybe just parsing the script: context is relevant here.
return false;
}
// contextType must be a super-type of declaredRecieverType:
List<TClassifier> receiverSuperTypes = AllSuperTypesCollector.collect((TClassifier) declaredReceiverType);
if (!receiverSuperTypes.contains(contextType)) {
// Problem: if super-keyword was usesed, the call is still valid.
if (!supercall) {
return false;
}
}
// and the member is part of a super-type (including default-method of implemented interfaces) of the
// receiver-type
TClassifier memberClsfContainer = EcoreUtil2.getContainerOfType(member, TClassifier.class);
if (declaredReceiverType instanceof TClassifier &&
receiverSuperTypes.contains(memberClsfContainer)) {
// definition of member is done in the super-type-tree of the receiver.
return true;
}
return false;
}