/** * The Xtend parser constructs a synthetic nested AST element to hold annotations which should be ignored as a documentation provider */ public boolean shouldBeHandled(final EObject o) { return (!((o instanceof XtendAnnotationTarget) && Objects.equal(o.eContainingFeature(), XtendPackage.Literals.XTEND_MEMBER__ANNOTATION_INFO))); } }
/** * @return the previous sibling of the passed eObject or null * @since 2.1 */ public static EObject getPreviousSibling(EObject eObject) { EObject previous = null; if (eObject.eContainingFeature()!=null && eObject.eContainingFeature().isMany()) { @SuppressWarnings("unchecked") List<EObject> siblings = (List<EObject>) eObject.eContainer().eGet(eObject.eContainingFeature()); int indexOf = siblings.indexOf(eObject); if (indexOf > 0) { previous = siblings.get(indexOf - 1); } } return previous; }
/** * @return the next sibling of the passed eObject or null * @since 2.1 */ public static EObject getNextSibling(EObject eObject) { EObject next = null; if (eObject.eContainingFeature()!=null && eObject.eContainingFeature().isMany()) { @SuppressWarnings("unchecked") List<EObject> siblings = (List<EObject>) eObject.eContainer().eGet(eObject.eContainingFeature()); int indexOf = siblings.indexOf(eObject); if (indexOf < siblings.size() - 1) { next = siblings.get(indexOf + 1); } } return next; }
protected boolean isStaticMemberCallTarget(final EObject contextObject) { boolean candidate = ((contextObject instanceof XFeatureCall) && (contextObject.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET)); if (candidate) { EObject _eContainer = contextObject.eContainer(); XMemberFeatureCall memberFeatureCall = ((XMemberFeatureCall) _eContainer); boolean _isExplicitStatic = memberFeatureCall.isExplicitStatic(); if (_isExplicitStatic) { return true; } } return false; }
private static void objPath(StringBuffer b, EObject obj) { if (obj.eContainer() != null) { objPath(b, obj.eContainer()); b.append("."); b.append(obj.eContainingFeature().getName()); if (obj.eContainingFeature().isMany()) { b.append("["); b.append(((List<?>) obj.eContainer().eGet(obj.eContainingFeature())).indexOf(obj)); b.append("]"); } b.append("->"); } b.append(obj.eClass().getName()); EStructuralFeature nameF = obj.eClass().getEStructuralFeature("name"); Object name = nameF != null ? obj.eGet(nameF) : null; if (name != null) { b.append("'"); b.append(name); b.append("'"); } } }
private static void objPath(StringBuffer b, EObject obj) { if (obj.eContainer() != null) { objPath(b, obj.eContainer()); b.append("."); b.append(obj.eContainingFeature().getName()); if (obj.eContainingFeature().isMany()) { b.append("["); b.append(((List<?>) obj.eContainer().eGet(obj.eContainingFeature())).indexOf(obj)); b.append("]"); } b.append("->"); } b.append(obj.eClass().getName()); EStructuralFeature nameF = obj.eClass().getEStructuralFeature("name"); Object name = nameF != null ? obj.eGet(nameF) : null; if (name != null) { b.append("'"); b.append(name); b.append("'"); } } }
protected static StringBuffer getQualifiedTextSegment(EObject eObject, QualifiedTextProvider qualifiedTextProvider, StringBuffer qualifiedText) { String text = qualifiedTextProvider.getText(eObject); if (!isEmpty(text)) { return qualifiedText.append(text); } else if (eObject == null) { return qualifiedText.append(String.valueOf(eObject)); } qualifiedText.append('{'); EStructuralFeature eContainingFeature = eObject.eContainingFeature(); if (eContainingFeature != null) { qualifiedText.append(qualifiedTextProvider .getFeatureText(eContainingFeature)); if (eContainingFeature.isMany()) { qualifiedText.append(' '); List<?> list = (List<?>) eObject.eContainer().eGet( eContainingFeature, false); qualifiedText.append('['); qualifiedText.append(list.indexOf(eObject)); qualifiedText.append(']'); } qualifiedText.append(' '); } qualifiedText.append(qualifiedTextProvider.getClassText(eObject)); qualifiedText.append('}'); return qualifiedText; }
protected static StringBuffer getQualifiedTextSegment(EObject eObject, QualifiedTextProvider qualifiedTextProvider, StringBuffer qualifiedText) { String text = qualifiedTextProvider.getText(eObject); if (!isEmpty(text)) { return qualifiedText.append(text); } else if (eObject == null) { return qualifiedText.append(String.valueOf(eObject)); } qualifiedText.append('{'); EStructuralFeature eContainingFeature = eObject.eContainingFeature(); if (eContainingFeature != null) { qualifiedText.append(qualifiedTextProvider .getFeatureText(eContainingFeature)); if (eContainingFeature.isMany()) { qualifiedText.append(' '); List<?> list = (List<?>) eObject.eContainer().eGet( eContainingFeature, false); qualifiedText.append('['); qualifiedText.append(list.indexOf(eObject)); qualifiedText.append(']'); } qualifiedText.append(' '); } qualifiedText.append(qualifiedTextProvider.getClassText(eObject)); qualifiedText.append('}'); return qualifiedText; }
@Check public void checkDupplicateTemplatesInComponentType(final ElementTypeWithInteractions componentType) { final HashMap<String, EObject> mapTemplateCode2InteractionType = CollectionLiterals.<String, EObject>newHashMap(); final Consumer<InteractionType> _function = (InteractionType it) -> { String templateCode = this._modelUtil.normalize(it.getTemplate()); boolean _containsKey = mapTemplateCode2InteractionType.containsKey(templateCode); if (_containsKey) { this.error(Messages.Validation_TemplateCode_NotUnique, componentType, componentType.eContainer().eContainingFeature(), AmlValidator.TEMPLATE_CODE_NOT_UNIQUE); this.error(Messages.Validation_TemplateCode_NotUnique, mapTemplateCode2InteractionType.get(templateCode), mapTemplateCode2InteractionType.get(templateCode).eContainer().eContainingFeature(), AmlValidator.TEMPLATE_CODE_NOT_UNIQUE); this.error(Messages.Validation_TemplateCode_NotUnique, it, it.eContainer().eContainingFeature(), AmlValidator.TEMPLATE_CODE_NOT_UNIQUE); } else { mapTemplateCode2InteractionType.put(templateCode, it); } }; componentType.getInteractionTypes().forEach(_function); }
@Check public void checkInteractionNameIsUnique(final AmlModel amlModel) { final HashMap<String, EObject> mapInteractionName2InteractionTypes = CollectionLiterals.<String, EObject>newHashMap(); final Consumer<InteractionType> _function = (InteractionType it) -> { boolean _containsKey = mapInteractionName2InteractionTypes.containsKey(it.getName()); if (_containsKey) { final String message = MessageFormat.format(Messages.Validation_InteractionType_Name_Dublicate, it.getName()); this.error(message, mapInteractionName2InteractionTypes.get(it.getName()), mapInteractionName2InteractionTypes.get(it.getName()).eContainer().eContainingFeature(), AmlValidator.INTERACTION_NAME_DUPLICATION); this.error(message, it, it.eContainer().eContainingFeature(), AmlValidator.INTERACTION_NAME_DUPLICATION); } else { mapInteractionName2InteractionTypes.put(it.getName(), it); } }; amlModel.getInteractionTypes().forEach(_function); }
public static String getPath(EObject eObject) { String path = ""; while (eObject != null && !(eObject instanceof DocumentRoot)) { EStructuralFeature feature = eObject.eContainingFeature(); EObject container = eObject.eContainer(); Object value = container.eGet(feature); if (feature.isMany()) { List<?> list = (List<?>) value; int index = list.indexOf(eObject) + 1; path = "/" + feature.getName() + "[" + index + "]" + path; } else { path = "/" + feature.getName() + "[1]" + path; } eObject = eObject.eContainer(); } return path; }
private EObject getNearestClosureOrTypeDeclaration(EObject object, IResolvedTypes resolvedTypes) { EObject candidate = object; while(candidate != null) { if (candidate instanceof XClosure) { return candidate; } if (candidate instanceof XConstructorCall) { // skip anonymous class constructors themselves if (candidate.eContainingFeature() == XtendPackage.Literals.ANONYMOUS_CLASS__CONSTRUCTOR_CALL) { candidate = candidate.eContainer(); } } else if (candidate instanceof XtendTypeDeclaration) { return candidate; } if (candidate instanceof RichString) { LightweightTypeReference type = resolvedTypes.getActualType((RichString)candidate); if (type != null && type.isType(StringConcatenationClient.class)) { return candidate; } } candidate = candidate.eContainer(); } return null; } }
@Check public void checkElementOrder(ServiceDataResource serviceDataResource) { String settingName = NLS.bind(Messages.RepreZenValidatorConfigurationBlock_random_order_issue_key_all, serviceDataResource.eClass().getName()); String setting = preferences.getString(settingName); if (!SeverityConverter.SEVERITY_IGNORE.equals(setting)) { List<INode> nodes = elementOrderSorter.getIncorrectOrderChildren(serviceDataResource); for (INode n : nodes) { if (n.getGrammarElement() instanceof Keyword) { settingName = NLS.bind(Messages.RepreZenValidatorConfigurationBlock_random_order_issue_key, serviceDataResource.eClass().getName(), ((Keyword) n.getGrammarElement()).getValue()); setting = preferences.getString(settingName); if (!SeverityConverter.SEVERITY_IGNORE.equals(setting)) { EObject semanticElement = findActualSemanticObject(n, serviceDataResource); if (serviceDataResource != semanticElement) { warning(NLS.bind(Messages.XtextDslJavaValidator_incorrect_order_warning, ((Keyword) n.getGrammarElement()).getValue()), semanticElement instanceof EStructuralFeature ? (EStructuralFeature) semanticElement : semanticElement.eContainingFeature(), INCORRECT_ELEMENT_ORDER, serviceDataResource.getName()); } } } } } }
@SuppressWarnings("all") private EObject getNearestClosureOrTypeDeclaration(EObject object, IResolvedTypes resolvedTypes) { // Overriding for proper lambda expression. EObject candidate = object; while(candidate != null) { if (candidate instanceof XClosure) { return candidate; } if (candidate instanceof XConstructorCall) { // skip anonymous class constructors themselves if (candidate.eContainingFeature() == XtendPackage.Literals.ANONYMOUS_CLASS__CONSTRUCTOR_CALL) { candidate = candidate.eContainer(); } } else if (candidate instanceof XtendTypeDeclaration) { return candidate; } if (candidate instanceof RichString) { LightweightTypeReference type = resolvedTypes.getActualType((RichString)candidate); if (type != null && type.isType(StringConcatenationClient.class)) { return candidate; } } candidate = candidate.eContainer(); } return null; }
public static String getPath(EObject eObject) { String path = ""; while (eObject != null && !(eObject instanceof DocumentRoot)) { EStructuralFeature feature = eObject.eContainingFeature(); EObject container = eObject.eContainer(); Object value = container.eGet(feature); if (feature.isMany()) { List<?> list = (List<?>) value; int index = list.indexOf(eObject) + 1; if (index > 1) { path = "/" + getName(feature) + "[" + index + "]" + path; } else { path = "/" + getName(feature) + path; } } else { path = "/" + getName(feature) + path; } eObject = eObject.eContainer(); } return path; }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void replaceOldSemanticElement(EObject oldElement, IParseResult previousParseResult, IParseResult newParseResult) { EObject oldSemanticParentElement = oldElement.eContainer(); if (oldSemanticParentElement != null) { EStructuralFeature feature = oldElement.eContainingFeature(); if (feature.isMany()) { List featureValueList = (List) oldSemanticParentElement.eGet(feature); int index = featureValueList.indexOf(oldElement); unloadSemanticObject(oldElement); featureValueList.set(index, newParseResult.getRootASTElement()); } else { unloadSemanticObject(oldElement); oldSemanticParentElement.eSet(feature, newParseResult.getRootASTElement()); } ((ParseResult) newParseResult).setRootASTElement(previousParseResult.getRootASTElement()); } else { unloadSemanticObject(oldElement); } }
/** * @return the location data for the given diagnostic. */ protected IssueLocation getLocationData(EObject obj, EStructuralFeature structuralFeature, int index) { INode parserNode = NodeModelUtils.getNode(obj); if (parserNode != null) { if (structuralFeature != null) { List<INode> nodes = NodeModelUtils.findNodesForFeature(obj, structuralFeature); if (index < 0) // insignificant index index = 0; if (nodes.size()>index) parserNode = nodes.get(index); } return getLocationForNode(parserNode); } else if (obj.eContainer() != null) { EObject container = obj.eContainer(); EStructuralFeature containingFeature = obj.eContainingFeature(); return getLocationData(container, containingFeature, containingFeature.isMany() ? ((EList<?>) container.eGet(containingFeature)).indexOf(obj) : ValidationMessageAcceptor.INSIGNIFICANT_INDEX); } IssueLocation result = new IssueLocation(); result.lineNumber = 0; result.offset = 0; result.length = 0; return result; }
@Override protected void doRemove(EObject object) throws ModelManipulationException { Command removeCommand = null; if (object.eContainer() != null) { /* * We must explicitly use container and feature to make this work in non-OSGi environment, otherwise the * command creation tries to find the parent using item providers that are registered by extension points * (or manually be the user) */ removeCommand = RemoveCommand.create(domain, object.eContainer(), object.eContainingFeature(), object); } else { // DeleteCommand cannot deal with root objects removeCommand = new RemoveCommand(domain, object.eResource().getContents(), object); } executeCommand(removeCommand); }
protected <EO extends EObject> List<EO> getMatchCandidates(EO eObject) { Element baseElement = getBaseElement(eObject); if (baseElement == null) { EStructuralFeature eContainingFeature = eObject .eContainingFeature(); if (eContainingFeature.isMany()) { @SuppressWarnings("unchecked") List<EO> values = (List<EO>) get(eObject.eContainer()) .eGet(eContainingFeature); return values; } else { @SuppressWarnings("unchecked") EO value = (EO) get(eObject.eContainer()).eGet( eContainingFeature); return Collections.<EO> singletonList(value); } } else { @SuppressWarnings("unchecked") List<EO> stereotypeApplications = (List<EO>) ((Element) get(baseElement)) .getStereotypeApplications(); return stereotypeApplications; } }
@Test @SuppressWarnings("unchecked") public void multiplicityManyContainmentWithoutOppositeRefWorks() { this.createEPackageMultiplicityManyContainmentNoOpposite(); EPackage ePackage = this.getEPackageByNsURI("http://www.example.com/model"); EClass myClass = (EClass) ePackage.getEClassifier("MyEClass"); EClass yourClass = (EClass) ePackage.getEClassifier("YourEClass"); assertNotNull(myClass); assertNotNull(yourClass); EAttribute myAttribute = (EAttribute) myClass.getEStructuralFeature("MyAttribute"); EReference myReference = (EReference) myClass.getEStructuralFeature("children"); EObject eObj1 = this.createEObject(myClass); EObject eObj2 = this.createEObject(yourClass); // assign a property to eObj1 assertNull(eObj1.eGet(myAttribute)); eObj1.eSet(myAttribute, "Hello World!"); assertEquals("Hello World!", eObj1.eGet(myAttribute)); // assign a reference target to eObj1 ((List<EObject>) eObj1.eGet(myReference)).add(eObj2); // get the EContainer of eObj2 assertEquals(eObj1, eObj2.eContainer()); // get the eContainingFeature of eObj2 assertEquals(myReference, eObj2.eContainingFeature()); // assert that our children reference was updated assertTrue(((List<EObject>) eObj1.eGet(myReference)).contains(eObj2)); // clear the list in eObj1#children ((List<EObject>) eObj1.eGet(myReference)).clear(); // get the EContainer of eObj2 assertNull(eObj2.eContainer()); }