Java Code Examples for org.eclipse.xtext.validation.Issue#getData()
The following examples show how to use
org.eclipse.xtext.validation.Issue#getData() .
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: LSPIssue.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Copy constructor */ public LSPIssue(Issue copyFrom) { this(); if (copyFrom.getOffset() != null) this.setOffset(copyFrom.getOffset()); if (copyFrom.getLength() != null) this.setLength(copyFrom.getLength()); if (copyFrom.getColumn() != null) this.setColumn(copyFrom.getColumn()); if (copyFrom.getLineNumber() != null) this.setLineNumber(copyFrom.getLineNumber()); if (copyFrom.getCode() != null) this.setCode(copyFrom.getCode()); if (copyFrom.getMessage() != null) this.setMessage(copyFrom.getMessage()); if (copyFrom.getUriToProblem() != null) this.setUriToProblem(copyFrom.getUriToProblem()); if (copyFrom.getSeverity() != null) this.setSeverity(copyFrom.getSeverity()); if (copyFrom.getType() != null) this.setType(copyFrom.getType()); if (copyFrom.getData() != null) this.setData(copyFrom.getData()); }
Example 2
Source File: XtextGrammarQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Fix(XtextLinkingDiagnosticMessageProvider.UNRESOLVED_RULE) public void fixUnresolvedRule(final Issue issue, IssueResolutionAcceptor acceptor) { final String ruleName = issue.getData()[0]; acceptor.accept(issue, "Create rule '" + ruleName + "'", "Create rule '" + ruleName + "'", NULL_QUICKFIX_IMAGE, new ISemanticModification() { @Override public void apply(final EObject element, IModificationContext context) throws BadLocationException { AbstractRule abstractRule = EcoreUtil2.getContainerOfType(element, ParserRule.class); ICompositeNode node = NodeModelUtils.getNode(abstractRule); int offset = node.getEndOffset(); String nl = context.getXtextDocument().getLineDelimiter(0); StringBuilder builder = new StringBuilder(nl+nl); if (abstractRule instanceof TerminalRule) builder.append("terminal "); String newRule = builder.append(ruleName).append(":" + nl + "\t" + nl + ";").toString(); context.getXtextDocument().replace(offset, 0, newRule); } }); createLinkingIssueResolutions(issue, acceptor); }
Example 3
Source File: CheckCfgQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Fix severity by setting it to a legal value as is defined by severity range of referenced check. Legal * severities are passed as issue data (org.eclipse.xtext.validation.Issue#getData()). * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.SEVERITY_NOT_ALLOWED) public void fixSeverityToMaxSeverity(final Issue issue, final IssueResolutionAcceptor acceptor) { if (issue.getData() != null) { for (final String severityProposal : issue.getData()) { final String label = NLS.bind(Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_LABEL, severityProposal); final String descn = NLS.bind(Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_DESCN, severityProposal); acceptor.accept(issue, label, descn, NO_IMAGE, new IModification() { public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.replace(issue.getOffset(), issue.getLength(), severityProposal); } }); } } }
Example 4
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 6 votes |
@Fix(DotAttributes.STYLE__GCNE) public void fixStyleAttributeValue(final Issue issue, IssueResolutionAcceptor acceptor) { String[] issueData = issue.getData(); if (issueData == null || issueData.length < 2) { return; } String issueCode = issueData[0]; switch (issueCode) { case DotStyleValidator.DEPRECATED_STYLE_ITEM: provideQuickfixesForDeprecatedStyleItem(issue, acceptor); break; case DotStyleValidator.DUPLICATED_STYLE_ITEM: provideQuickfixesForDuplicatedStyleItem(issue, acceptor); break; case DotStyleValidator.INVALID_STYLE_ITEM: provideQuickfixesForInvalidStyleItem(issue, acceptor); default: return; } }
Example 5
Source File: MarkerCreator.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.0 */ protected void setMarkerAttributes(Issue issue, IResource resource, IMarker marker) throws CoreException { String lineNR = ""; if (issue.getLineNumber() != null) { lineNR = "line: " + issue.getLineNumber() + " "; } marker.setAttribute(IMarker.LOCATION, lineNR + resource.getFullPath().toString()); marker.setAttribute(Issue.CODE_KEY, issue.getCode()); marker.setAttribute(IMarker.SEVERITY, getSeverity(issue)); marker.setAttribute(IMarker.CHAR_START, issue.getOffset()); if(issue.getOffset() != null && issue.getLength() != null) marker.setAttribute(IMarker.CHAR_END, issue.getOffset()+issue.getLength()); marker.setAttribute(IMarker.LINE_NUMBER, issue.getLineNumber()); marker.setAttribute(Issue.COLUMN_KEY, issue.getColumn()); marker.setAttribute(IMarker.MESSAGE, issue.getMessage()); if (issue.getUriToProblem()!=null) marker.setAttribute(Issue.URI_KEY, issue.getUriToProblem().toString()); if(issue.getData() != null && issue.getData().length > 0) { marker.setAttribute(Issue.DATA_KEY, Strings.pack(issue.getData())); } if (resolutionProvider != null && resolutionProvider.hasResolutionFor(issue.getCode())) { marker.setAttribute(FIXABLE_KEY, true); } }
Example 6
Source File: CheckQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Fixes an illegally set default severity. The default severity must be within given severity range. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.DEFAULT_SEVERITY_NOT_IN_RANGE) public void fixIllegalDefaultSeverity(final Issue issue, final IssueResolutionAcceptor acceptor) { if (issue.getData() != null) { for (final String severityProposal : issue.getData()) { final String label = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_LABEL, severityProposal); final String descn = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_DESCN, severityProposal); acceptor.accept(issue, label, descn, NO_IMAGE, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.replace(issue.getOffset(), issue.getLength(), severityProposal); } }); } } }
Example 7
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 6 votes |
@Fix(REDUNDANT_ATTRIBUTE) public void fixRedundantAttribute(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() == null || issue.getData().length == 0) { return; } String attributeName = issue.getData()[0]; String label = "Remove '" + attributeName + "' attribute."; //$NON-NLS-1$ //$NON-NLS-2$ String description = "Remove the redundant '" + attributeName //$NON-NLS-1$ + "' attribute."; //$NON-NLS-1$ ISemanticModification semanticModification = (EObject element, IModificationContext context) -> EcoreUtil.remove(element); acceptor.accept(issue, label, description, DELETE_IMAGE, semanticModification); }
Example 8
Source File: MemberRenameModification.java From sarl with Apache License 2.0 | 6 votes |
/** Create the quick fix if needed. * * <p>The user data ccontains the new names. * * @param provider the quick fix provider. * @param issue the issue to fix. * @param acceptor the quick fix acceptor. */ public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor) { for (final String newName : issue.getData()) { final String msg = MessageFormat.format( Messages.SARLQuickfixProvider_11, newName); final MemberRenameModification modification = new MemberRenameModification(newName); modification.setIssue(issue); modification.setTools(provider); acceptor.accept(issue, msg, MessageFormat.format(Messages.SARLQuickfixProvider_12, newName), JavaPluginImages.IMG_CORRECTION_RENAME, modification, IProposalRelevance.RENAME_REFACTORING); } }
Example 9
Source File: ImplementedTypeRemoveModification.java From sarl with Apache License 2.0 | 5 votes |
/** Create the quick fix if needed. * * <p>The first user data is the name of the type to remove. * The second parameter may be the type of the removal (see {@link RemovalType}). * * @param provider the quick fix provider. * @param issue the issue to fix. * @param acceptor the quick fix acceptor. * @param type the type of the modification. */ public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor, RemovalType type) { final String[] data = issue.getData(); RemovalType removalType = type; String redundantName = null; if (data != null && data.length >= 1) { redundantName = data[0]; if (removalType == null && data.length >= 2) { final String mode = data[1]; if (!Strings.isNullOrEmpty(mode)) { try { removalType = RemovalType.valueOf(mode.toUpperCase()); } catch (Throwable exception) { // } } } } if (removalType == null) { removalType = RemovalType.OTHER; } final String msg; if (Strings.isNullOrEmpty(redundantName)) { msg = Messages.SARLQuickfixProvider_0; } else { msg = MessageFormat.format(Messages.SARLQuickfixProvider_6, redundantName); } final ImplementedTypeRemoveModification modification = new ImplementedTypeRemoveModification(removalType); modification.setIssue(issue); modification.setTools(provider); acceptor.accept(issue, msg, Messages.SARLQuickfixProvider_9, JavaPluginImages.IMG_CORRECTION_REMOVE, modification); }
Example 10
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
@Fix(DotAttributes.OUTPUTORDER__G) public void fixOutputOrderAttributeValue(final Issue issue, IssueResolutionAcceptor acceptor) { String invalidValue = issue.getData()[0]; provideQuickfixes(invalidValue, OutputMode.values(), "graph outputMode", //$NON-NLS-1$ issue, acceptor); }
Example 11
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.CONFLICTING_DEFAULT_METHODS) public void overrideDefaultMethod(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() != null) { for (String data : issue.getData()) { int separatorIndex = data.indexOf('|'); if (separatorIndex > 0) { String interfaceName = data.substring(0, separatorIndex); String uri = data.substring(separatorIndex + 1); doOverrideMethods(issue, acceptor, "Override conflicting method of type " + interfaceName, new String[] {uri}); } } } }
Example 12
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
@Fix(DotAttributes.RANKDIR__G) public void fixRankdirAttributeValue(final Issue issue, IssueResolutionAcceptor acceptor) { String invalidValue = issue.getData()[0]; provideQuickfixes(invalidValue, Rankdir.values(), "graph rankdir", //$NON-NLS-1$ issue, acceptor); }
Example 13
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
private void provideQuickfixesForInvalidStyleItem(Issue issue, IssueResolutionAcceptor acceptor) { String[] issueData = issue.getData(); String invalidValue = issueData[1]; DotAttributes.Context attributeContext = DotAttributes.Context .valueOf(issueData[2]); switch (attributeContext) { case GRAPH: case SUBGRAPH: case CLUSTER: provideQuickfixesForMultipleAttributeValue(invalidValue, ClusterStyle.VALUES, "graph style", //$NON-NLS-1$ issue, acceptor); break; case NODE: provideQuickfixesForMultipleAttributeValue(invalidValue, NodeStyle.VALUES, "node style", //$NON-NLS-1$ issue, acceptor); break; case EDGE: provideQuickfixesForMultipleAttributeValue(invalidValue, EdgeStyle.VALUES, "edge style", //$NON-NLS-1$ issue, acceptor); break; default: break; } }
Example 14
Source File: GamlQuickfixProvider.java From gama with GNU General Public License v3.0 | 5 votes |
@Fix (IGamlIssue.SHOULD_CAST) public void shouldCast(final Issue issue, final IssueResolutionAcceptor acceptor) { final String[] data = issue.getData(); if (data == null || data.length == 0) { return; } final String castingString = data[0]; acceptor.accept(issue, "Cast the expression to " + castingString + "...", "", "", new Surround(issue.getOffset(), issue.getLength(), castingString + "(", ")")); }
Example 15
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.AMBIGUOUS_FEATURE_CALL) public void fixAmbiguousMethodCall(final Issue issue, IssueResolutionAcceptor acceptor) { String[] data = issue.getData(); if (data == null || data.length == 0) { return; } for (String replacement : data) { String replaceLabel = "Change to '" + replacement + "'"; acceptor.accept(issue, replaceLabel, replaceLabel, null, new ReplaceModification(issue, replacement)); } }
Example 16
Source File: StatemachineQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Fix(StatemachineValidator.INVALID_NAME) public void convertNameToFirstLowerCase(Issue issue, IssueResolutionAcceptor acceptor) { String[] data = issue.getData(); String firstLower = StringExtensions.toFirstLower(data[0]); String label = "Change to \'" + firstLower + "\'."; acceptor.accept(issue, label, label, "upcase.png", (IModification) (IModificationContext ctx) -> { IXtextDocument xtextDocument = ctx.getXtextDocument(); String firstLetter = xtextDocument.get(issue.getOffset(), 1); xtextDocument.replace(issue.getOffset(), 1, firstLetter.toLowerCase()); }); }
Example 17
Source File: CreateMemberQuickfixes.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception { if (referenceOwner instanceof XAbstractFeatureCall) { XAbstractFeatureCall call = (XAbstractFeatureCall) referenceOwner; String newMemberName = (issue.getData() != null && issue.getData().length > 0) ? issue.getData()[0] : null; if(newMemberName != null) { if (call instanceof XMemberFeatureCall) { if(!call.isExplicitOperationCallOrBuilderSyntax()) { newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor); newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor); } newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor); } else if(call instanceof XFeatureCall) { if(!call.isExplicitOperationCallOrBuilderSyntax()) { if(logicalContainerProvider.getNearestLogicalContainer(call) instanceof JvmExecutable) newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor); newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor); newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor); } newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor); } else if (call instanceof XAssignment) { newSetterQuickfix(issue, issueResolutionAcceptor, newMemberName, call); XAssignment assigment = (XAssignment) call; if(assigment.getAssignable() == null) { newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor); newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor); } else if (isThis(assigment)) { newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor); } } } if (call.isOperation()) { JvmIdentifiableElement feature = call.getFeature(); if(feature.eIsProxy()) { String operatorMethodName = getOperatorMethodName(call); if(operatorMethodName != null) newMethodQuickfixes(operatorMethodName, call, issue, issueResolutionAcceptor); } } if(call instanceof XFeatureCall && call.getFeature() instanceof JvmConstructor) { newConstructorQuickfix(issue, issueResolutionAcceptor, (XFeatureCall) call); } } if(referenceOwner instanceof XConstructorCall) { newConstructorQuickfix(issue, issueResolutionAcceptor, (XConstructorCall) referenceOwner); } }
Example 18
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 4 votes |
private void provideQuickfixesForDeprecatedStyleItem(Issue issue, IssueResolutionAcceptor acceptor) { String[] issueData = issue.getData(); String styleItemName = issueData[1]; final String penwidthValue = issueData.length > 2 ? issueData[2] : ""; //$NON-NLS-1$ final String styleItem = styleItemName + (penwidthValue == "" ? "" //$NON-NLS-1$ //$NON-NLS-2$ : "(" + penwidthValue + ")"); //$NON-NLS-1$ //$NON-NLS-2$ String label = "Replace '" + styleItem + "' with 'penwidth=" //$NON-NLS-1$ //$NON-NLS-2$ + penwidthValue + "'."; //$NON-NLS-1$ String description = "Use the 'penwidth' attribute instead of the deprecated '" //$NON-NLS-1$ + styleItemName + "' style."; //$NON-NLS-1$ ISemanticModification semanticModification = new ChangingDotAttributeValueSemanticModification() { private String newValue; public void apply(EObject element, IModificationContext context) throws Exception { super.apply(element, context); EObject container = element.eContainer(); // if the valid style attribute value is empty, remove the // entire style attribute if (newValue.isEmpty()) { EcoreUtil.remove(element); } // add a new pendwidth attribute Attribute penwidthAttribute = DotFactory.eINSTANCE .createAttribute(); penwidthAttribute .setName(ID.fromValue(DotAttributes.PENWIDTH__CNE)); penwidthAttribute.setValue( ID.fromValue(penwidthValue, ID.Type.QUOTED_STRING)); if (container instanceof AttrList) { AttrList attrList = (AttrList) container; attrList.getAttributes().add(penwidthAttribute); } else if (container instanceof Subgraph) { Subgraph subgraph = (Subgraph) container; subgraph.getStmts().add(penwidthAttribute); } } @Override public String getNewValue(String currentValue) { newValue = currentValue.replace(styleItem, "").trim(). //$NON-NLS-1$ // trim the unnecessary ',' if any is left over replaceAll("^,", "") //$NON-NLS-1$ //$NON-NLS-2$ .replaceAll(",$", "").replace(", ,", ",").trim(); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-1$ return newValue; } }; acceptor.accept(issue, label, description, null, semanticModification); }
Example 19
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Fix(org.eclipse.xtext.xbase.validation.IssueCodes.UNHANDLED_EXCEPTION) public void addThrowsDeclaration(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() != null && issue.getData().length > 0) acceptor.accept(issue, "Add throws declaration", "Add throws declaration", "fix_indent.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { String[] issueData = issue.getData(); XtendExecutable xtendExecutable = EcoreUtil2.getContainerOfType(element, XtendExecutable.class); XtextResource xtextResource = (XtextResource) xtendExecutable.eResource(); List<JvmType> exceptions = getExceptions(issueData, xtextResource); if (exceptions.size() > 0) { int insertPosition; if (xtendExecutable.getExpression() == null) { ICompositeNode functionNode = NodeModelUtils.findActualNodeFor(xtendExecutable); if (functionNode == null) throw new IllegalStateException("functionNode may not be null"); insertPosition = functionNode.getEndOffset(); } else { ICompositeNode expressionNode = NodeModelUtils.findActualNodeFor(xtendExecutable.getExpression()); if (expressionNode == null) throw new IllegalStateException("expressionNode may not be null"); insertPosition = expressionNode.getOffset(); } ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) xtendExecutable.eResource(), insertPosition, 0); if (xtendExecutable.getExpression() == null) appendable.append(" "); EList<JvmTypeReference> thrownExceptions = xtendExecutable.getExceptions(); if (thrownExceptions.isEmpty()) appendable.append("throws "); else appendable.append(", "); for(int i = 0; i < exceptions.size(); i++) { appendable.append(exceptions.get(i)); if (i != exceptions.size() - 1) { appendable.append(", "); } } if (xtendExecutable.getExpression() != null) appendable.append(" "); appendable.commitChanges(); } } }); }
Example 20
Source File: N4JSPackageJsonQuickfixProviderExtension.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** Installs a specific npm */ @Fix(IssueCodes.NON_EXISTING_PROJECT) @Fix(IssueCodes.NO_MATCHING_VERSION) @Fix(IssueCodes.MISSING_YARN_WORKSPACE) public void installMissingNPM(Issue issue, IssueResolutionAcceptor acceptor) { final String[] userData = issue.getData(); final String packageName = userData[0]; final String versionRequirement = userData[1]; final String msgAtVersion = Strings.isNullOrEmpty(versionRequirement) ? "" : "@" + versionRequirement; final String label = "Install npm package " + packageName + msgAtVersion; final String description = "Calls npm/yarn to install the missing npm package into the workspace."; final String errMsg = "Error while uninstalling npm dependency: '" + packageName + "'."; N4Modification modification = new N4Modification() { @Override public Collection<? extends IChange> computeChanges(IModificationContext context, final IMarker marker, int offset, int length, EObject element) throws Exception { Function<IProgressMonitor, IStatus> registerFunction = new Function<>() { @Override public IStatus apply(IProgressMonitor monitor) { final URI uri = issue.getUriToProblem(); final IN4JSProject containingProject = n4jsCore.findProject(uri).orNull(); if (containingProject == null) { return statusHelper.createError("cannot find containing project"); } FileURI targetLocation = containingProject.getLocation().toFileURI(); Map<N4JSProjectName, NPMVersionRequirement> installedNpms = new HashMap<>(); NPMVersionRequirement versionReq = semverHelper.parse(versionRequirement); N4JSProjectName typesafePackageName = new N4JSProjectName(packageName); installedNpms.put(typesafePackageName, versionReq); return libraryManager.installNPM(typesafePackageName, versionRequirement, targetLocation, monitor); } }; wrapWithMonitor(label, errMsg, registerFunction); return Collections.emptyList(); } }; accept(acceptor, issue, label, description, null, modification); }