org.eclipse.xtext.diagnostics.IDiagnosticProducer Java Examples
The following examples show how to use
org.eclipse.xtext.diagnostics.IDiagnosticProducer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private void ensureLinked(EObject obj, IDiagnosticProducer producer, ICompositeNode node, Set<EReference> handledReferences, boolean dontCheckParent) { for(INode abstractNode = node.getFirstChild(); abstractNode != null; abstractNode = abstractNode.getNextSibling()) { EObject grammarElement = abstractNode.getGrammarElement(); if (grammarElement instanceof CrossReference) { CrossReference ref = (CrossReference) grammarElement; producer.setNode(abstractNode); ensureIsLinked(obj, abstractNode, ref, handledReferences, producer); } else if (grammarElement instanceof RuleCall && abstractNode instanceof ICompositeNode) { RuleCall ruleCall = (RuleCall) grammarElement; AbstractRule calledRule = ruleCall.getRule(); if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) { ensureLinked(obj, producer, (ICompositeNode) abstractNode, handledReferences, true); } } } if (!dontCheckParent && shouldCheckParentNode(node)) { ensureLinked(obj, producer, node.getParent(), handledReferences, false); } }
Example #2
Source File: N4JSLinker.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Installs proxies for all non containment references and only if the node representing the EObject that contains * the cross reference has got leaf nodes (as a leaf node represents the cross reference). * * @param resource * the N4JSResource * @param obj * the EObject containing the cross reference * @param producer * the error/warning producer * @param parentNode * the node representing obj inside the node model */ private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer, ICompositeNode parentNode, boolean dontCheckParent) { final EClass eClass = obj.eClass(); if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0) return; for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) { EObject grammarElement = node.getGrammarElement(); if (grammarElement instanceof CrossReference && hasLeafNodes(node)) { producer.setNode(node); CrossReference crossReference = (CrossReference) grammarElement; final EReference eRef = GrammarUtil.getReference(crossReference, eClass); if (eRef == null) { ParserRule parserRule = GrammarUtil.containingParserRule(crossReference); final String feature = GrammarUtil.containingAssignment(crossReference).getFeature(); throw new IllegalStateException("Couldn't find EReference for crossreference '" + eClass.getName() + "::" + feature + "' in parser rule '" + parserRule.getName() + "'."); } createAndSetProxy(resource, obj, node, eRef, crossReference, producer); afterCreateAndSetProxy(obj, node, eRef, crossReference, producer); } else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) { RuleCall ruleCall = (RuleCall) grammarElement; AbstractRule calledRule = ruleCall.getRule(); if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) { installProxies(resource, obj, producer, (ICompositeNode) node, true); } } } if (!dontCheckParent && shouldCheckParentNode(parentNode)) { installProxies(resource, obj, producer, parentNode.getParent(), dontCheckParent); } }
Example #3
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void ensureModelLinked(EObject model, final IDiagnosticProducer producer) { boolean clearAllReferencesRequired = isClearAllReferencesRequired(model.eResource()); TreeIterator<EObject> iterator = getAllLinkableContents(model); while(iterator.hasNext()) { EObject next = iterator.next(); if (clearAllReferencesRequired) { clearReferences(next); } ensureLinked(next, producer); } }
Example #4
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private void setDefaultValues(EObject obj, Set<EReference> references, IDiagnosticProducer producer) { for (EReference ref : obj.eClass().getEAllReferences()) { if (canSetDefaultValues(ref) && !references.contains(ref) && !obj.eIsSet(ref) && !ref.isDerived()) { setDefaultValue(obj, ref, producer); } } }
Example #5
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void ensureLinked(EObject obj, IDiagnosticProducer producer) { ICompositeNode node = NodeModelUtils.getNode(obj); if (node == null) return; Set<EReference> handledReferences = new HashSet<EReference>(); ensureLinked(obj, producer, node, handledReferences, false); producer.setNode(node); setDefaultValues(obj, handledReferences, producer); }
Example #6
Source File: LazyLinker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private void installProxies(EObject obj, IDiagnosticProducer producer, Multimap<EStructuralFeature.Setting, INode> settingsToLink, ICompositeNode parentNode, boolean dontCheckParent) { final EClass eClass = obj.eClass(); if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0) return; for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) { EObject grammarElement = node.getGrammarElement(); if (grammarElement instanceof CrossReference && hasLeafNodes(node)) { producer.setNode(node); CrossReference crossReference = (CrossReference) grammarElement; final EReference eRef = GrammarUtil.getReference(crossReference, eClass); if (eRef == null) { ParserRule parserRule = GrammarUtil.containingParserRule(crossReference); final String feature = GrammarUtil.containingAssignment(crossReference).getFeature(); throw new IllegalStateException("Couldn't find EReference for crossreference '"+eClass.getName()+"::"+feature+"' in parser rule '"+parserRule.getName()+"'."); } if (!eRef.isResolveProxies() /*|| eRef.getEOpposite() != null see https://bugs.eclipse.org/bugs/show_bug.cgi?id=282486*/) { final EStructuralFeature.Setting setting = ((InternalEObject) obj).eSetting(eRef); settingsToLink.put(new SettingDelegate(setting), node); } else { createAndSetProxy(obj, node, eRef); afterCreateAndSetProxy(obj, node, eRef, crossReference, producer); } } else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) { RuleCall ruleCall = (RuleCall) grammarElement; AbstractRule calledRule = ruleCall.getRule(); if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) { installProxies(obj, producer, settingsToLink, (ICompositeNode) node, true); } } } if (!dontCheckParent && shouldCheckParentNode(parentNode)) { installProxies(obj, producer, settingsToLink, parentNode.getParent(), dontCheckParent); } }
Example #7
Source File: LazyLinker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void installProxies(EObject obj, IDiagnosticProducer producer, Multimap<EStructuralFeature.Setting, INode> settingsToLink) { ICompositeNode node = NodeModelUtils.getNode(obj); if (node == null) return; installProxies(obj, producer, settingsToLink, node, false); }
Example #8
Source File: XtextLinker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override protected void beforeEnsureIsLinked(EObject obj, EReference ref, IDiagnosticProducer producer) { if (XtextPackage.eINSTANCE.getTypeRef_Classifier() == ref) { final TypeRef typeRef = (TypeRef) obj; if (typeRef.getMetamodel() == null) setDefaultValue(obj, XtextPackage.eINSTANCE.getTypeRef_Metamodel(), producer); } else super.beforeEnsureIsLinked(obj, ref, producer); }
Example #9
Source File: Linker.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected void afterCreateAndSetProxy(EObject obj, INode node, EReference eRef, CrossReference xref, IDiagnosticProducer diagnosticProducer) { AbstractElement terminal = xref.getTerminal(); if (!(terminal instanceof RuleCall)) { throw new IllegalArgumentException(String.valueOf(xref)); } AbstractRule rule = ((RuleCall) terminal).getRule(); try { String tokenText = NodeModelUtils.getTokenText(node); valueConverterService.toValue(tokenText, rule.getName(), node); } catch(ValueConverterException e) { diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), Severity.ERROR, Diagnostic.SYNTAX_DIAGNOSTIC, Strings.EMPTY_ARRAY)); } }
Example #10
Source File: N4JSLinker.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Creates a proxy instance that will later on allow to lazily resolve the semantically referenced instance for the * given {@link CrossReference xref}. */ @SuppressWarnings("unchecked") private void createAndSetProxy(N4JSResource resource, EObject obj, INode node, EReference eRef, CrossReference xref, IDiagnosticProducer diagnosticProducer) { final EObject proxy = createProxy(resource, obj, node, eRef, xref, diagnosticProducer); proxy.eSetDeliver(false); if (eRef.isMany()) { ((InternalEList<EObject>) obj.eGet(eRef, false)).addUnique(proxy); } else { obj.eSet(eRef, proxy); } }
Example #11
Source File: N4JSLinker.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Installs only a proxy for EObjects that have a representation in the Xtext document node model. */ private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer) { ICompositeNode node = NodeModelUtils.getNode(obj); if (node == null) return; installProxies(resource, obj, producer, node, false); }
Example #12
Source File: XtextLinker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override protected void setDefaultValueImpl(EObject obj, EReference ref, IDiagnosticProducer producer) { if (XtextPackage.eINSTANCE.getTypeRef_Metamodel() == ref) { final TypeRef typeRef = (TypeRef) obj; final String typeRefName = GrammarUtil.getTypeRefName(typeRef); final List<EObject> metamodels = XtextMetamodelReferenceHelper.findBestMetamodelForType(typeRef, "", typeRefName, scopeProvider.getScope(typeRef, ref)); if (metamodels.isEmpty() || metamodels.size() > 1) producer.addDiagnostic(new DiagnosticMessage("Cannot find meta model for type '" + typeRefName + "'", Severity.ERROR, null)); else typeRef.setMetamodel((AbstractMetamodelDeclaration) metamodels.get(0)); } else if (XtextPackage.eINSTANCE.getCrossReference_Terminal() == ref) { AbstractRule rule = GrammarUtil.findRuleForName(GrammarUtil.getGrammar(obj), "ID"); if (rule == null) producer.addDiagnostic(new DiagnosticMessage("Cannot resolve implicit reference to rule 'ID'", Severity.ERROR, null)); else { RuleCall call = XtextFactory.eINSTANCE.createRuleCall(); call.setRule(rule); ((CrossReference) obj).setTerminal(call); } } else if (XtextPackage.eINSTANCE.getNamedArgument_Parameter() == ref) { final NamedArgument argument = (NamedArgument) obj; if (!argument.isCalledByName()) { RuleCall ruleCall = EcoreUtil2.getContainerOfType(argument, RuleCall.class); AbstractRule calledRule = ruleCall.getRule(); if (!(calledRule instanceof ParserRule)) { producer.addDiagnostic(new DiagnosticMessage("Arguments can only be used with parser rules.", Severity.ERROR, null)); return; } if (!calledRule.eIsProxy()) { ParserRule casted = (ParserRule) calledRule; int idx = ruleCall.getArguments().indexOf(argument); if (idx < casted.getParameters().size()) { argument.setParameter(casted.getParameters().get(idx)); return; } else if (casted.getParameters().size() == 0) { producer.addDiagnostic(new DiagnosticMessage( "Rule " + calledRule.getName() + " has no arguments.", Severity.ERROR, null)); } else { String message = "Invalid number of arguments for rule " + calledRule.getName() + ", expecting " + casted.getParameters().size() + " but was " + (idx+1); producer.addDiagnostic(new DiagnosticMessage(message, Severity.ERROR, null)); } } } } else { super.setDefaultValueImpl(obj, ref, producer); } }
Example #13
Source File: LazyLinker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.7 */ protected void afterCreateAndSetProxy(EObject obj, INode node, EReference eRef, CrossReference crossReference, IDiagnosticProducer producer) { }
Example #14
Source File: N4JSLinker.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Creates the proxy with a custom encoded URI format (starting with "|"). The object used to produce the encoded * URI are collected as tuple inside {@link N4JSResource}. Then the node text is checked if it is convertible to a * valid value. If there is a {@link BadEscapementException} is thrown then there is either a warning or an error * produced via the diagnosticProducer. * * * @param resource * the N4JSResource * @param obj * the EObject containing the cross reference * @param node * the node representing the EObject * @param eRef * the cross reference in the domain model * @param xref * the cross reference in the node model * @param diagnosticProducer * to produce errors or warnings * @return the created proxy */ private EObject createProxy(N4JSResource resource, EObject obj, INode node, EReference eRef, CrossReference xref, IDiagnosticProducer diagnosticProducer) { final URI uri = resource.getURI(); /* * as otherwise with 0 the EObjectDescription created for Script would be fetched */ final int fragmentNumber = resource.addLazyProxyInformation(obj, eRef, node); final URI encodedLink = uri.appendFragment("|" + fragmentNumber); EClass referenceType = findInstantiableCompatible(eRef.getEReferenceType()); final EObject proxy = EcoreUtil.create(referenceType); ((InternalEObject) proxy).eSetProxyURI(encodedLink); AbstractElement terminal = xref.getTerminal(); if (!(terminal instanceof RuleCall)) { throw new IllegalArgumentException(String.valueOf(xref)); } AbstractRule rule = ((RuleCall) terminal).getRule(); try { String tokenText = NodeModelUtils.getTokenText(node); Object value = valueConverterService.toValue(tokenText, rule.getName(), node); if (obj instanceof IdentifierRef && value instanceof String) { ((IdentifierRef) obj).setIdAsText((String) value); } else if (obj instanceof ParameterizedTypeRef && value instanceof String) { ((ParameterizedTypeRef) obj).setDeclaredTypeAsText((String) value); } else if (obj instanceof LabelRef && value instanceof String) { ((LabelRef) obj).setLabelAsText((String) value); } else if (obj instanceof ParameterizedPropertyAccessExpression && value instanceof String) { ((ParameterizedPropertyAccessExpression) obj).setPropertyAsText((String) value); } else if (obj instanceof ImportDeclaration && value instanceof String) { ((ImportDeclaration) obj).setModuleSpecifierAsText((String) value); } else if (obj instanceof NamedImportSpecifier && value instanceof String) { ((NamedImportSpecifier) obj).setImportedElementAsText((String) value); } else if ((obj instanceof JSXPropertyAttribute) && (value instanceof String)) { ((JSXPropertyAttribute) obj).setPropertyAsText((String) value); } else { setOtherElementAsText(tokenText, obj, value); } } catch (BadEscapementException e) { diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), e.getSeverity(), e.getIssueCode(), Strings.EMPTY_ARRAY)); } catch (N4JSValueConverterException vce) { diagnosticProducer.addDiagnostic(new DiagnosticMessage(vce.getMessage(), vce.getSeverity(), vce.getIssueCode(), Strings.EMPTY_ARRAY)); } catch (N4JSValueConverterWithValueException vcwve) { diagnosticProducer.addDiagnostic(new DiagnosticMessage(vcwve.getMessage(), vcwve.getSeverity(), vcwve.getIssueCode(), Strings.EMPTY_ARRAY)); } return proxy; }
Example #15
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected IDiagnosticProducer createDiagnosticProducer(IDiagnosticConsumer consumer) { return new LinkingDiagnosticProducer(consumer); }
Example #16
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected final void setDefaultValue(EObject obj, EReference ref, IDiagnosticProducer producer) { producer.setTarget(obj, ref); setDefaultValueImpl(obj, ref, producer); }
Example #17
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void setDefaultValueImpl(EObject obj, EReference ref, IDiagnosticProducer producer) { // may be overridden by clients }
Example #18
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void beforeEnsureIsLinked(EObject obj, EReference ref, IDiagnosticProducer producer) { // may be overridden by clients }
Example #19
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override protected void doLinkModel(EObject model, IDiagnosticConsumer consumer) { final IDiagnosticProducer producer = createDiagnosticProducer(consumer); ensureModelLinked(model, producer); }
Example #20
Source File: SequencerTestLanguageRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override protected void installProxies(EObject obj, IDiagnosticProducer producer, Multimap<Setting, INode> settingsToLink) { super.installProxies(obj, producer, settingsToLink); if (obj instanceof NullCrossRef) ((NullCrossRef) obj).setRef(null); }