org.eclipse.xtext.ui.editor.model.edit.IModificationContext Java Examples
The following examples show how to use
org.eclipse.xtext.ui.editor.model.edit.IModificationContext.
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: CreateJavaTypeQuickfixes.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void newJavaClassQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) { String packageDescription = getPackageDescription(explicitPackage); issueResolutionAcceptor.accept(issue, "Create Java class '" + typeName + "'" + packageDescription, "Opens the new Java class wizard to create the type '" + typeName + "'" + packageDescription, "java_file.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { runAsyncInDisplayThread(new Runnable() { @Override public void run() { NewClassWizardPage classWizardPage = new NewClassWizardPage(); NewClassCreationWizard wizard = new NewClassCreationWizard(classWizardPage, true); WizardDialog dialog = createWizardDialog(wizard); configureWizardPage(classWizardPage, resource.getURI(), typeName, explicitPackage); dialog.open(); } }); } }); }
Example #2
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 #3
Source File: N4ModificationWrapper.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public final void apply(IModificationContext context) throws Exception { context.getXtextDocument().modify(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { final IMarker marker = issue instanceof N4JSIssue ? ((N4JSIssue) issue).getMarker() : null; final EObject element = resource.getEObject(issue.getUriToProblem().fragment()); final Collection<? extends IChange> changes = modification.computeChanges( context, marker, issue.getOffset(), issue.getLength(), element); changeManager.applyAll(changes); } }); }
Example #4
Source File: MultiModification.java From sarl with Apache License 2.0 | 6 votes |
@Override public void apply(EObject element, IModificationContext context) throws Exception { Class<? extends SARLSemanticModification> selected = null; Class<?> deeperType = null; for (final Entry<Class<?>, Class<? extends SARLSemanticModification>> entry : this.modificationTypes.entrySet()) { if (entry.getKey().isInstance(element)) { if (deeperType == null || deeperType.isAssignableFrom(entry.getKey())) { deeperType = entry.getKey(); selected = entry.getValue(); } } } if (selected != null) { final SARLSemanticModification modification = selected.newInstance(); modification.setIssue(getIssue()); modification.setTools(getTools()); modification.apply(element, context); } }
Example #5
Source File: SARLQuickfixProvider.java From sarl with Apache License 2.0 | 6 votes |
@Override protected void internalDoAddAbstractKeyword(EObject element, IModificationContext context) throws BadLocationException { EObject container = element; if (element instanceof SarlAction) { container = element.eContainer(); } XtendTypeDeclaration declaration = null; String keyword = null; if (container instanceof SarlAgent) { declaration = (XtendTypeDeclaration) container; keyword = getGrammarAccess().getAgentKeyword(); } else if (container instanceof SarlBehavior) { declaration = (XtendTypeDeclaration) container; keyword = getGrammarAccess().getBehaviorKeyword(); } else if (container instanceof SarlSkill) { declaration = (XtendTypeDeclaration) container; keyword = getGrammarAccess().getSkillKeyword(); } if (declaration != null && keyword != null) { final IXtextDocument document = context.getXtextDocument(); addAbstractKeyword(declaration, document, keyword); } else { super.internalDoAddAbstractKeyword(container, context); } }
Example #6
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 #7
Source File: QuickfixCrossrefTestLanguageQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Fix(QuickfixCrossrefTestLanguageValidator.LOWERCASE) public void fixLowercase(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "fix lowercase", "fix lowercase", null, new ITextualMultiModification() { @Override public void apply(IModificationContext context) throws Exception { if (context instanceof IssueModificationContext) { Issue theIssue = ((IssueModificationContext) context).getIssue(); IXtextDocument document = context.getXtextDocument(); String upperCase = document.get(theIssue.getOffset(), theIssue.getLength()).toUpperCase(); // uppercase + duplicate => allows offset change tests document.replace(theIssue.getOffset(), theIssue.getLength(), upperCase + "_" +upperCase); } } }); }
Example #8
Source File: SuppressWarningsAddModification.java From sarl with Apache License 2.0 | 6 votes |
/** Add SuppressWarnings annotation. * * @param element the element to receive the annotation. * @param annotation the suppress-warning annotation. * @param context the modification context. * @throws Exception if the document cannot be changed. */ protected void addAnnotation(EObject element, XAnnotation annotation, IModificationContext context) throws Exception { final ICompositeNode node = NodeModelUtils.findActualNodeFor(annotation); if (node != null) { final IXtextDocument document = context.getXtextDocument(); final int startOffset = node.getOffset(); final int parameterOffset = getTools().getOffsetForPattern(document, startOffset, "@\\s*" + toPattern(annotation.getAnnotationType().getQualifiedName()) //$NON-NLS-1$ + "\\s*\\(\\s*"); //$NON-NLS-1$ final int insertOffset; if (document.getChar(parameterOffset) == '{') { insertOffset = parameterOffset + getTools().getSpaceSize(document, parameterOffset + 1) + 1; } else { insertOffset = parameterOffset; } final ReplacingAppendable appendable = getTools().getAppendableFactory().create(document, (XtextResource) element.eResource(), insertOffset, 0); appendable.append("\""); //$NON-NLS-1$ appendable.append(extractId(this.code)); appendable.append("\", "); //$NON-NLS-1$ appendable.commitChanges(); } }
Example #9
Source File: N4JSPackageJsonQuickfixProviderExtension.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** Changes the project type to {@link ProjectType#VALIDATION} */ @Fix(IssueCodes.OUTPUT_AND_SOURCES_FOLDER_NESTING) public void changeProjectTypeToValidation(Issue issue, IssueResolutionAcceptor acceptor) { String validationPT = ProjectType.VALIDATION.getName().toLowerCase(); String title = "Change project type to '" + validationPT + "'"; String descr = "The project type '" + validationPT + "' does not generate code. Hence, output and source folders can be nested."; accept(acceptor, issue, title, descr, null, new N4Modification() { @Override public Collection<? extends IChange> computeChanges(IModificationContext context, IMarker marker, int offset, int length, EObject element) throws Exception { Resource resource = element.eResource(); ProjectDescription prjDescr = EcoreUtil2.getContainerOfType(element, ProjectDescription.class); Collection<IChange> changes = new LinkedList<>(); changes.add(PackageJsonChangeProvider.setProjectType(resource, ProjectType.VALIDATION, prjDescr)); return changes; } @Override public boolean supportsMultiApply() { return false; } }); }
Example #10
Source File: CheckQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Fix catalog name. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.WRONG_FILE) public void fixCatalogName(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_CORRECT_CATALOG_NAME_LABEL, Messages.CheckQuickfixProvider_CORRECT_CATALOG_NAME_DESCN, NO_IMAGE, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); IFile file = xtextDocument.getAdapter(IFile.class); if (file != null) { final String fileName = file.getName(); final String name = fileName.indexOf('.') > 0 ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName; xtextDocument.replace(issue.getOffset(), issue.getLength(), name); } } }); }
Example #11
Source File: CreateXtendTypeQuickfixes.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void newXtendInterfaceQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) { String packageDescription = getPackageDescription(explicitPackage); issueResolutionAcceptor.accept(issue, "Create Xtend interface '" + typeName + "'" + packageDescription, "Opens the new Xtend interface wizard to create the type '" + typeName + "'" + packageDescription, "xtend_file.png", new IModification() { @Override public void apply(/* @Nullable */ IModificationContext context) throws Exception { runAsyncInDisplayThread(new Runnable() { @Override public void run() { NewElementWizard newXtendInterfaceWizard = newXtendInterfaceWizardProvider.get(); WizardDialog dialog = createWizardDialog(newXtendInterfaceWizard); NewXtendInterfaceWizardPage page = (NewXtendInterfaceWizardPage) newXtendInterfaceWizard.getStartingPage(); configureWizardPage(page, resource.getURI(), typeName, explicitPackage); dialog.open(); } }); } }); }
Example #12
Source File: CreateXtendTypeQuickfixes.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void newXtendAnnotationQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) { String packageDescription = getPackageDescription(explicitPackage); issueResolutionAcceptor.accept(issue, "Create Xtend annotation '" + typeName + "'" + packageDescription, "Opens the new Xtend annotation wizard to create the type '" + typeName + "'" + packageDescription, "xtend_file.png", new IModification() { @Override public void apply(/* @Nullable */ IModificationContext context) throws Exception { runAsyncInDisplayThread(new Runnable() { @Override public void run() { NewElementWizard newXtendAnnotationWizard = newXtendAnnotationWizardProvider.get(); WizardDialog dialog = createWizardDialog(newXtendAnnotationWizard); NewXtendAnnotationWizardPage page = (NewXtendAnnotationWizardPage) newXtendAnnotationWizard.getStartingPage(); configureWizardPage(page, resource.getURI(), typeName, explicitPackage); dialog.open(); } }); } }); }
Example #13
Source File: CreateXtendTypeQuickfixes.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void newXtendClassQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) { String packageDescription = getPackageDescription(explicitPackage); issueResolutionAcceptor.accept(issue, "Create Xtend class '" + typeName + "'" + packageDescription, "Opens the new Xtend class wizard to create the type '" + typeName + "'" + packageDescription, "xtend_file.png", new IModification() { @Override public void apply(/* @Nullable */ IModificationContext context) throws Exception { runAsyncInDisplayThread(new Runnable() { @Override public void run() { NewElementWizard newXtendClassWizard = newXtendClassWizardProvider.get(); WizardDialog dialog = createWizardDialog(newXtendClassWizard); NewXtendClassWizardPage page = (NewXtendClassWizardPage) newXtendClassWizard.getStartingPage(); configureWizardPage(page, resource.getURI(), typeName, explicitPackage); dialog.open(); } }); } }); }
Example #14
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void internalDoAddAbstractKeyword(EObject element, IModificationContext context) throws BadLocationException { if (element instanceof XtendFunction) { element = element.eContainer(); } if (element instanceof XtendClass) { XtendClass clazz = (XtendClass) element; IXtextDocument document = context.getXtextDocument(); ICompositeNode clazzNode = NodeModelUtils.findActualNodeFor(clazz); if (clazzNode == null) throw new IllegalStateException("Cannot determine node for clazz " + clazz.getName()); int offset = -1; for (ILeafNode leafNode : clazzNode.getLeafNodes()) { if (leafNode.getText().equals("class")) { offset = leafNode.getOffset(); break; } } ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(), offset, 0); appendable.append("abstract "); appendable.commitChanges(); } }
Example #15
Source File: CapacityReferenceRemoveModification.java From sarl with Apache License 2.0 | 6 votes |
@Override public void apply(EObject element, IModificationContext context) throws Exception { final Issue issue = getIssue(); final SARLQuickfixProvider tools = getTools(); final IXtextDocument document = context.getXtextDocument(); final String sep = tools.getGrammarAccess().getCommaKeyword(); if (!tools.removeToPreviousSeparator(issue, document, sep)) { if (!tools.removeToNextSeparator(issue, document, sep)) { tools.removeToPreviousKeyword(issue, document, tools.getGrammarAccess() .getRequiresKeyword(), tools.getGrammarAccess() .getUsesKeyword()); } } }
Example #16
Source File: SuppressWarningsAddModification.java From sarl with Apache License 2.0 | 6 votes |
@Override public void apply(EObject element, IModificationContext context) throws Exception { final EObject currentElement; if (this.uri == null) { currentElement = element; } else { currentElement = element.eResource().getResourceSet().getEObject(this.uri, true); } if (currentElement instanceof XtendAnnotationTarget) { final JvmType swtype = getTools().getTypeServices().getTypeReferences().findDeclaredType( SuppressWarnings.class, element); final XtendAnnotationTarget annotationTarget = (XtendAnnotationTarget) currentElement; final XAnnotation annotation = findAnnotation(annotationTarget, swtype); if (annotation == null) { addAnnotation(currentElement, context, swtype); } else { addAnnotation(currentElement, annotation, context); } } }
Example #17
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 #18
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Fix(IssueCodes.WRONG_PACKAGE) public void fixPackageName(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() != null && issue.getData().length == 1) { final String expectedPackage = issue.getData()[0]; acceptor.accept(issue, "Change package declaration to '" + expectedPackage + "'", "Change package declaration to '" + expectedPackage + "'", "package_obj.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { XtendFile file = (XtendFile) element; String newPackageName = isEmpty(expectedPackage) ? null : expectedPackage; String oldPackageName = file.getPackage(); for(EObject obj: file.eResource().getContents()) { if (obj instanceof JvmDeclaredType) { JvmDeclaredType type = (JvmDeclaredType) obj; String typePackage = type.getPackageName(); if (Objects.equal(typePackage, oldPackageName) || typePackage != null && typePackage.startsWith(oldPackageName + ".")) { type.internalSetIdentifier(null); type.setPackageName(newPackageName); } } } file.setPackage(newPackageName); } }); } }
Example #19
Source File: CheckQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Fixes the severity range order by setting the lower severity level kind first and the severity of higher severity level last. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.ILLEGAL_SEVERITY_RANGE_ORDER) public void fixSeverityRangeOrder(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_FIX_SEVERITY_RANGE_ORDER_LABEL, Messages.CheckQuickfixProvider_FIX_SEVERITY_RANGE_ORDER_DESCN, NO_IMAGE, new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) { final Check check = EcoreUtil2.getContainerOfType(element, Check.class); if (check != null && check.getSeverityRange() != null) { final SeverityRange range = check.getSeverityRange(); SeverityKind oldMinSeverity = range.getMinSeverity(); range.setMinSeverity(range.getMaxSeverity()); range.setMaxSeverity(oldMinSeverity); } } }); }
Example #20
Source File: SuppressWarningsAddModification.java From sarl with Apache License 2.0 | 6 votes |
/** Add SuppressWarnings annotation. * * @param element the element to receive the annotation. * @param context the modification context. * @param suppressWarningsAnnotation the type for the suppress warning annotation. * @throws Exception if the document cannot be changed. */ protected void addAnnotation(EObject element, IModificationContext context, JvmType suppressWarningsAnnotation) throws Exception { final ICompositeNode node = NodeModelUtils.findActualNodeFor(element); if (node != null) { final int insertOffset = node.getOffset(); final IXtextDocument document = context.getXtextDocument(); final int length = getTools().getSpaceSize(document, insertOffset); final ReplacingAppendable appendable = getTools().getAppendableFactory().create(document, (XtextResource) element.eResource(), insertOffset, length); appendable.append(getTools().getGrammarAccess().getCommercialAtKeyword()); appendable.append(suppressWarningsAnnotation); appendable.append("(\""); //$NON-NLS-1$ appendable.append(extractId(this.code)); appendable.append("\")"); //$NON-NLS-1$ appendable.newLine(); appendable.commitChanges(); } }
Example #21
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Fix(IssueCodes.OBSOLETE_OVERRIDE) public void fixObsoleteOverride(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Change 'override' to 'def'", "Removes 'override' from this function", "fix_indent.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { replaceKeyword(grammarAccess.getMethodModifierAccess().findKeywords("override").get(0), "def", element, context.getXtextDocument()); if (element instanceof XtendFunction) { XtendFunction function = (XtendFunction) element; for (XAnnotation anno : Lists.reverse(function.getAnnotations())) { if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) { ICompositeNode node = NodeModelUtils.findActualNodeFor(anno); context.getXtextDocument().replace(node.getOffset(), node.getLength(), ""); } } } } }); }
Example #22
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private void addTypeCastToImplicitReceiver(XFeatureCall featureCall, IModificationContext context, JvmType declaringType) throws BadLocationException { String receiver; if (featureCall.getImplicitReceiver() instanceof XAbstractFeatureCall) receiver = ((XAbstractFeatureCall) featureCall.getImplicitReceiver()).getFeature().getSimpleName(); else return; List<INode> nodes = NodeModelUtils.findNodesForFeature(featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE); if (nodes.isEmpty()) return; INode firstNode = IterableExtensions.head(nodes); int offset = firstNode.getOffset(); ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, 0); appendable.append("("); appendable.append(receiver); appendable.append(" as "); appendable.append(declaringType); appendable.append(")."); appendable.commitChanges(); }
Example #23
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Fix(IssueCodes.MISSING_OVERRIDE) public void fixMissingOverride(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Change 'def' to 'override'", "Marks this function as 'override'", "fix_indent.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { replaceKeyword(grammarAccess.getMethodModifierAccess().findKeywords("def").get(0), "override", element, context.getXtextDocument()); if (element instanceof XtendFunction) { XtendFunction function = (XtendFunction) element; for (XAnnotation anno : Lists.reverse(function.getAnnotations())) { if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) { ICompositeNode node = NodeModelUtils.findActualNodeFor(anno); context.getXtextDocument().replace(node.getOffset(), node.getLength(), ""); } } } } }); }
Example #24
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 #25
Source File: DotHtmlLabelQuickfixDelegator.java From gef with Eclipse Public License 2.0 | 6 votes |
public void provideQuickfixes(Issue originalIssue, Issue subgrammarIssue, IssueResolutionAcceptor acceptor) { List<IssueResolution> resolutions = getResolutions(subgrammarIssue); for (IssueResolution issueResolution : resolutions) { acceptor.accept(originalIssue, issueResolution.getLabel(), issueResolution.getDescription(), issueResolution.getImage(), new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { Attribute attribute = (Attribute) element; String originalText = attribute.getValue() .toValue(); String modifiedText = getModifiedText(originalText, issueResolution); attribute.setValue(ID.fromValue(modifiedText, ID.Type.HTML_STRING)); } }); } }
Example #26
Source File: CreateJavaTypeQuickfixes.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void newJavaAnnotationQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) { String packageDescription = getPackageDescription(explicitPackage); issueResolutionAcceptor.accept(issue, "Create Java annotation '@" + typeName + "'" + packageDescription, "Opens the new Java annotation wizard to create the type '@" + typeName + "'" + packageDescription, "java_file.gif", new IModification() { @Override public void apply(/* @Nullable */ IModificationContext context) throws Exception { runAsyncInDisplayThread(new Runnable() { @Override public void run() { NewAnnotationWizardPage annotationWizardPage = new NewAnnotationWizardPage(); NewAnnotationCreationWizard wizard = new NewAnnotationCreationWizard(annotationWizardPage, true); WizardDialog dialog = createWizardDialog(wizard); configureWizardPage(annotationWizardPage, resource.getURI(), typeName, explicitPackage); dialog.open(); } }); } }); }
Example #27
Source File: CheckQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** {@inheritDoc} */ @Override public void apply(final IModificationContext context) throws BadLocationException { final IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(final XtextResource state) throws Exception { // NOPMD final EObject target = EcoreUtil2.getContainerOfType(state.getEObject(issue.getUriToProblem().fragment()), type); if (type.isInstance(target)) { int offset = NodeModelUtils.findActualNodeFor(target).getOffset(); int lineOfOffset = xtextDocument.getLineOfOffset(offset); int lineOffset = xtextDocument.getLineOffset(lineOfOffset); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < (offset - lineOffset); i++) { buffer.append(' '); } xtextDocument.replace(offset, 0, NLS.bind(autodocumentation, buffer.toString())); } } }); }
Example #28
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.INCONSISTENT_INDENTATION) public void fixIndentation(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Correct indentation", "Correctly indents this line in this rich string", "fix_indent.gif", new IModification() { @Override public void apply(IModificationContext context) throws Exception { context.getXtextDocument().replace(issue.getOffset(), issue.getLength(), issue.getData()[0]); } }); }
Example #29
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.MISSING_CONSTRUCTOR) public void addConstuctorFromSuper(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() != null) { for(int i=0; i<issue.getData().length; i+=2) { final URI constructorURI = URI.createURI(issue.getData()[i]); String javaSignature = issue.getData()[i+1]; String xtendSignature = "new" + javaSignature.substring(javaSignature.indexOf('(')); acceptor.accept(issue, "Add constructor " + xtendSignature, "Add constructor " + xtendSignature, "fix_indent.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { XtendClass clazz = (XtendClass) element; JvmGenericType inferredType = associations.getInferredType(clazz); ResolvedFeatures features = overrideHelper.getResolvedFeatures(inferredType); ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) clazz.eResource(), insertionOffsets.getNewConstructorInsertOffset(null, clazz), 0, new OptionalParameters() {{ ensureEmptyLinesAround = true; baseIndentationLevel = 1; }}); EObject constructor = clazz.eResource().getResourceSet().getEObject(constructorURI, true); if (constructor instanceof JvmConstructor) { superMemberImplementor.appendConstructorFromSuper( clazz, new ResolvedConstructor((JvmConstructor) constructor, features.getType()), appendable); } appendable.commitChanges(); } }); } } }
Example #30
Source File: DotQuickfixProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void apply(EObject element, IModificationContext context) throws Exception { Attribute attribute = (Attribute) element; ID value = attribute.getValue(); String currentValue = value.toValue(); Type type = value.getType(); String newValue = getNewValue(currentValue); ID newValueAsID = ID.fromValue(newValue, type); attribute.setValue(newValueAsID); }