Java Code Examples for org.eclipse.xtext.validation.Issue#IssueImpl
The following examples show how to use
org.eclipse.xtext.validation.Issue#IssueImpl .
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: ElementIssueProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void synthesizeIssuesForFollowUpErrors(Resource resource, List<Issue> result) { List<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { IResolvedTypes resolvedTypes = typeResolver.resolveTypes(contents.get(0)); for(ILinkingCandidate linkingCandidate: resolvedTypes.getFollowUpErrors()) { XExpression expression = linkingCandidate.getExpression(); IssueImpl issue = new Issue.IssueImpl(); issue.setUriToProblem(EcoreUtil.getURI(linkingCandidate.getExpression())); if (expression instanceof XAbstractFeatureCall) issue.setMessage(((XAbstractFeatureCall) expression).getConcreteSyntaxFeatureName() + " cannot be resolved"); else { List<INode> nodes = NodeModelUtils.findNodesForFeature(expression, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR); if (nodes.size() >= 1) { issue.setMessage(nodes.get(0).getText() + " cannot be resolved"); } } result.add(issue); } } }
Example 2
Source File: LinkingErrorTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testSemanticIssueResolution() throws Exception { IFile dslFile = dslFile(MODEL_WITH_LINKING_ERROR); XtextEditor xtextEditor = openEditor(dslFile); URI uriToProblem = xtextEditor.getDocument().readOnly(new IUnitOfWork<URI, XtextResource>() { @Override public URI exec(XtextResource state) throws Exception { Main main = (Main) state.getContents().get(0); Element element = main.getElements().get(1); return EcoreUtil.getURI(element); } }); Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setUriToProblem(uriToProblem); issue.setCode(QuickfixCrossrefTestLanguageQuickfixProvider.SEMANTIC_FIX_ID); List<IssueResolution> resolutions = issueResolutionProvider.getResolutions(issue); assertEquals(1, resolutions.size()); IssueResolution issueResolution = resolutions.get(0); issueResolution.apply(); xtextEditor.doSave(null); List<Issue> issues = getAllValidationIssues(xtextEditor.getDocument()); assertTrue(issues.isEmpty()); }
Example 3
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 6 votes |
@Fix(DotAttributes.LABEL__GCNE) public void fixHtmlLabelAttributeValue(final Issue issue, IssueResolutionAcceptor acceptor) { String[] data = issue.getData(); if (data == null || data.length < 4) { return; } String htmlLabelIssueCode = data[0]; String htmlLabelUriToProblem = data[1]; Issue.IssueImpl htmlLabelIssue = new Issue.IssueImpl(); htmlLabelIssue.setCode(htmlLabelIssueCode); htmlLabelIssue.setData(data); htmlLabelIssue.setUriToProblem(URI.createURI(htmlLabelUriToProblem)); new DotHtmlLabelQuickfixDelegator().provideQuickfixes(issue, htmlLabelIssue, acceptor); }
Example 4
Source File: DiagnosticIssueConverter.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Convert the given diagnostic to an issue. */ public Issue toIssue(URI uri, Diagnostic diagnostic, Optional<Document> document) { IssueImpl issue = new Issue.IssueImpl(); issue.setSeverity(toSeverity(diagnostic.getSeverity())); Range range = diagnostic.getRange(); Position sPos = range.getStart(); Position ePos = range.getEnd(); int offSetStart = 0; int offSetEnd = 0; if (document.isPresent()) { offSetStart = document.get().getOffSet(new Position(sPos.getLine() + 1, sPos.getCharacter() + 1)); offSetEnd = document.get().getOffSet(new Position(ePos.getLine() + 1, ePos.getCharacter() + 1)); } issue.setLineNumber(sPos.getLine() + 1); issue.setColumn(sPos.getCharacter() + 1); issue.setOffset(offSetStart); issue.setLength(offSetEnd - offSetStart); issue.setUriToProblem(uri); issue.setCode(diagnostic.getCode()); issue.setType(CheckType.FAST); issue.setMessage(diagnostic.getMessage()); return issue; }
Example 5
Source File: N4JSResourceValidator.java From n4js with Eclipse Public License 1.0 | 5 votes |
private static Issue createFileIssue(Resource res, String message, String issueCode) { final Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setCode(issueCode); issue.setSeverity(IssueCodes.getDefaultSeverity(issueCode)); issue.setMessage(message); issue.setUriToProblem(res.getURI()); issue.setType(CheckType.FAST); // using CheckType.FAST is important to get proper marker update behavior in ... // ... the editor between persisted and dirty states! issue.setOffset(0); issue.setLength(0); issue.setLineNumber(0); issue.setColumn(0); return issue; }
Example 6
Source File: DerivedResourceMarkerCopier.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private String determinateMarkerTypeByURI(SourceRelativeURI resourceURI) { IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(resourceURI.getURI()); if (serviceProvider == null) return null; MarkerTypeProvider typeProvider = serviceProvider.get(MarkerTypeProvider.class); Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setType(CheckType.NORMAL); return typeProvider.getMarkerType(issue); }
Example 7
Source File: ValidatorTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * https://bugs.eclipse.org/bugs/show_bug.cgi?id=322645 */ @Test public void testBugFix322645() throws Exception { Issues issues = issues(); Issue a = new Issue.IssueImpl(); Issue b = new Issue.IssueImpl(); issues.addError("foo", a); issues.addWarning(null, a); issues.addError(null, b); MWEDiagnostic[] errors = issues.getErrors(); assertEquals(2, errors.length); final Validator validator = new Validator(); final String string = validator.toString(issues); assert(string.contains("foo")); }
Example 8
Source File: ProjectManager.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void reportProjectIssue(String message, String code, Severity severity) { Issue.IssueImpl result = new Issue.IssueImpl(); result.setMessage(message); result.setCode(code); result.setSeverity(severity); result.setUriToProblem(baseDir); issueAcceptor.apply(baseDir, ImmutableList.of(result)); }
Example 9
Source File: StatechartValidationDecorationProvider.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected SCTIssue getSubDiagramIssue(View view) { if (SemanticHints.STATE.equals(view.getType())) { BooleanValueStyle style = GMFNotationUtil.getBooleanValueStyle(view, DiagramPartitioningUtil.INLINE_STYLE); if (style == null ? false : !style.isBooleanValue()) { EObject element = view.getElement(); TreeIterator<EObject> eAllContents = element.eAllContents(); while (eAllContents.hasNext()) { EObject next = eAllContents.next(); if(next instanceof Transition && next.eContainer() == element) { eAllContents.prune(); continue; } String semanticURI = EcoreUtil.getURI(next).fragment(); List<SCTIssue> issues = store.getIssues(semanticURI); for (final SCTIssue issue : issues) { if (Severity.ERROR.equals(issue.getSeverity())) { IssueImpl result = new Issue.IssueImpl(); result.setMessage(SUB_DIAGRAM_ERRORS); result.setSeverity(Severity.ERROR); return new SCTIssue(result, issue.getSemanticURI()); } } } } } return null; }
Example 10
Source File: SarlBatchCompiler.java From sarl with Apache License 2.0 | 5 votes |
/** Reports the given warning message. * * @param message the warning message. * @since 0.8 */ protected void reportInternalWarning(String message) { getLogger().warning(message); if (getReportInternalProblemsAsIssues()) { final org.eclipse.emf.common.util.URI uri = null; final Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setCode(INTERNAL_ERROR_CODE); issue.setMessage(message); issue.setUriToProblem(uri); issue.setSeverity(Severity.WARNING); notifiesIssueMessageListeners(issue, uri, message); } }
Example 11
Source File: SarlBatchCompiler.java From sarl with Apache License 2.0 | 5 votes |
/** Reports the given warning message. * * @param message the warning message. * @param exception the source of the exception. * @since 0.8 */ protected void reportInternalWarning(String message, Throwable exception) { getLogger().log(Level.WARNING, message, exception); if (getReportInternalProblemsAsIssues()) { final org.eclipse.emf.common.util.URI uri = null; final Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setCode(INTERNAL_ERROR_CODE); issue.setMessage(message); issue.setUriToProblem(uri); issue.setSeverity(Severity.WARNING); notifiesIssueMessageListeners(issue, uri, message); } }
Example 12
Source File: SarlBatchCompiler.java From sarl with Apache License 2.0 | 5 votes |
/** Reports the given error message. * * @param message the warning message. * @param exception the source of the exception. * @since 0.8 */ protected void reportInternalError(String message, Throwable exception) { getLogger().log(Level.SEVERE, message, exception); if (getReportInternalProblemsAsIssues()) { final org.eclipse.emf.common.util.URI uri = null; final Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setCode(INTERNAL_ERROR_CODE); issue.setMessage(message); issue.setUriToProblem(uri); issue.setSeverity(Severity.ERROR); notifiesIssueMessageListeners(issue, uri, message); } }
Example 13
Source File: SarlBatchCompiler.java From sarl with Apache License 2.0 | 5 votes |
/** Reports the given error message. * * @param message the warning message. * @param parameters the values of the parameters that must be dynamically replaced within the message text. * @since 0.8 */ protected void reportInternalError(String message, Object... parameters) { getLogger().severe(MessageFormat.format(message, parameters)); if (getReportInternalProblemsAsIssues()) { final org.eclipse.emf.common.util.URI uri = null; final Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setCode(INTERNAL_ERROR_CODE); issue.setMessage(message); issue.setUriToProblem(uri); issue.setSeverity(Severity.ERROR); notifiesIssueMessageListeners(issue, uri, message); } }
Example 14
Source File: DeclarativeQuickfixProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected Issue createIssue(String code) { Issue.IssueImpl issue = new Issue.IssueImpl(); issue.setCode(code); return issue; }
Example 15
Source File: IssueUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * Creates an Issue out of a Marker. * setSyntaxError is unset since the current API does not allow fixing systax errors anyway. * * @param marker The marker to create an issue from * @return an issue created out of the given marker or <code>null</code> */ public Issue createIssue(IMarker marker) { Issue.IssueImpl issue = new Issue.IssueImpl(); try { Map<String, Object> attributes = marker.getAttributes(); String markerType = marker.getType(); Object message = attributes.get(IMarker.MESSAGE); issue.setMessage(message instanceof String ? (String) message : null); Object lineNumber = attributes.get(IMarker.LINE_NUMBER); issue.setLineNumber(lineNumber instanceof Integer ? (Integer) lineNumber : null); Object column = attributes.get(Issue.COLUMN_KEY); issue.setColumn(column instanceof Integer ? (Integer) column : null); Object offset = attributes.get(IMarker.CHAR_START); Object endOffset = attributes.get(IMarker.CHAR_END); if(offset instanceof Integer && endOffset instanceof Integer) { issue.setOffset((Integer) offset); issue.setLength((Integer) endOffset - (Integer) offset); } else { issue.setOffset(-1); issue.setLength(0); } Object code = attributes.get(Issue.CODE_KEY); issue.setCode(code instanceof String ? (String) code:null); Object data = attributes.get(Issue.DATA_KEY); issue.setData(data instanceof String ? Strings.unpack((String) data) : null); Object uri = attributes.get(Issue.URI_KEY); issue.setUriToProblem(uri instanceof String ? URI.createURI((String) uri) : null); Object severity = attributes.get(IMarker.SEVERITY); Severity translatedSeverity = translateSeverity(severity instanceof Integer ? (Integer) severity : 0); if(translatedSeverity == null) throw new IllegalArgumentException(marker.toString()); issue.setSeverity(translatedSeverity); if(markerTypeProvider != null) issue.setType(markerTypeProvider.getCheckType(markerType)); else issue.setType(MarkerTypes.toCheckType(markerType)); } catch (CoreException e) { return null; } return issue; }