org.eclipse.xtext.diagnostics.DiagnosticMessage Java Examples
The following examples show how to use
org.eclipse.xtext.diagnostics.DiagnosticMessage.
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: N4JSResource.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected void createAndAddDiagnostic(Triple<EObject, EReference, INode> triple) { // check if unresolved reference is special case handled by {@link N4JSScopingDiagnostician} DiagnosticMessage scopingDiagnostic = scopingDiagnostician.getMessageFor(triple.getFirst(), triple.getSecond(), triple.getThird()); // if so, use more specific diagnostic message if (null != scopingDiagnostic) { if (scopingDiagnostic == N4JSScopingDiagnostician.NO_MESSAGE) { return; // don't show an error message for this unresolved reference } List<Diagnostic> list = getDiagnosticList(scopingDiagnostic); Diagnostic diagnostic = createDiagnostic(triple, scopingDiagnostic); if (!list.contains(diagnostic)) { list.add(diagnostic); } } else { // if not, use default generic scoping message super.createAndAddDiagnostic(triple); } }
Example #2
Source File: AbstractUnresolvableReferenceWithNode.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public void applyToModel(IResolvedTypes resolvedTypes) { Resource resource = getExpression().eResource(); if (resource instanceof LazyLinkingResource) { LazyLinkingResource lazyLinkingResource = (LazyLinkingResource) resource; TypeAwareLinkingDiagnosticContext context = new TypeAwareLinkingDiagnosticContext(this, resolvedTypes); DiagnosticMessage message = lazyLinkingResource.getDiagnosticMessageProvider() .getUnresolvedProxyMessage(context); if (message != null) { List<Resource.Diagnostic> diagnostics = getDiagnosticList(lazyLinkingResource, message); Diagnostic diagnostic = createDiagnostic(message); diagnostics.add(diagnostic); } EObject referenced = (InternalEObject) getExpression().eGet(getReference(), false); lazyLinkingResource.markUnresolvable(referenced); } }
Example #3
Source File: BatchLinkableResource.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected EObject handleCyclicResolution(Triple<EObject, EReference, INode> triple) throws AssertionError { if (!isValidationDisabled()) { EObject context = triple.getFirst(); if (context.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) { // here we may end up with cyclic resolution requests in rare situations, e.g. for input types // like : /* * package p; * class C extends p.C.Bogus {} */ return null; } DiagnosticMessage message = new DiagnosticMessage("Cyclic linking detected : " + getReferences(triple, resolving), Severity.ERROR, "cyclic-resolution"); List<Diagnostic> list = getDiagnosticList(message); Diagnostic diagnostic = createDiagnostic(triple, message); if (!list.contains(diagnostic)) list.add(diagnostic); } return null; }
Example #4
Source File: LinkingDiagnosticMessageProvider.java From statecharts with Eclipse Public License 1.0 | 6 votes |
@Override public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) { String linkText = ""; try { linkText = context.getLinkText(); } catch (IllegalNodeException e) { linkText = e.getNode().getText(); } String format = "Could not find declaration of %s '%s'"; String type = context.getReference().getEReferenceType().getName(); String message = String.format(format, "", linkText); if (!type.equals("EObject")) { message = String.format(format, type, linkText); } return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #5
Source File: LazyLinkingResource.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected List<Diagnostic> getDiagnosticList(DiagnosticMessage message) throws AssertionError { if (message != null) { switch (message.getSeverity()) { case ERROR: return getErrors(); case WARNING: return getWarnings(); default: throw new AssertionError("Unexpected severity: " + message.getSeverity()); } } return Collections.emptyList(); }
Example #6
Source File: LinkingDiagnosticMessageProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public DiagnosticMessage getViolatedBoundsConstraintMessage(ILinkingDiagnosticContext context, int size) { String message = "Too many matches for reference to '" + context.getLinkText() + "'. " + "Feature " + context.getReference().getName() + " can only hold " + context.getReference().getUpperBound() + " reference" + (context.getReference().getUpperBound() != 1 ? "s" : "") + " but found " + size + " candidate" + (size!=1 ? "s" : ""); return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #7
Source File: LazyLinkingResource.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void removeDiagnostic(Triple<EObject, EReference, INode> triple) { // return early if there's nothing to remove if (getErrors().isEmpty() && getWarnings().isEmpty()) return; DiagnosticMessage message = createDiagnosticMessage(triple); List<Diagnostic> list = getDiagnosticList(message); if (!list.isEmpty()) { Diagnostic diagnostic = createDiagnostic(triple, message); list.remove(diagnostic); } }
Example #8
Source File: LazyLinkingResource.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.3 */ protected void createAndAddDiagnostic(Triple<EObject, EReference, INode> triple, IllegalNodeException ex) { if (isValidationDisabled()) return; ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticMessageContext(triple); DiagnosticMessage message = linkingDiagnosticMessageProvider.getIllegalNodeMessage(context, ex); if (message != null) { List<Diagnostic> list = getDiagnosticList(message); Diagnostic diagnostic = createDiagnostic(triple, message); if (!list.contains(diagnostic)) list.add(diagnostic); } }
Example #9
Source File: LazyLinkingResource.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void createAndAddDiagnostic(Triple<EObject, EReference, INode> triple) { if (isValidationDisabled()) return; DiagnosticMessage message = createDiagnosticMessage(triple); if (message != null) { List<Diagnostic> list = getDiagnosticList(message); Diagnostic diagnostic = createDiagnostic(triple, message); if (!list.contains(diagnostic)) list.add(diagnostic); } }
Example #10
Source File: XtextLinkingDiagnosticMessageProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticContext context) { DiagnosticMessage diagnosticMessage = new XtextSwitch<DiagnosticMessage>() { @Override public DiagnosticMessage caseRuleCall(RuleCall ruleCall) { return new DiagnosticMessage(context.getLinkText()+" cannot be resolved to a rule", Severity.ERROR, UNRESOLVED_RULE, context.getLinkText()); } }.doSwitch(context.getContext()); return diagnosticMessage != null ? diagnosticMessage : super.getUnresolvedProxyMessage(context); }
Example #11
Source File: AbstractSCTResource.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void createDiagnostic(Triple<EObject, EReference, INode> triple) { SpecificationElement specificationElement = EcoreUtil2.getContainerOfType(triple.getFirst(), SpecificationElement.class); DiagnosticMessage message = createDiagnosticMessage(triple); Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(), message.getIssueCode(), message.getIssueData()); linkingDiagnostics.put(specificationElement, diagnostic); }
Example #12
Source File: TransformationDiagnosticsProducer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptError(TransformationErrorCode errorCode, String message, EObject element) { setTarget(element, null); lastError = errorCode; addDiagnostic(new DiagnosticMessage(message, Severity.ERROR, null)); lastError = null; }
Example #13
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 #14
Source File: DomainmodelLinkingDiagnosticMessageProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticContext context) { EObject element = context.getContext(); if (element instanceof JvmTypeReference) { JvmTypeReference jvmTypeReference = (JvmTypeReference) element; DiagnosticMessage diagnosticMessage = new DomainmodelSwitch<DiagnosticMessage>() { @Override public DiagnosticMessage caseEntity(Entity entity) { return new DiagnosticMessage("Missing supertype " + context.getLinkText(), Severity.ERROR, IssueCodes.MISSING_TYPE, context.getLinkText()); } @Override public DiagnosticMessage caseProperty(Property property) { return new DiagnosticMessage("Missing property type " + context.getLinkText(), Severity.ERROR, IssueCodes.MISSING_TYPE, context.getLinkText()); } @Override public DiagnosticMessage caseOperation(Operation operation) { return new DiagnosticMessage("Missing return type " + context.getLinkText(), Severity.ERROR, IssueCodes.MISSING_TYPE, context.getLinkText()); } }.doSwitch(jvmTypeReference.eContainer()); if (diagnosticMessage != null) return diagnosticMessage; } return super.getUnresolvedProxyMessage(context); }
Example #15
Source File: AbstractUnresolvableReferenceWithNode.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected List<Diagnostic> getDiagnosticList(LazyLinkingResource resource, /* @Nullable */ DiagnosticMessage message) throws AssertionError { if (message != null) { switch (message.getSeverity()) { case ERROR: return resource.getErrors(); case WARNING: return resource.getWarnings(); default: throw new AssertionError("Unexpected severity: " + message.getSeverity()); } } return Collections.emptyList(); }
Example #16
Source File: AbstractUnresolvableReferenceWithNode.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Resource.Diagnostic createDiagnostic(DiagnosticMessage message) { Diagnostic diagnostic = new XtextLinkingDiagnostic( node, message.getMessage(), message.getIssueCode(), message.getIssueData()); return diagnostic; }
Example #17
Source File: N4JSScopingConsumableMethodsDiagnosis.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override DiagnosticMessage diagnose(QualifiedName name, ParameterizedPropertyAccessExpression propertyAccess) { // determine containing member declaration and classifier definition N4MemberDeclaration containingMemberDeclaration = EcoreUtil2.getContainerOfType(propertyAccess, N4MemberDeclaration.class); N4ClassifierDefinition classifierDefinition = EcoreUtil2.getContainerOfType(containingMemberDeclaration, N4ClassifierDefinition.class); // if ancestors present and non-static context (no super in static context) if (containingMemberDeclaration != null && !containingMemberDeclaration.isStatic() && classifierDefinition != null) { // Get candidate methods MemberList<TMember>.MemberIterable<TMethod> methods = containerTypesHelper.fromContext(propertyAccess) .membersOfImplementedInterfacesForConsumption((TClassifier) classifierDefinition.getDefinedType()) .methods(); boolean hasMethod = methods.stream() .filter(m -> !m.isHasNoBody() && !m.isStatic()) // Filter for non-static non-abstract methods .anyMatch(m -> m.getName().equals(name.toString())); if (hasMethod) { return createMessage(IssueCodes.CLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER, IssueCodes.getMessageForCLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER()); } } return null; }
Example #18
Source File: N4JSScopingInstanceOfPrimitivTypeDiagnosis.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Creates a {@link DiagnosticMessage} for instanceof expressions where the right-hand-side is a primitive type * identifier. * * It is assumed that the given qualified name was extracted from the {@link IdentifierRef} on the rhs of the given * relational expression. * * Returns null if not applicable. * * @param name * The unresolved name of an IdentifierRef on the RHS of the expression. * * @param expression * A pair of the instanceof-expression and the unresolved IdentifierRef. */ @Override DiagnosticMessage diagnose(QualifiedName name, RelationalExpression expression) { // only applicable for the instanceof operator if (expression.getOp() != RelationalOperator.INSTANCEOF) { return null; } // query built-in type scope for the unresolved name BuiltInTypeScope builtInTypeScope = BuiltInTypeScope.get(expression.eResource().getResourceSet()); IEObjectDescription singleElement = builtInTypeScope.getSingleElement(name); // if there is no primitive type with this name, this diagnosis is not applicable if (null == singleElement) { return null; } // if we can find a primitive type for the qualified name if (singleElement.getEClass().getClassifierID() == TypesPackage.Literals.PRIMITIVE_TYPE.getClassifierID()) { // create special error message return createMessage(IssueCodes.TYS_INSTANCEOF_NOT_SUPPORTED_FOR_PRIMITIVE_TYPES, IssueCodes.getMessageForTYS_INSTANCEOF_NOT_SUPPORTED_FOR_PRIMITIVE_TYPES()); } else { // the found element is not a primitive type, diagnosis not applicable return null; } }
Example #19
Source File: LinkingDiagnosticMessageProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) { EClass referenceType = context.getReference().getEReferenceType(); String linkText = ""; try { linkText = context.getLinkText(); } catch (IllegalNodeException e){ linkText = e.getNode().getText(); } String msg = "Couldn't resolve reference to " + referenceType.getName() + " '" + linkText + "'."; return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #20
Source File: GamlLinkingErrorMessageProvider.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public DiagnosticMessage getViolatedBoundsConstraintMessage(final ILinkingDiagnosticContext context, final int size) { final String message = "Too many matches for reference to '" + context.getLinkText() + "'. " + "Feature " + context.getReference().getName() + " can only hold " + context.getReference().getUpperBound() + " reference" + (context.getReference().getUpperBound() != 1 ? "s" : "") + " but found " + size + " candidate" + (size != 1 ? "s" : ""); return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #21
Source File: LinkingDiagnosticMessageProvider.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public DiagnosticMessage getIllegalNodeMessage(ILinkingDiagnosticContext context, IllegalNodeException ex) { String message = ex.getMessage(); return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #22
Source File: LinkingDiagnosticMessageProvider.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public DiagnosticMessage getIllegalCrossReferenceMessage(ILinkingDiagnosticContext context, CrossReference reference) { String message = "Cannot find reference " + reference; return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #23
Source File: LinkingDiagnosticProducer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override protected Diagnostic createDiagnostic(DiagnosticMessage message) { return new XtextLinkingDiagnostic(getNode(), message.getMessage(), message.getIssueCode(), message.getIssueData()); }
Example #24
Source File: AbstractSCTResource.java From statecharts with Eclipse Public License 1.0 | 4 votes |
protected DiagnosticMessage createDiagnosticMessage(Triple<EObject, EReference, INode> triple) { ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticMessageContext(triple); DiagnosticMessage message = diagnosticMessageProvider.getUnresolvedProxyMessage(context); return message; }
Example #25
Source File: LinkingDiagnosticMessageProvider.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public DiagnosticMessage getViolatedUniqueConstraintMessage(ILinkingDiagnosticContext context) { String message = "Cannot refer to '" + context.getLinkText() + "' more than once."; return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #26
Source File: LinkingWarningsTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) { return new DiagnosticMessage(expected, Severity.WARNING, Diagnostic.LINKING_DIAGNOSTIC); }
Example #27
Source File: LazyLinkingResource.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected Diagnostic createDiagnostic(Triple<EObject, EReference, INode> triple, DiagnosticMessage message) { Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(), message.getIssueCode(), message.getIssueData()); return diagnostic; }
Example #28
Source File: GamlLinkingErrorMessageProvider.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public DiagnosticMessage getIllegalNodeMessage(final ILinkingDiagnosticContext context, final IllegalNodeException ex) { final String message = ex.getMessage(); return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #29
Source File: GamlLinkingErrorMessageProvider.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public DiagnosticMessage getIllegalCrossReferenceMessage(final ILinkingDiagnosticContext context, final CrossReference reference) { final String message = "Cannot find reference " + reference; return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }
Example #30
Source File: GamlLinkingErrorMessageProvider.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public DiagnosticMessage getViolatedUniqueConstraintMessage(final ILinkingDiagnosticContext context) { final String message = "Cannot refer to '" + context.getLinkText() + "' more than once."; return new DiagnosticMessage(message, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC); }