本文整理汇总了Java中org.eclipse.xtext.resource.IEObjectDescription.getEObjectOrProxy方法的典型用法代码示例。如果您正苦于以下问题:Java IEObjectDescription.getEObjectOrProxy方法的具体用法?Java IEObjectDescription.getEObjectOrProxy怎么用?Java IEObjectDescription.getEObjectOrProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.resource.IEObjectDescription
的用法示例。
在下文中一共展示了IEObjectDescription.getEObjectOrProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPolyfillTypesFromScope
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
private List<Type> getPolyfillTypesFromScope(QualifiedName fqn) {
IScope contextScope = polyfillScopeAccess.getRecordingPolyfillScope(contextResource);
List<Type> types = new ArrayList<>();
// contextScope.getElements(fqn) returns all polyfills, since shadowing is handled differently
// for them!
for (IEObjectDescription descr : contextScope.getElements(fqn)) {
Type polyfillType = (Type) descr.getEObjectOrProxy();
if (polyfillType.eIsProxy()) {
// TODO review: this seems odd... is this a test setup problem (since we do not use the
// index
// there and load the resource separately)?
polyfillType = (Type) EcoreUtil.resolve(polyfillType, contextResource);
if (polyfillType.eIsProxy()) {
throw new IllegalStateException("unexpected proxy");
}
}
types.add(polyfillType);
}
// }
return types;
}
示例2: isAccepted
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@Override
protected boolean isAccepted(IEObjectDescription description) {
EObject proxyOrInstance = description.getEObjectOrProxy();
if (proxyOrInstance instanceof TVariable && !proxyOrInstance.eIsProxy()) {
TVariable type = (TVariable) proxyOrInstance;
TypeVisibility visibility = checker.isVisible(this.contextResource, type);
if (!visibility.visibility) {
this.accessModifierSuggestionStore.put(description.getEObjectURI().toString(),
visibility.accessModifierSuggestion);
}
return visibility.visibility;
}
return super.isAccepted(description);
}
示例3: isAccepted
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@Override
protected boolean isAccepted(IEObjectDescription description) {
EObject proxyOrInstance = description.getEObjectOrProxy();
if (proxyOrInstance != null && !proxyOrInstance.eIsProxy()) {
if (proxyOrInstance instanceof TMember) {
TMember member = (TMember) proxyOrInstance;
MemberVisibility result = checker.isVisible(context, receiverType, member);
if (!result.visibility)
this.accessModifierSuggestionStore.put(description.getEObjectURI().toString(),
result.accessModifierSuggestion);
return result.visibility;
} else if (proxyOrInstance instanceof TEnumLiteral) {
return checker.isEnumLiteralVisible(context, receiverType);
}
}
return true;
}
示例4: testResolveSuperTypeOfBuiltInType
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@SuppressWarnings("javadoc")
@Test
public void testResolveSuperTypeOfBuiltInType() {
BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
IEObjectDescription intDescription = scope.getSingleElement(QualifiedName.create("i18nKey")); // trigger loading
PrimitiveType intType = (PrimitiveType) intDescription.getEObjectOrProxy();
PrimitiveType assCompatType = intType.getAssignmentCompatible();
Assert.assertFalse(assCompatType.eIsProxy());
Assert.assertEquals("string", assCompatType.getName());
}
示例5: getEObjectOrProxy
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
/**
* Returns a reference to the instance with the given qualified name.
*
* @return an optional reference.
*/
protected <T extends EObject> T getEObjectOrProxy(QualifiedName qn) {
IEObjectDescription description = getSingleElement(qn);
if (description == null)
throw new IllegalStateException(qn + " is not contained in this scope");
@SuppressWarnings("unchecked")
T result = (T) description.getEObjectOrProxy();
return result;
}
示例6: loadTClass
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
private Optional<TClass> loadTClass(final ResourceSet resSet, final IEObjectDescription objDesc) {
if (T_CLASS.isSuperTypeOf(objDesc.getEClass())) {
final EObject objectOrProxy = objDesc.getEObjectOrProxy();
final EObject object = objectOrProxy.eIsProxy() ? EcoreUtil.resolve(objectOrProxy, resSet) : objectOrProxy;
if (!object.eIsProxy()) {
return fromNullable((TClass) object);
}
}
return absent();
}
示例7: getText
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@Override
public String getText(Object element) {
if (element instanceof ImportableObject) {
ImportableObject io = (ImportableObject) element;
return getText(io.getTe());
}
if (element instanceof ImportProvidedElement) {
ImportProvidedElement ele = ((ImportProvidedElement) element);
TModule tm = ((ImportDeclaration) ele.importSpec.eContainer()).getModule();
return ele.localname + " from " + findLocation(tm);
}
if (element instanceof IEObjectDescription) {
IEObjectDescription ieod = (IEObjectDescription) element;
EObject eo = ieod.getEObjectOrProxy();
if (eo instanceof TExportableElement && !eo.eIsProxy()) {
return getText(eo);
}
return ieod.getName().getLastSegment() + " from "
+ qualifiedNameConverter.toString(ieod.getName().skipLast(1));
}
if (element instanceof TExportableElement) {
TExportableElement te = (TExportableElement) element;
return te.getName() + " (exported as " + te.getExportedName() + ") from "
+ findLocation(te.getContainingModule());
}
return n4Labelprovider.getText(element);
}
示例8: getAliasedDescription
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
/**
* Creates proposal taking semantics of the N4JS imports into account.
*
* @param candidate
* the original input for which we create proposal
* @param reference
* the reference
* @param context
* the context
* @return candidate proposal adjusted to the N4JS imports
*/
private IEObjectDescription getAliasedDescription(IEObjectDescription candidate, EReference reference,
ContentAssistContext context) {
// Content assist at a location where only simple names are allowed:
// We found a qualified name and we'd need an import to be allowed to use
// that name. Consider only the simple name of the element from the index
// and make sure that the import is inserted as soon as the proposal is applied
QualifiedName inputQN = candidate.getName();
int inputNameSegmentCount = inputQN.getSegmentCount();
if (reference == N4JSPackage.Literals.IDENTIFIER_REF__ID && inputNameSegmentCount > 1)
return new AliasedEObjectDescription(QualifiedName.create(inputQN.getLastSegment()), candidate);
// filter out non-importable things:
// globally provided things should never be imported:
if (inputNameSegmentCount == 2 && N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT
.equals(inputQN.getFirstSegment()))
return new AliasedEObjectDescription(QualifiedName.create(inputQN.getLastSegment()), candidate);
// special handling for default imports:
if (inputQN.getLastSegment().equals(N4JSLanguageConstants.EXPORT_DEFAULT_NAME)) {
EObject element = candidate.getEObjectOrProxy();
if (element instanceof TExportableElement) {
TExportableElement exported = (TExportableElement) element;
if (N4JSLanguageConstants.EXPORT_DEFAULT_NAME.equals(exported.getExportedName())) {
return new AliasedEObjectDescription(inputQN, candidate);
}
}
// not accessed via namespace
QualifiedName nameNoDefault = inputQN.skipLast(1);
QualifiedName moduleName = nameNoDefault.getSegmentCount() > 1
? QualifiedName.create(nameNoDefault.getLastSegment()) : nameNoDefault;
return new AliasedEObjectDescription(moduleName, candidate);
}
// no special handling, return original input
return candidate;
}
示例9: getLinkedObjects
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
final EClass requiredType = ref.getEReferenceType();
if (requiredType == null)
return Collections.<EObject> emptyList();
final String crossRefString = getCrossRefNodeAsString(context, ref, node);
if (crossRefString != null && !crossRefString.equals("")) {
final IScope scope = getScope(context, ref);
QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
if (IEObjectDescriptionWithError.isErrorDescription(eObjectDescription) && context.eResource() != null
&& !n4jsCore.isNoValidate(context.eResource().getURI())) {
addError(context, node, IEObjectDescriptionWithError.getDescriptionWithError(eObjectDescription));
} else if (eObjectDescription instanceof UnresolvableObjectDescription) {
return Collections.<EObject> singletonList((EObject) context.eGet(ref, false));
}
if (eObjectDescription != null) {
EObject candidate = eObjectDescription.getEObjectOrProxy();
if (!candidate.eIsProxy() && candidate.eResource() == null) {
// Error is necessary since EMF catches all exceptions in EcoreUtil#resolve
throw new AssertionError("Found an instance without resource and without URI");
}
return Collections.singletonList(candidate);
}
}
return Collections.emptyList();
}
示例10: wrapFilteredDescription
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@Override
protected IEObjectDescriptionWithError wrapFilteredDescription(IEObjectDescription originalDescr) {
EObject proxyOrInstance = originalDescr.getEObjectOrProxy();
// The cast to TClassifier always works (see the method isAccepted below).
TClassifier ctorClassifier = (TClassifier) proxyOrInstance;
return new InvisibleCtorDescription(originalDescr, ctorClassifier);
}
示例11: isAccepted
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@Override
protected boolean isAccepted(IEObjectDescription description) {
EObject proxyOrInstance = description.getEObjectOrProxy();
if (proxyOrInstance != null && !proxyOrInstance.eIsProxy()) {
if (proxyOrInstance instanceof TClassifier) {
TClassifier ctorClassifier = (TClassifier) proxyOrInstance;
// If the class is found, check if the visibility of the constructor is valid
TMethod usedCtor = containerTypesHelper.fromContext(context).findConstructor(ctorClassifier);
if (usedCtor != null && usedCtor.isConstructor()) {
return checker.isConstructorVisible(context, TypeUtils.createTypeRef(ctorClassifier), usedCtor);
}
}
}
return true;
}
示例12: findMemberInSubScope
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
/**
* Searches for a member of the given name and for the given access in the sub-scope with index 'subScopeIdx'.
*/
private TMember findMemberInSubScope(IScope subScope, String name) {
final IEObjectDescription currElem = subScope.getSingleElement(QualifiedName.create(name));
if (currElem != null) {
final EObject objOrProxy = currElem.getEObjectOrProxy();
if (objOrProxy != null && !objOrProxy.eIsProxy() && objOrProxy instanceof TMember) {
final TMember currM = (TMember) objOrProxy;
return currM;
}
}
return null;
}
示例13: initialize
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
private boolean initialize() {
if (message == null) {
IEObjectDescription[] descriptions = new IEObjectDescription[subScopes.length];
MapOfIndexes<String> indexesPerMemberType = new MapOfIndexes<>(); // use string here, since EnumLiteral is
// not a TMember!
MapOfIndexes<String> indexesPerCode = new MapOfIndexes<>();
List<String> missingFrom = new ArrayList<>();
final QualifiedName name = getName();
boolean readOnlyField = false;
for (int i = 0; i < max; i++) {
IEObjectDescription description = subScopes[i].getSingleElement(name);
if (description != null) {
descriptions[i] = description;
EObject eobj = description.getEObjectOrProxy();
String type = getMemberTypeName(eobj);
indexesPerMemberType.add(type, i);
if (description instanceof IEObjectDescriptionWithError) {
String subCode = ((IEObjectDescriptionWithError) description).getIssueCode();
indexesPerCode.add(subCode, i);
}
if ("field".equals(type)) {
readOnlyField |= !((TField) eobj).isWriteable();
}
} else {
missingFrom.add(getNameForSubScope(i));
}
}
return initMessageAndCode(missingFrom, indexesPerMemberType, name, readOnlyField, descriptions,
indexesPerCode);
}
return false;
}
示例14: descriptionToNameWithPosition
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
/**
* Returns a string with name and position of the described object. The position is specified by line number (if
* possible, otherwise the uri fragment of the proxy is used). If the object is a {@link SyntaxRelatedTElement}, a
* "T" is used as a prefix of the line number.
*
* The following examples shows different mappings, depending on the described object:
* <table>
* <tr>
* <th>Mapping</th>
* <th>Described Object</th>
* </tr>
* <tr>
* <td><code>bar - 42</code></td>
* <td>Some element "bar", located in same resource on line 42</td>
* </tr>
* <tr>
* <td><code>foo - T23</code></td>
* <td>A type "foo" (or other syntax related element, a function is a type) which syntax related element (from which
* the type is build) is located in same file on line 23</td>
* </tr>
* <tr>
* <td><code>Infinity - global.n4ts:3</code></td>
* <td>An element "Infinity", located in another resource "global.n4ts" on line 3.</td>
* </tr>
* <tr>
* <td><code>decodeURI - global.n4ts:11</code></td>
* <td>An element "decodeURI", located in another resource "global.n4ts" on line 11. Although the element may be a
* type, there is no syntax related element because "n4ts" directly describes types.</td>
* </tr>
* </table>
*
* @param currentURI
* the current resource's URI, if described object is in same resource, resource name is omitted
* @param desc
* the object descriptor
*/
public static String descriptionToNameWithPosition(URI currentURI, boolean withLineNumber,
IEObjectDescription desc) {
String name = desc.getName().toString();
EObject eobj = desc.getEObjectOrProxy();
if (eobj == null) {
return "No EObject or proxy for " + name + " at URI " + desc.getEObjectURI();
}
String location = "";
if (eobj instanceof SyntaxRelatedTElement) {
EObject syntaxElement = ((SyntaxRelatedTElement) eobj).getAstElement();
if (syntaxElement != null) {
location += "T";
eobj = syntaxElement;
}
}
Resource eobjRes = eobj.eResource();
URI uri = eobjRes == null ? null : eobjRes.getURI();
if (uri != currentURI && uri != null) {
location = uri.lastSegment();
if (eobj.eIsProxy() || withLineNumber) {
location += ":";
}
}
if (eobj.eIsProxy()) {
URI proxyUri = desc.getEObjectURI();
location += "proxy:" + simpleURIString(proxyUri);
} else if (withLineNumber) {
INode node = NodeModelUtils.findActualNodeFor(eobj);
if (node == null) {
location += "no node:" + simpleURIString(desc.getEObjectURI());
} else {
location += node.getStartLine();
}
}
return name + SEPARATOR + location;
}
示例15: isAccepted
import org.eclipse.xtext.resource.IEObjectDescription; //导入方法依赖的package包/类
@Override
protected boolean isAccepted(IEObjectDescription description) {
EObject proxyOrInstance = description.getEObjectOrProxy();
if (proxyOrInstance instanceof TMember && !proxyOrInstance.eIsProxy()) {
TMember member = (TMember) proxyOrInstance;
// check correct static access of fields or setters.
// if member is const (i.e. not writeable), other error messages will be created anyway and we do not want
// this particular message to hide the better one.
if (member.isStatic() && member.isWriteable() /* i.e. (member.isField(), not const || member.isSetter()) */
&& isWriteAccess()) {
ContainerType<?> memberType = member.getContainingType();
memberTypeName = memberType.getName();
// Access only allowed for Direct access, so AST must be IdentifierRef.
final boolean isTargetGivenByIdentifier = getTarget() instanceof IdentifierRef;
if (!isTargetGivenByIdentifier) {
// Not an IdentifierRef --> disallowed for write access.
return false;
}
IdentifierRef idref = (IdentifierRef) getTarget();
// this also covers aliased imports:
if (idref.getId().getName().equals(memberTypeName)) {
// correct name.
return true;
} else {
// wrong name, disallowed
// search for alias, for better error reporting.
Script sc = EcoreUtil2.getContainerOfType(context, Script.class);
Optional<NamedImportSpecifier> namedImport = sc.getScriptElements().stream()
.filter(se -> se instanceof ImportDeclaration)
.map(se -> (ImportDeclaration) se)
.flatMap(idecl -> {
return idecl.getImportSpecifiers().stream()
.filter(is -> is instanceof NamedImportSpecifier)
.map(is -> (NamedImportSpecifier) is);
})
.filter(s -> s.getImportedElement() == memberType)
.findFirst();
if (namedImport.isPresent()) {
// if alias is present assign, otherwise null will be passed through
memberTypeAlias = namedImport.get().getAlias();
}
return false;
}
}
}
return true;
}