Search in sources :

Example 1 with NewFeatureNameUtil

use of org.eclipse.xtext.xbase.ui.refactoring.NewFeatureNameUtil in project xtext-eclipse by eclipse.

the class NewFeatureNameUtilTest method assertDefaultName.

protected void assertDefaultName(final String modelWithSelectionMarkup, final String expectedName) {
    final String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
    final XExpression expression = this.parse(cleanedModel);
    final int selectionOffset = modelWithSelectionMarkup.indexOf("$");
    int _lastIndexOf = modelWithSelectionMarkup.lastIndexOf("$");
    int _minus = (_lastIndexOf - selectionOffset);
    final int selectionLength = (_minus - 1);
    Resource _eResource = expression.eResource();
    TextSelection _textSelection = new TextSelection(selectionOffset, selectionLength);
    final XExpression selectedExpression = this.util.findSelectedExpression(((XtextResource) _eResource), _textSelection);
    final XExpression successor = this.util.findSuccessorExpressionForVariableDeclaration(selectedExpression);
    final NewFeatureNameUtil nameUtil = this.nameUtilProvider.get();
    nameUtil.setFeatureScopeContext(successor);
    final String defaultName = nameUtil.getDefaultName(selectedExpression);
    Assert.assertEquals(expectedName, defaultName);
}
Also used : NewFeatureNameUtil(org.eclipse.xtext.xbase.ui.refactoring.NewFeatureNameUtil) TextSelection(org.eclipse.jface.text.TextSelection) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XExpression(org.eclipse.xtext.xbase.XExpression) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 2 with NewFeatureNameUtil

use of org.eclipse.xtext.xbase.ui.refactoring.NewFeatureNameUtil in project xtext-eclipse by eclipse.

the class NewFeatureNameUtilTest method assertInvalidName.

protected void assertInvalidName(final String name, final int severity, final String messageFragment) {
    final RefactoringStatus status = new RefactoringStatus();
    final NewFeatureNameUtil nameUtil = this.nameUtilProvider.get();
    nameUtil.checkNewFeatureName(name, false, status);
    Assert.assertEquals(severity, status.getSeverity());
    final String message = status.getEntryWithHighestSeverity().getMessage();
    Assert.assertTrue(message, message.contains(messageFragment));
}
Also used : NewFeatureNameUtil(org.eclipse.xtext.xbase.ui.refactoring.NewFeatureNameUtil) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Aggregations

NewFeatureNameUtil (org.eclipse.xtext.xbase.ui.refactoring.NewFeatureNameUtil)2 Resource (org.eclipse.emf.ecore.resource.Resource)1 TextSelection (org.eclipse.jface.text.TextSelection)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XExpression (org.eclipse.xtext.xbase.XExpression)1