org.eclipse.xtext.ui.editor.model.edit.ISemanticModification Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.model.edit.ISemanticModification. 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: XtextGrammarQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #2
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #3
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #4
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 #5
Source File: DotQuickfixProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void provideQuickfixesForDuplicatedStyleItem(Issue issue,
		IssueResolutionAcceptor acceptor) {
	final String styleItem = issue.getData()[1];

	String label = "Remove '" + styleItem + "' style attribute value."; //$NON-NLS-1$ //$NON-NLS-2$
	String description = "Remove the redundant '" + styleItem //$NON-NLS-1$
			+ "' style attribute value."; //$NON-NLS-1$

	ISemanticModification semanticModification = new ChangingDotAttributeValueSemanticModification() {
		@Override
		public String getNewValue(String currentValue) {
			return currentValue.replaceFirst(styleItem + ",", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
		}
	};

	acceptor.accept(issue, label, description, DELETE_IMAGE,
			semanticModification);
}
 
Example #6
Source File: DotQuickfixProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@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 #7
Source File: DotHtmlLabelQuickfixDelegator.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
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 #8
Source File: CreateJavaTypeQuickfixes.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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 #9
Source File: CheckQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes the guard statement occurring at offending position.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.GUARDS_COME_FIRST)
@SuppressWarnings("unchecked")
public void removeGuardStatement(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_GUARD_LABEL, Messages.CheckQuickfixProvider_REMOVE_GUARD_DESCN, NO_IMAGE, new ISemanticModification() {
    @Override
    public void apply(final EObject element, final IModificationContext context) {
      final XGuardExpression guard = EcoreUtil2.getContainerOfType(element, XGuardExpression.class);
      if (guard != null && guard.eContainingFeature().isMany()) {
        EList<? extends EObject> holder = (EList<? extends EObject>) guard.eContainer().eGet(guard.eContainingFeature());
        if (holder != null && holder.contains(guard)) {
          holder.remove(guard);
        }
      }
    }
  });
}
 
Example #10
Source File: CheckQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #11
Source File: CheckQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes the severity range declaration from the check. Final conflicts with severity range.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.SEVERITY_RANGES_FOR_FINAL_CHECK)
public void removeSeverityRange(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_SEVERITY_RANGE_LABEL, Messages.CheckQuickfixProvider_REMOVE_SEVERITY_RANGE_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.setSeverityRange(null);
      }
    }
  });
}
 
Example #12
Source File: CheckQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes a duplicate parameter definition.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.DUPLICATE_PARAMETER_DEFINITION)
public void removeDuplicateParameterDefinition(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_PARAM_DEF_LABEL, Messages.CheckQuickfixProvider_REMOVE_PARAM_DEF_DESCN, null, new ISemanticModification() {
    @Override
    public void apply(final EObject element, final IModificationContext context) {
      Check check = EcoreUtil2.getContainerOfType(element, Check.class);
      check.getFormalParameters().remove(element);
    }
  });
}
 
Example #13
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void newLocalVariableQuickfix(final String variableName, XAbstractFeatureCall call, Issue issue,
		IssueResolutionAcceptor issueResolutionAcceptor) {
	LightweightTypeReference variableType = getNewMemberType(call);
	final StringBuilderBasedAppendable localVarDescriptionBuilder = new StringBuilderBasedAppendable();
	localVarDescriptionBuilder.append("...").newLine();
	final String defaultValueLiteral = getDefaultValueLiteral(variableType);
	localVarDescriptionBuilder.append("val ").append(variableName).append(" = ").append(defaultValueLiteral);
	localVarDescriptionBuilder.newLine().append("...");
	issueResolutionAcceptor.accept(issue, "Create local variable '" + variableName + "'",
			localVarDescriptionBuilder.toString(), "fix_local_var.png",
			new SemanticModificationWrapper(issue.getUriToProblem(), new ISemanticModification() {
				@Override
				public void apply(/* @Nullable */ final EObject element, /* @Nullable */ final IModificationContext context) throws Exception {
					if (element != null) {
						XtendMember xtendMember = EcoreUtil2.getContainerOfType(element, XtendMember.class);
						if (xtendMember != null) {
							int offset = getFirstOffsetOfKeyword(xtendMember, "{");
							IXtextDocument xtextDocument = context.getXtextDocument();
							if (offset != -1 && xtextDocument != null) {
								final ReplacingAppendable appendable = appendableFactory.create(xtextDocument,
										(XtextResource) element.eResource(), offset, 0, new OptionalParameters() {{ 
											baseIndentationLevel = 1;	
										}});
								appendable.increaseIndentation().newLine().append("val ").append(variableName).append(" = ")
										.append(defaultValueLiteral);
								appendable.commitChanges();
							}
						}
					}
				}
			}));
}
 
Example #14
Source File: CheckCfgQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes a duplicate catalog configuration.
 * 
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.DUPLICATE_CATALOG_CONFIGURATION)
public void removeDuplicateCatalogConfiguration(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CATALOG_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CATALOG_DESCN, null, new ISemanticModification() {
    public void apply(final EObject element, final IModificationContext context) {
      CheckConfiguration configuration = EcoreUtil2.getContainerOfType(element, CheckConfiguration.class);
      configuration.getLegacyCatalogConfigurations().remove(element);
    }
  });
}
 
Example #15
Source File: CheckCfgQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes a duplicate check configuration.
 * 
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.DUPLICATE_CHECK_CONFIGURATION)
public void removeDuplicateCheckConfiguration(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CHECK_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CHECK_DESCN, null, new ISemanticModification() {
    public void apply(final EObject element, final IModificationContext context) {
      ConfiguredCatalog catalog = EcoreUtil2.getContainerOfType(element, ConfiguredCatalog.class);
      catalog.getCheckConfigurations().remove(element);
    }
  });
}
 
Example #16
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.MODIFIER_DOES_NOT_MATCH_TYPENAME)
public void addModifierAccordingToTypename(final Issue issue, IssueResolutionAcceptor acceptor) {
	String label = "Add missing abstract modifier.";
	String description = "Add the abstract modifier to match naming conventions for the "
			+ "type name. Delete final modifier if necessary.";
	String image = null;

	acceptor.accept(issue, label, description, image, new ISemanticModification() {
		@Override
		public void apply(EObject element, IModificationContext context) throws Exception {
			if (element instanceof XtendClass) {
				int index = 0;
				List<String> modifiers = ((XtendClass) element).getModifiers();
				boolean modExist = !modifiers.isEmpty();

				//remove final modifier if present, as type cannot be both final and abstract
				modifiers.remove("final");

				//add abstract
				if (modifiers.contains("public") || modifiers.contains("package")) {
					index++;
				}
				if (modExist) {
					modifiers.add(index, "abstract");
				} else {
					//use existent method to add abstract modifier, if modifier list is empty, to prevent wrong insertion
					internalDoAddAbstractKeyword(element, context);
				}
			}
		}
	});
}
 
Example #17
Source File: CheckCfgQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes a duplicate parameter configuration.
 * 
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.DUPLICATE_PARAMETER_CONFIGURATION)
public void removeDuplicateParameterConfiguration(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_PARAM_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_PARAM_DESCN, null, new ISemanticModification() {
    public void apply(final EObject element, final IModificationContext context) {
      ConfiguredCheck check = EcoreUtil2.getContainerOfType(element, ConfiguredCheck.class);
      check.getParameterConfigurations().remove(element);
    }
  });
}
 
Example #18
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.IMPLICIT_RETURN) 
public void fixImplicitReturn(final Issue issue, IssueResolutionAcceptor acceptor){
	acceptor.accept(issue, "Add \"return\" keyword", "Add \"return\" keyword", null, new ISemanticModification() {
		@Override
		public void apply(EObject element, IModificationContext context) throws Exception {
			ICompositeNode node = NodeModelUtils.findActualNodeFor(element);
			ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) element.eResource(), node.getOffset(), 0);
			appendable.append("return ");
			appendable.commitChanges();
		}
	});
}
 
Example #19
Source File: CheckCfgQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes the configured values of a disabled check.
 * 
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.DISABLED_CHECK_NOT_CONFIGURED)
public void removeConfiguredParamsOfDisabledCheck(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_CONFIGURED_PARAM_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_CONFIGURED_PARAM_DESCN, null, new ISemanticModification() {
    public void apply(final EObject element, final IModificationContext context) {
      ConfiguredCheck check = EcoreUtil2.getContainerOfType(element, ConfiguredCheck.class);
      check.getParameterConfigurations().removeAll(check.getParameterConfigurations());
    }
  });
}
 
Example #20
Source File: CheckCfgQuickfixProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Reset the severity of a configured check which is final to {@code default}.
 * 
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.FINAL_CHECK_NOT_CONFIGURABLE)
public void resetSeverityOfFinalCheck(final Issue issue, final IssueResolutionAcceptor acceptor) {
  acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_OF_FINAL_CHECK_LABEL, Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_OF_FINAL_CHECK_DESCN, null, new ISemanticModification() {
    public void apply(final EObject element, final IModificationContext context) {
      ConfiguredCheck check = EcoreUtil2.getContainerOfType(element, ConfiguredCheck.class);
      check.setSeverity(SeverityKind.DEFAULT);
    }
  });
}
 
Example #21
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.API_TYPE_INFERENCE)
public void specifyTypeExplicitly(Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.accept(issue, "Infer type", "Infer type", null, new ISemanticModification() {
		@Override
		public void apply(EObject element, IModificationContext context) throws Exception {
			EStructuralFeature featureAfterType = null;
			JvmIdentifiableElement jvmElement = null;
			if (element instanceof XtendFunction) {
				XtendFunction function = (XtendFunction) element;
				if (function.getCreateExtensionInfo() == null) {
					featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__NAME;
				} else {
					featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__CREATE_EXTENSION_INFO;
				}
				jvmElement = associations.getDirectlyInferredOperation((XtendFunction) element);
			} else if (element instanceof XtendField) {
				featureAfterType = XtendPackage.Literals.XTEND_FIELD__NAME;
				jvmElement = associations.getJvmField((XtendField) element);
			}
			
			if (jvmElement != null) {
				LightweightTypeReference type = batchTypeResolver.resolveTypes(element).getActualType(jvmElement);
				INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(element, featureAfterType), null);
				
				if (node == null) {
					throw new IllegalStateException("Could not determine node for " + element);
				}
				if (type == null) {
					throw new IllegalStateException("Could not determine type for " + element);
				}
				ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(),
						(XtextResource) element.eResource(), node.getOffset(), 0);
				appendable.append(type);
				appendable.append(" ");
				appendable.commitChanges();
			}
		}
	});
}
 
Example #22
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.MISSING_ABSTRACT)
public void makeClassAbstract(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.accept(issue, "Make class abstract", "Make class abstract", "fix_indent.gif",
			new ISemanticModification() {
				@Override
				public void apply(EObject element, IModificationContext context) throws Exception {
					internalDoAddAbstractKeyword(element, context);
				}
			});
}
 
Example #23
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.XBASE_LIB_NOT_ON_CLASSPATH)
public void putXtendOnClasspath(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.accept(issue, "Add Xtend libs to classpath", "Add Xtend libs to classpath", "fix_indent.gif", new ISemanticModification() {
		@Override
		public void apply(EObject element, IModificationContext context) throws Exception {
			ResourceSet resourceSet = element.eResource().getResourceSet();
			IJavaProject javaProject = projectProvider.getJavaProject(resourceSet);
			xtendLibAdder.addLibsToClasspath(javaProject, new NullProgressMonitor());
		}
	});
}
 
Example #24
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #25
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void doOverrideMethods(final Issue issue, IssueResolutionAcceptor acceptor, String label, final String[] operationUris) {
	acceptor.accept(issue, label, label, "fix_indent.gif",
			new ISemanticModification() {
				@Override
				public void apply(EObject element, IModificationContext context) throws Exception {
					XtendTypeDeclaration clazz = (XtendTypeDeclaration) element;
					JvmGenericType inferredType = (JvmGenericType) associations.getInferredType(clazz);
					ResolvedFeatures resolvedOperations = overrideHelper.getResolvedFeatures(inferredType);
					IXtextDocument document = context.getXtextDocument();
					final int offset = insertionOffsets.getNewMethodInsertOffset(null, clazz);
					int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, (XtextResource) clazz.eResource());
					final int indentationToUse = clazz.getMembers().isEmpty() ? currentIndentation + 1 : currentIndentation;
					ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(),
							offset, 0, new OptionalParameters() {{ 
								ensureEmptyLinesAround = true;
								baseIndentationLevel = indentationToUse;	
							}});
					boolean isFirst = true;
					for (String operationUriAsString : operationUris) {
						URI operationURI = URI.createURI(operationUriAsString);
						EObject overridden = clazz.eResource().getResourceSet().getEObject(operationURI, true);
						if (overridden instanceof JvmOperation) {
							if(!isFirst) 
								appendable.newLine().newLine();
							isFirst = false;
							
							superMemberImplementor.appendOverrideFunction(clazz, resolvedOperations.getResolvedOperation((JvmOperation) overridden),
									appendable);
						}
					}
					appendable.commitChanges();
				}
			});
}
 
Example #26
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.CLASS_MUST_BE_ABSTRACT)
public void implementAbstractMethods(final Issue issue, IssueResolutionAcceptor acceptor) {
	doOverrideMethods(issue, acceptor, "Add unimplemented methods");
	acceptor.accept(issue, "Make class abstract", "Make class abstract", "fix_indent.gif",
			new ISemanticModification() {
		@Override
		public void apply(EObject element, IModificationContext context) throws Exception {
			internalDoAddAbstractKeyword(element, context);
		}
	});
}
 
Example #27
Source File: QuickfixCrossrefTestLanguageQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(SEMANTIC_FIX_ID)
public void rename(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.accept(issue, SEMANTIC_FIX_ID, SEMANTIC_FIX_ID, null, new ISemanticModification() {
		@Override
		public void apply(EObject element, IModificationContext context) {
			((Element) element).setName("Bor");
		}
	});
}
 
Example #28
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.MISSING_SYNCHRONIZED)
public void fixMissingSynchronizedKeyword(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.accept(issue, "Mark operation as synchronized", "Marks this operation as synchronized", "fix_indent.gif", new ISemanticModification() {
		@Override
		public void apply(EObject element, IModificationContext context) throws Exception {
			if (element instanceof XtendFunction) {
				((XtendFunction) element).getModifiers().add("synchronized");
			}
		}
	});
}
 
Example #29
Source File: DotQuickfixProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void provideQuickfix(String invalidValue, String validValue,
		String suffix, Issue issue, IssueResolutionAcceptor acceptor,
		ISemanticModification semanticModification) {
	acceptor.accept(issue,
			"Replace '" + invalidValue + "' with '" + validValue //$NON-NLS-1$ //$NON-NLS-2$
					+ "'.", //$NON-NLS-1$
			"Use valid '" + validValue + "' instead of invalid '" //$NON-NLS-1$ //$NON-NLS-2$
					+ invalidValue + "' " + suffix + ".", //$NON-NLS-1$ //$NON-NLS-2$
			null, semanticModification);
}
 
Example #30
Source File: DotHtmlLabelQuickfixProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(DotHtmlLabelValidator.HTML_ATTRIBUTE_INVALID_ATTRIBUTE_NAME)
public void fixInvalidAttributeName(final Issue issue,
		IssueResolutionAcceptor acceptor) {
	String[] issueData = issue.getData();
	String tagName = issueData[2];
	String invalidAttribute = issueData[3];

	Set<String> validAttributes = DotHtmlLabelHelper.getValidAttributes()
			.get(tagName.toUpperCase());

	List<String> validAttributesSorted = new ArrayList<>(validAttributes);
	Collections.sort(validAttributesSorted);

	for (String validAttribute : validAttributesSorted) {
		String label = "Change to '" + validAttribute + "'."; //$NON-NLS-1$ //$NON-NLS-2$
		String description = "Change '" //$NON-NLS-1$
				+ invalidAttribute + "' to '" + validAttribute + "'."; //$NON-NLS-1$ //$NON-NLS-2$
		acceptor.accept(issue, label, description, null,
				new ISemanticModification() {

					@Override
					public void apply(EObject element,
							IModificationContext context) throws Exception {
						if (element instanceof HtmlAttr) {
							HtmlAttr htmlAttr = (HtmlAttr) element;
							htmlAttr.setName(validAttribute);
						}
					}
				});
	}
}