org.eclipse.xtext.ui.editor.quickfix.IssueResolution Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.quickfix.IssueResolution. 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: QuickFixXpectMethod.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * CollectAll resolutions under the cursor at offset.
 *
 */
List<IssueResolution> collectAllResolutions(XtextResource resource, RegionWithCursor offset,
		Multimap<Integer, Issue> offset2issue) {

	EObject script = resource.getContents().get(0);
	ICompositeNode scriptNode = NodeModelUtils.getNode(script);
	ILeafNode offsetNode = NodeModelUtils.findLeafNodeAtOffset(scriptNode, offset.getGlobalCursorOffset());
	int offStartLine = offsetNode.getTotalStartLine();
	List<Issue> allIssues = QuickFixTestHelper.extractAllIssuesInLine(offStartLine, offset2issue);

	List<IssueResolution> resolutions = Lists.newArrayList();

	for (Issue issue : allIssues) {
		if (issue.getLineNumber() == offsetNode.getStartLine()
				&& issue.getLineNumber() <= offsetNode.getEndLine()) {

			IssueResolutionProvider quickfixProvider = resource.getResourceServiceProvider()
					.get(IssueResolutionProvider.class);
			Display.getDefault().syncExec(() -> resolutions.addAll(quickfixProvider.getResolutions(issue)));
		}
	}
	return resolutions;
}
 
Example #2
Source File: AbstractQuickFixTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Assert that application of the target quickfix was successful and the text of the resulting document equals the expected text.
 * The method ensures that there is one and only one quickfix for the given issue code with the given label.
 *
 * @param issueCode
 *          the code of the issue that should have been fixed, may be {@code null}
 * @param quickfixLabel
 *          the label of the quick fix that should be applied, may be {@code null}
 * @param expectedContent
 *          the name of the file containing the expected result after applying the quick fix
 * @param ignoreFormatting
 *          ignore formatting
 */
private void assertQuickFixExistsAndSuccessful(final String issueCode, final String quickfixLabel, final String expectedContent, final boolean ignoreFormatting) {
  // Assert amount of quickfixes
  int resolutionCount = resolutionsFor(issueCode, quickfixLabel).size();
  Assert.assertTrue(String.format("There must be exactly one quickfix with label '%s' for issue '%s', but found '%d'.", quickfixLabel, issueCode, resolutionCount), resolutionCount == 1);
  // Apply quickfix
  UiThreadDispatcher.dispatchAndWait(new Runnable() {
    @Override
    public void run() {
      List<IssueResolution> resolutions = resolutionsFor(issueCode, quickfixLabel);
      if (!resolutions.isEmpty()) {
        resolutions.get(0).apply();
      }
    }
  });
  waitForValidation();
  Assert.assertTrue(resolutionsFor(issueCode, quickfixLabel).isEmpty());
  String actualContent = getDocument().get();
  assertQuickFixProducesExpectedOutput(expectedContent, actualContent, ignoreFormatting);
}
 
Example #3
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<IssueResolution> getResolutions(Issue issue) {
	StopWatch stopWatch = new StopWatch(logger);
	try {
		if(LINKING_ISSUE_CODES.contains(issue.getCode())){
			List<IssueResolution> result = new ArrayList<IssueResolution>();
			result.addAll(getResolutionsForLinkingIssue(issue));
			if(!result.isEmpty())
				return result;
		}
		
		return super.getResolutions(issue);
	} finally {
		stopWatch.resetAndLog("#getResolutions");
	}
}
 
Example #4
Source File: QuickfixTestBuilder.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public QuickfixTestBuilder assertModelAfterQuickfix(final CharSequence expectedModel) {
  QuickfixTestBuilder _xblockexpression = null;
  {
    final Function1<Issue, List<IssueResolution>> _function = (Issue it) -> {
      return this._issueResolutionProvider.getResolutions(it);
    };
    final List<IssueResolution> resolutions = IterableExtensions.<IssueResolution>toList(Iterables.<IssueResolution>concat(IterableExtensions.<Issue, List<IssueResolution>>map(this.getIssuesAtCaret(), _function)));
    final String originalModel = this.editor.getDocument().get();
    final IssueResolution resolution = IterableExtensions.<IssueResolution>head(resolutions);
    Assert.assertNotNull(resolution);
    resolution.apply();
    Assert.assertEquals(expectedModel.toString(), this.editor.getDocument().get());
    this.editor.getDocument().set(originalModel);
    this._syncUtil.waitForReconciler(this.editor);
    _xblockexpression = this;
  }
  return _xblockexpression;
}
 
Example #5
Source File: AbstractQuickFixTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds all resolutions for issues with a specific issue code.
 *
 * @param issueCode
 *          to find resolutions for, may be {@code null}
 * @param quickfixLabel
 *          to find resolutions for, may be {@code null}
 * @return {@link List} of resolutions for issues with a specific code
 */
private List<IssueResolution> resolutionsFor(final String issueCode, final String quickfixLabel) {
  final List<IssueResolution> resolutions = new ArrayList<IssueResolution>();

  for (final Issue issue : issuesWith(issueCode)) {
    UiThreadDispatcher.dispatchAndWait(new Runnable() {
      @Override
      public void run() {
        if (quickfixLabel == null) {
          resolutions.addAll(getIssueResolutionProvider().getResolutions(issue));
        } else {
          for (IssueResolution r : getIssueResolutionProvider().getResolutions(issue)) {
            if (quickfixLabel.equals(r.getLabel())) {
              resolutions.add(r);
            }
          }
        }
      }
    });
  }

  return resolutions;
}
 
Example #6
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 #7
Source File: AbstractQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void assertIssueResolutionResult(String expectedResult, IssueResolution actualIssueResolution, String originalText) {
	/*
	 * Manually create an IModificationContext with an XtextDocument and call the
	 * apply method of the actualIssueResolution with that IModificationContext
	 */
	IXtextDocument document = getDocument(originalText);
	TestModificationContext modificationContext = new TestModificationContext();
	modificationContext.setDocument(document);

	new IssueResolution(actualIssueResolution.getLabel(), //
			actualIssueResolution.getDescription(), //
			actualIssueResolution.getImage(), //
			modificationContext, //
			actualIssueResolution.getModification(), //
			actualIssueResolution.getRelevance()).apply();
	String actualResult = document.get();
	assertEquals(expectedResult, actualResult);
}
 
Example #8
Source File: AbstractQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void quickfixesAreOffered(XtextEditor editor, String issueCode, Quickfix... expected) {
	List<Quickfix> expectedSorted = Arrays.asList(expected);
	expectedSorted.sort(Comparator.comparing(e -> e.getLabel()));

	IXtextDocument document = editor.getDocument();
	String originalText = document.get();
	Issue issue = getValidationIssue(document, issueCode);

	List<IssueResolution> actualIssueResolutions = issueResolutionProvider.getResolutions(issue);
	actualIssueResolutions.sort(Comparator.comparing(i -> i.getLabel()));
	assertEquals("The number of quickfixes does not match!", expectedSorted.size(), actualIssueResolutions.size());

	for (int i = 0; i < actualIssueResolutions.size(); i++) {
		IssueResolution actualIssueResolution = actualIssueResolutions.get(i);
		Quickfix expectedIssueResolution = expectedSorted.get(i);
		assertEquals(expectedIssueResolution.label, actualIssueResolution.getLabel());
		assertEquals(expectedIssueResolution.description, actualIssueResolution.getDescription());
		assertIssueResolutionResult(expectedIssueResolution.result, actualIssueResolution, originalText);
	}
}
 
Example #9
Source File: XtextGrammarQuickfixProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void assertAndApplySingleResolution(XtextEditor xtextEditor, String issueCode, int issueDataCount, String resolutionLabel,
		boolean isCleanAfterApply) {
	IXtextDocument document = xtextEditor.getDocument();
	List<Issue> issues = getIssues(document);
	assertFalse(issues.toString(), issues.isEmpty());
	Issue issue = issues.iterator().next();
	assertEquals(issueCode, issue.getCode());
	assertNotNull(issue.getData());
	assertEquals(issueDataCount, issue.getData().length);
	List<IssueResolution> resolutions = issueResolutionProvider.getResolutions(issue);

	assertEquals(1, resolutions.size());
	IssueResolution resolution = resolutions.iterator().next();
	assertEquals(resolutionLabel, resolution.getLabel());
	try {
		resolution.apply();
		assertEquals(getIssues(document).toString(), isCleanAfterApply, getIssues(document).isEmpty());
	} finally {
		// Save xtextEditor in any case. Otherwise test will stuck,
		// because the "save changed resource dialog" waits for user input.
		xtextEditor.doSave(new NullProgressMonitor());
	}
}
 
Example #10
Source File: LinkingErrorTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #11
Source File: LinkingErrorTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug361509() throws Exception {
	IFile dslFile = dslFile(MODEL_WITH_LINKING_ERROR_361509);
	XtextEditor xtextEditor = openEditor(dslFile);
	IXtextDocument document = xtextEditor.getDocument();

	List<Issue> issues = getAllValidationIssues(document);
	assertFalse(issues.isEmpty());
	Issue issue = issues.get(0);
	assertNotNull(issue);
	List<IssueResolution> resolutions = issueResolutionProvider.getResolutions(issue);

	assertEquals(1, resolutions.size());
	IssueResolution resolution = resolutions.get(0);
	assertEquals("Change to 'ref'", resolution.getLabel());
	resolution.apply();
	issues = getAllValidationIssues(document);
	assertTrue(issues.isEmpty());
	assertEquals(MODEL_WITH_LINKING_ERROR_361509.replace("raf", "^ref"), document.get());
}
 
Example #12
Source File: LinkingErrorTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testQuickfixTurnaround() throws Exception {
	IFile dslFile = dslFile(MODEL_WITH_LINKING_ERROR);
	XtextEditor xtextEditor = openEditor(dslFile);
	IXtextDocument document = xtextEditor.getDocument();

	List<Issue> issues = getAllValidationIssues(document);
	assertFalse(issues.isEmpty());
	Issue issue = issues.get(0);
	assertNotNull(issue);
	List<IssueResolution> resolutions = issueResolutionProvider.getResolutions(issue);

	assertEquals(1, resolutions.size());
	IssueResolution resolution = resolutions.get(0);
	assertEquals("Change to 'Bar'", resolution.getLabel());
	resolution.apply();
	issues = getAllValidationIssues(document);
	assertTrue(issues.isEmpty());
}
 
Example #13
Source File: N4JSMarkerResolutionGenerator.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IMarkerResolution[] getAdaptedResolutions(List<IssueResolution> resolutions) {
	// choose valid resolutions
	final List<IssueResolution> validResolutions = new ArrayList<>(resolutions.size());
	if (isMultiApplyAttempt()) {
		// only those that support multi-apply are valid
		for (IssueResolution currResolution : resolutions) {
			if (supportsMultiApply(currResolution))
				validResolutions.add(currResolution);
		}
		if (validResolutions.size() < resolutions.size())
			showError_MultiApplyNotSupported();
	} else {
		// all are valid
		validResolutions.addAll(resolutions);
	}
	// perform wrapping
	IMarkerResolution[] result = new IMarkerResolution[validResolutions.size()];
	for (int i = 0; i < validResolutions.size(); i++)
		result[i] = new MultiResolutionAdapter(validResolutions.get(i));
	return result;
}
 
Example #14
Source File: AbstractSARLQuickfixTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies the resolution that corresponds to the given label.
 *
 * @param label the label of the resolution to search for.
 * @param failIfNotFound fails if no resolution found.
 * @param removeWhenFound indicates if the resolution must be removed for the list of the resolutions
 * when it was found.
 * @return the resolution or {@code null}.
 */
public IssueResolution findResolution(String label, boolean failIfNotFound, boolean removeWhenFound) {
	Iterator<IssueResolution> iterator = this.resolutions.iterator();
	String close = null;
	int distance = Integer.MAX_VALUE;
	while (iterator.hasNext()) {
		IssueResolution resolution = iterator.next();
		String resolutionLabel = resolution.getLabel();
		int d = TextUtil.getLevenshteinDistance(resolutionLabel, label);
		if (d == 0) {
			if (removeWhenFound) {
				iterator.remove();
			}
			return resolution;
		} else if (close == null || d < distance) {
			distance = d;
			close = resolutionLabel;
		}
	}
	if (failIfNotFound) {
		throw new ComparisonFailure(
				"Quick fix not found for the issue '" + this.issueCode + "'.", //$NON-NLS-1$//$NON-NLS-2$
				label, close);
	}
	return null;
}
 
Example #15
Source File: QuickFixXpectMethod.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Example: {@code // XPECT quickFixList  at 'a.<|>method' --> 'import A','do other things' }
 *
 * @param expectation
 *            comma separated strings, which are proposed as quick fix
 * @param resource
 *            injected xtext-file
 * @param offset
 *            cursor position at '<|>'
 * @param checkType
 *            'display': verify list of provided proposals comparing their user-displayed strings.
 * @param selected
 *            which proposal to pick
 * @param mode
 *            modus of operation
 * @param offset2issue
 *            mapping of offset(!) to issues.
 * @throws Exception
 *             if failing
 */
@Xpect
@ParameterParser(syntax = "('at' (arg2=STRING (arg3=ID  (arg4=STRING)?  (arg5=ID)? )? )? )?")
@ConsumedIssues({ Severity.INFO, Severity.ERROR, Severity.WARNING })
public void quickFixList(
		@CommaSeparatedValuesExpectation(quoted = true, ordered = true) ICommaSeparatedValuesExpectation expectation, // arg0
		@ThisResource XtextResource resource, // arg1
		RegionWithCursor offset, // arg2
		String checkType, // arg3
		String selected, // arg4
		String mode, // arg5
		@IssuesByLine Multimap<Integer, Issue> offset2issue) throws Exception {

	List<IssueResolution> resolutions = collectAllResolutions(resource, offset, offset2issue);

	List<String> resolutionNames = Lists.newArrayList();
	for (IssueResolution resolution : resolutions) {
		resolutionNames.add(resolution.getLabel());
	}

	expectation.assertEquals(resolutionNames);
}
 
Example #16
Source File: WorkbenchMarkerResolutionGenerator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * If we have a Core resolution execute in current thread, otherwise run in UI thread.
 *
 * @param markerResolution
 *          the marker resolution to apply
 */
protected void applyResolution(final IMarkerResolution markerResolution) {
  final IssueResolution issueResolution = ((WorkbenchResolutionAdapter) markerResolution).getResolution();
  if (issueResolution instanceof IssueResolutionWrapper) {
    issueResolution.apply();
  } else {
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
      @Override
      public void run() {
        issueResolution.apply();
      }
    });
  }
}
 
Example #17
Source File: AbstractSARLQuickfixTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * @param issueCode
 * @param invalidCode
 * @param scriptResource
 * @param resolutions
 */
public QuickFixAsserts(
		String issueCode,
		String invalidCode,
		Resource scriptResource,
		Collection<IssueResolution> resolutions) {
	this.issueCode = issueCode;
	this.invalidCode = invalidCode;
	this.scriptResource = scriptResource;
	this.resolutions.addAll(resolutions);
}
 
Example #18
Source File: WorkbenchMarkerResolutionGenerator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * Note : this method is largely copied from the superclass, all we need to override is the call to
 * getAdaptedResolutions to provider the marker.
 */
@Override
public IMarkerResolution[] getResolutions(final IMarker marker) {
  final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
  try {
    if (!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION)) {
      return emptyResult;
    }
  } catch (CoreException e) {
    return emptyResult;
  }
  if (!languageResourceHelper.isLanguageResource(marker.getResource())) {
    return emptyResult;
  }

  final XtextEditor editor = getEditor(marker.getResource());
  if (editor != null) {
    final IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
    if (annotationModel != null && !isMarkerStillValid(marker, annotationModel)) {
      return emptyResult;
    }
  }

  final Iterable<IssueResolution> resolutions = getResolutionProvider().getResolutions(getIssueUtil().createIssue(marker));
  if (editor != null && editor.isEditorInputReadOnly()) {
    editor.close(false);
  }

  return getAdaptedResolutions(resolutions, marker);
}
 
Example #19
Source File: AbstractSARLQuickfixTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	StringBuilder buffer = new StringBuilder();
	for(IssueResolution resolution : this.resolutions) {
		if (buffer.length() > 0) {
			buffer.append(", "); //$NON-NLS-1$
		}
		buffer.append("\""); //$NON-NLS-1$
		buffer.append(Strings.convertToJavaString(resolution.getLabel()));
		buffer.append("\""); //$NON-NLS-1$
	}
	return "[ " + buffer.toString() + " ]"; //$NON-NLS-1$ //$NON-NLS-2$
}
 
Example #20
Source File: AbstractQuickFixTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Assert that application of the quick fixes for the given issueCode and label resolve the problem.
 *
 * @param issueCode
 *          the code of the issue that should have been fixed, may be {@code null}
 * @param quickfixLabel
 *          the label of the quickfix, may be {@code null}
 */
protected void assertQuickFixSuccessful(final String issueCode, final String quickfixLabel) {
  for (final IssueResolution issueResolution : sortResolutionsByOffsetDecreasing(resolutionsFor(issueCode, quickfixLabel))) {
    UiThreadDispatcher.dispatchAndWait(new Runnable() {
      @Override
      public void run() {
        issueResolution.apply();
      }
    });
  }
  waitForValidation();
  Assert.assertTrue(resolutionsFor(issueCode, quickfixLabel).isEmpty());
}
 
Example #21
Source File: WorkbenchResolutionAdaptorTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void findOtherMarkers() {
  IssueResolution mockIssueResolution = mock(IssueResolution.class);
  IMarker mockResolutionMarker = mock(IMarker.class);
  when(mockResolutionMarker.getAttribute(Issue.CODE_KEY, null)).thenReturn(CODE1);
  IMarker mockMarker1 = mock(IMarker.class);
  when(mockMarker1.getAttribute(Issue.CODE_KEY, null)).thenReturn(CODE1);
  IMarker mockMarker2 = mock(IMarker.class);
  when(mockMarker2.getAttribute(Issue.CODE_KEY, null)).thenReturn(CODE2);
  IMarker mockMarker3 = mock(IMarker.class);
  when(mockMarker3.getAttribute(Issue.CODE_KEY, null)).thenReturn(CODE1);

  IMarker[] allMarkers = new IMarker[] {mockMarker1, mockMarker2, mockMarker3};
  IMarker[] matchingMarkers = new IMarker[] {mockMarker1, mockMarker3};

  WorkbenchResolutionAdapter adapter = mockWmrg.new WorkbenchResolutionAdapter(mockIssueResolution, mockResolutionMarker);

  assertArrayEquals("Adapter findOtherMarkers matching on CODE1.", matchingMarkers, adapter.findOtherMarkers(allMarkers)); //$NON-NLS-1$

  when(mockResolutionMarker.getAttribute(Issue.CODE_KEY, null)).thenReturn(CODE2);
  matchingMarkers = new IMarker[] {mockMarker2};

  adapter = mockWmrg.new WorkbenchResolutionAdapter(mockIssueResolution, mockResolutionMarker);

  assertArrayEquals("Adapter findOtherMarkers matching on CODE2.", matchingMarkers, adapter.findOtherMarkers(allMarkers)); //$NON-NLS-1$

}
 
Example #22
Source File: WorkbenchResolutionAdaptorTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetDescription() {
  IssueResolution mockIssueResolution = mock(IssueResolution.class);
  IMarker mockMarker = mock(IMarker.class);

  when(mockIssueResolution.getDescription()).thenReturn(TEST_DESCRIPTION);

  WorkbenchResolutionAdapter adapter = mockWmrg.new WorkbenchResolutionAdapter(mockIssueResolution, mockMarker);

  assertEquals("Adapter delegates get description to resolution.", TEST_DESCRIPTION, adapter.getDescription()); //$NON-NLS-1$
}
 
Example #23
Source File: N4JSMarkerResolutionGenerator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private MultiResolutionAdapter(IssueResolution resolution) {
	if (!(resolution.getModificationContext() instanceof IssueModificationContext))
		throw new IllegalArgumentException(
				"the resolution's modification context must be an IssueModificationContext");
	this.issue = ((IssueModificationContext) resolution.getModificationContext()).getIssue();
	this.resolution = resolution;
}
 
Example #24
Source File: N4JSMarkerResolutionGenerator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
	if (existsDirtyEditorFor(marker)) {
		showError_UnsavedChanges();
		return new IMarkerResolution[0];
	}
	if (marker.getResource() instanceof IProject) {
		// This happens with IssueCodes.NODE_MODULES_OUT_OF_SYNC
		Issue issue = getIssueUtil().createIssue(marker);
		Iterable<IssueResolution> result = resolutionProvider.getResolutions(issue);
		return getAdaptedResolutions(Lists.newArrayList(result));
	}
	return super.getResolutions(marker);
}
 
Example #25
Source File: N4JSMarkerResolutionGenerator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns true iff the given resolution supports being applied to multiple issues / markers at once.
 */
private boolean supportsMultiApply(IssueResolution resolution) {
	// must be based on an N4Modification and #supportsMultiApply() returns true
	return resolution.getModification() instanceof N4ModificationWrapper
			&& ((N4ModificationWrapper) resolution.getModification()).getN4Modification() != null
			&& ((N4ModificationWrapper) resolution.getModification()).getN4Modification().supportsMultiApply();
}
 
Example #26
Source File: DotHtmlLabelQuickfixDelegator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private String getModifiedText(String originalText,
		IssueResolution issueResolution) {
	/*
	 * manually create an IModificationContext with an XtextDocument and
	 * call the apply method of the issueResolution with that
	 * IModificationContext
	 */
	IXtextDocument document = getDocument(originalText);
	IModificationContext modificationContext = new IModificationContext() {

		@Override
		public IXtextDocument getXtextDocument() {
			return document;
		}

		@Override
		public IXtextDocument getXtextDocument(URI uri) {
			return document;
		}
	};

	new IssueResolution(issueResolution.getLabel(),
			issueResolution.getDescription(), issueResolution.getImage(),
			modificationContext, issueResolution.getModification(),
			issueResolution.getRelevance()).apply();
	return document.get();
}
 
Example #27
Source File: WorkbenchResolutionAdaptorTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetLabel() {
  IssueResolution mockIssueResolution = mock(IssueResolution.class);
  IMarker mockMarker = mock(IMarker.class);

  when(mockIssueResolution.getLabel()).thenReturn(TEST_LABEL);

  WorkbenchResolutionAdapter adapter = mockWmrg.new WorkbenchResolutionAdapter(mockIssueResolution, mockMarker);

  assertEquals("Adapter delegates get label to resolution.", TEST_LABEL, adapter.getLabel()); //$NON-NLS-1$
}
 
Example #28
Source File: WorkbenchResolutionAdaptorTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetImage() {
  IssueResolution mockIssueResolution = mock(IssueResolution.class);
  IMarker mockMarker = mock(IMarker.class);

  when(mockWmrg.getImage(mockIssueResolution)).thenReturn(TEST_IMAGE);

  WorkbenchResolutionAdapter adapter = mockWmrg.new WorkbenchResolutionAdapter(mockIssueResolution, mockMarker);

  assertEquals("Adapter delegates get Image to resolution.", TEST_IMAGE, adapter.getImage()); //$NON-NLS-1$
}
 
Example #29
Source File: WorkbenchResolutionAdaptorRunTest.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
  wmrg.setIssueUtil(new IssueUtil());

  when(mockRegistryProvider.get()).thenReturn(mockMarkerHelpRegistry);

  mockIssueResolution = mock(IssueResolution.class);
  mockMarker = mock(IMarker.class);

  IMarkerResolution mockMarkerResolution = wmrg.new WorkbenchResolutionAdapter(mockIssueResolution, mockMarker);

  mockMarkerResolutions = new IMarkerResolution[] {mockMarkerResolution};

  mockFile = mock(IFile.class);

  when(mockIssueResolutionProvider.getResolutions(Matchers.any(Issue.class))).thenReturn(Lists.newArrayList(mockIssueResolution));
}
 
Example #30
Source File: DotHtmlLabelQuickfixDelegator.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
private List<IssueResolution> getResolutions(Issue issue) {
	IssueResolutionProvider quickfixProvider = injector
			.getInstance(IssueResolutionProvider.class);
	return quickfixProvider.getResolutions(issue);
}