org.eclipse.ui.IMarkerResolution Java Examples

The following examples show how to use org.eclipse.ui.IMarkerResolution. 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: BugResolutionAssociations.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
public IMarkerResolution[] createBugResolutions(String bugType, IMarker marker) {
    Assert.isNotNull(bugType);
    Assert.isNotNull(marker);
    List<QuickFixContribution> classes = quickFixes.get(bugType);
    if (classes == null) {
        return new IMarkerResolution[0];
    }

    Set<BugResolution> fixes = instantiateBugResolutions(classes);
    for (Iterator<BugResolution> iterator = fixes.iterator(); iterator.hasNext();) {
        BugResolution fix = iterator.next();
        if (fix.isApplicable(marker)) {
            fix.setMarker(marker);
        } else {
            iterator.remove();
        }
    }
    return fixes.toArray(new IMarkerResolution[fixes.size()]);
}
 
Example #2
Source File: CheckstyleMarkerResolutionGenerator.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {

  Collection<ICheckstyleMarkerResolution> fixes = new ArrayList<>();

  // get all fixes that apply to this marker instance
  String moduleName = marker.getAttribute(CheckstyleMarker.MODULE_NAME, null);

  RuleMetadata metadata = MetadataFactory.getRuleMetadata(moduleName);
  List<ICheckstyleMarkerResolution> potentialFixes = getInstantiatedQuickfixes(metadata);

  for (ICheckstyleMarkerResolution fix : potentialFixes) {

    if (fix.canFix(marker)) {
      fixes.add(fix);
    }
  }

  return fixes.toArray(new ICheckstyleMarkerResolution[fixes.size()]);
}
 
Example #3
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 #4
Source File: SpellingResolutionGenerator.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Generate resolutions for the given error marker.
 * Marker type must be SpellChecker.SPELLING_ERROR_MARKER_TYPE.
 * 
 * @param marker marker for the error
 * @return an array of resolutions for the given marker
 *         or null if an error occurs or the marker is of wrong type
 */
public IMarkerResolution[] getResolutions(IMarker marker) {
    
    try {
        if (!SpellChecker.SPELLING_ERROR_MARKER_TYPE.equals(marker.getType())) {
            return null;
        }
    } catch (CoreException e) {
        return null;
    }
    
    String[] proposals = SpellChecker.getProposals(marker);
    if (proposals == null || proposals.length == 0) {
        return null;
    }
    
    IDocument doc = getProviderDocument();
    
    IMarkerResolution[] res = new IMarkerResolution[proposals.length];
    for (int i = 0; i < res.length; i++) {
        res[i] = new SpellingMarkerResolution(proposals[i], doc);
    }
    return res;
}
 
Example #5
Source File: ConflictResolutionGenerator.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public IMarkerResolution[] getResolutions(IMarker marker) {
	List conflictResolutions = new ArrayList();
	try {
 	if (marker.getAttribute("textConflict") != null && marker.getAttribute("textConflict").toString().equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		conflictResolutions.add(new EditConflictsResolution());
 		conflictResolutions.add(new AcceptMineResolution());
 		conflictResolutions.add(new AcceptTheirsResolution());
 	}
	} catch (Exception e) {
		 SVNUIPlugin.log(e.getMessage());
	}
	conflictResolutions.add(new MarkAsResolvedResolution());
	IMarkerResolution[] resolutionArray = new IMarkerResolution[conflictResolutions.size()];
	conflictResolutions.toArray(resolutionArray);
    return resolutionArray;
}
 
Example #6
Source File: AppEngineWebMarkerResolutionGenerator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
  
  ArrayList<IMarkerResolution> resolutions = new ArrayList<>();
  try {
    if ("com.google.cloud.tools.eclipse.appengine.validation.applicationMarker"
        .equals(marker.getType())) {
      resolutions.add(new ApplicationQuickFix());
    } else if ("com.google.cloud.tools.eclipse.appengine.validation.versionMarker"
        .equals(marker.getType())) {
      resolutions.add(new VersionQuickFix());
    } else if ("com.google.cloud.tools.eclipse.appengine.validation.runtimeMarker"
        .equals(marker.getType())) {
      resolutions.add(new UpgradeRuntimeQuickFix());
    }
  } catch (CoreException ex) {
    logger.log(Level.SEVERE, ex.getMessage());
  }
  return resolutions.toArray(new IMarkerResolution[0]);
}
 
Example #7
Source File: AbstractMultiQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void applyQuickfixOnMultipleMarkers(IMarker[] markers) {
	IMarker primaryMarker = markers[0];
	IMarkerResolution[] resolutions = markerResolutionGenerator.getResolutions(primaryMarker);
	Assert.assertEquals(1, resolutions.length);
	assertTrue(resolutions[0] instanceof WorkbenchMarkerResolution);
	WorkbenchMarkerResolution resolution = (WorkbenchMarkerResolution) resolutions[0];
	List<IMarker> others = Lists.newArrayList(resolution.findOtherMarkers(markers));
	assertFalse(others.contains(primaryMarker));
	assertEquals(markers.length - 1, others.size());
	others.add(primaryMarker);
	long seed = new Random().nextLong();
	// System out is intended so that the seed used can be recovered on failures
	System.out.println(seed);
	Collections.shuffle(others, new Random(seed));
	resolution.run(others.toArray(new IMarker[others.size()]), new NullProgressMonitor());
}
 
Example #8
Source File: QuickfixMulti.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void applyMultiResolutionToAllMarkers(IMarker[] markers) {
    IMarkerResolution[] resolutions = getResolutionGenerator().getResolutions(markers[0]);
    if (resolutions[0] instanceof WorkbenchMarkerResolution) {
        //this represents one of the bugs a user would click on in the problems menu
        WorkbenchMarkerResolution resolutionFromProblemsMenu = ((WorkbenchMarkerResolution) resolutions[0]);

        //in theory, we should have filtered all the bugs of the passed in type
        //So, findOtherMarkers should return them all
        assertEquals(markers.length - 1, resolutionFromProblemsMenu.findOtherMarkers(markers).length);

        resolutionFromProblemsMenu.run(markers, null);
    } else {
        fail("Should have been a WorkBenchMarkerResolution: " + resolutions[0]);
    }

}
 
Example #9
Source File: ResolutionGenerator.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
public IMarkerResolution[] getResolutions(IMarker marker) {
	return new IMarkerResolution[] { 
			new SuppressProblemInLineResolution(),
			new SuppressProblemResolution(),
			new SuppressFileResolution(),
			new ReportBugResolution(),
			new CheckDescriptionResolution()
	};
}
 
Example #10
Source File: BugResolutionGenerator.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    String type = MarkerUtil.getBugPatternString(marker);
    if (type == null) {
        return null;
    }
    BugResolutionAssociations resolutions = getBugResolutions();
    if (resolutions == null) {
        return new IMarkerResolution[0];
    }
    return resolutions.createBugResolutions(type, marker);
}
 
Example #11
Source File: AbstractQuickfixTest.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void doTestQuickfixResolution(String classFileName, Class<? extends IMarkerResolution> resolutionClass, String... expectedPatterns)
        throws CoreException, IOException {
    QuickFixTestPackager packager = new QuickFixTestPackager();
    packager.addBugPatterns(expectedPatterns);

    doTestQuickfixResolution(classFileName, resolutionClass, packager.asList());
}
 
Example #12
Source File: CodewindMarkerResolutionGenerator.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
	CodewindApplication app = getApplication(marker);
	if (app == null) {
		return null;
	}
	
	String quickFixId = marker.getAttribute(CodewindEclipseApplication.QUICK_FIX_ID, (String)null);
	String quickFixDescription = marker.getAttribute(CodewindEclipseApplication.QUICK_FIX_DESCRIPTION, (String)null);
	IMarkerResolution resolution = new CodewindMarkerResolution(app, quickFixId, quickFixDescription);
	return new IMarkerResolution[] { resolution };
}
 
Example #13
Source File: AbstractQuickfixTest.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void applySingleResolutionForAllMarkers(IMarker[] markers) {
    for (int i = 0; i < markers.length; i++) {
        IMarkerResolution[] resolutions = getResolutionGenerator().getResolutions(markers[i]);
        assertEquals(1, resolutions.length);
        resolutions[0].run(markers[i]);
    }
}
 
Example #14
Source File: AbstractQuickfixTest.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void applySpecificResolutionForAllMarkers(IMarker[] markers, Class<? extends IMarkerResolution> resolutionClass) {
    for (int i = 0; i < markers.length; i++) {
        IMarkerResolution[] resolutions = getResolutionGenerator().getResolutions(markers[i]);
        for (int j = 0; j < resolutions.length; j++) {
            if (resolutionClass.isInstance(resolutions[j])) {
                resolutions[j].run(markers[i]);
                return;
            }
        }
    }
    Assert.fail("No resolution of class " + resolutionClass);
}
 
Example #15
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 #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: AbstractQuickfixTest.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void doTestQuickfixResolution(String classFileName, Class<? extends IMarkerResolution> resolutionClass,
        List<QuickFixTestPackage> packages) throws CoreException, IOException {
    // Run FindBugs on the input class
    work(createFindBugsWorker(), getInputResource(classFileName));

    // Assert the expected markers are present
    IMarker[] markers = getInputFileMarkers(classFileName);
    assertEquals("Too many or too few markers", packages.size(), markers.length);

    sortMarkers(markers);

    assertPresentBugPatterns(packages, markers);
    assertPresentLabels(packages, markers);
    assertPresentLineNumbers(packages, markers);

    // Assert all markers have resolution
    assertAllMarkersHaveResolutions(markers);

    // Apply resolution to each marker
    if (resolutionClass != null) {
        applySpecificResolutionForAllMarkers(markers, resolutionClass);
    } else {
        applySingleResolutionForAllMarkers(markers);
    }

    // Assert output file
    assertEqualFiles(getExpectedOutputFile(classFileName), getInputCompilationUnit(classFileName));
    assertEquals(0, getInputFileMarkers(classFileName).length);
}
 
Example #18
Source File: JavaMarkerResolutionGenerator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public IMarkerResolution[] getResolutions(IMarker marker) {
  if (!hasResolutions(marker)) {
    return NO_RESOLUTIONS;
  }

  ICompilationUnit cu = getCompilationUnit(marker);
  if (cu != null) {
    IEditorInput input = new FileEditorInput(
        (IFile) cu.getPrimary().getResource());
    if (input != null) {
      int offset = marker.getAttribute(IMarker.CHAR_START, -1);
      int length = marker.getAttribute(IMarker.CHAR_END, -1) - offset;
      int problemId = marker.getAttribute(IJavaModelMarker.ID, -1);
      boolean isError = (marker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR);
      String[] arguments = CorrectionEngine.getProblemArguments(marker);

      IProblemLocation location = new ProblemLocation(offset, length,
          problemId, arguments, isError, null);
      IInvocationContext context = new AssistContext(cu, offset, length);

      IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[0];

      try {
        proposals = getCorrections(context, new IProblemLocation[] {location});
      } catch (CoreException e) {
        CorePluginLog.logError(e);
      }

      int nProposals = proposals.length;
      IMarkerResolution[] resolutions = new IMarkerResolution[nProposals];
      for (int i = 0; i < nProposals; i++) {
        resolutions[i] = new QuickFixCompletionProposalWrapper(cu, offset,
            length, proposals[i]);
      }
      return resolutions;
    }
  }

  return NO_RESOLUTIONS;
}
 
Example #19
Source File: QuickFixer.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    if (isMissingObjectType(marker)) {
        return new IMarkerResolution[] { new FixMissingObjectType() };
    }
    return new IMarkerResolution[0];
}
 
Example #20
Source File: QuickFixes.java    From yang-design-studio with Eclipse Public License 1.0 5 votes vote down vote up
public IMarkerResolution[] getResolutions(IMarker mk) {
   try {
      Object problem = mk.getAttribute("WhatsUp");
      return new IMarkerResolution[] {
         new Quick("Fix #1 for "+problem),
         new Quick("Fix #2 for "+problem),
      };
   }
   catch (CoreException e) {
      return new IMarkerResolution[0];
   }
}
 
Example #21
Source File: JavaCorrectionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void collectMarkerProposals(SimpleMarkerAnnotation annotation, Collection<IJavaCompletionProposal> proposals) {
	IMarker marker= annotation.getMarker();
	IMarkerResolution[] res= IDE.getMarkerHelpRegistry().getResolutions(marker);
	if (res.length > 0) {
		for (int i= 0; i < res.length; i++) {
			proposals.add(new MarkerResolutionProposal(res[i], marker));
		}
	}
}
 
Example #22
Source File: CorrectionMarkerResolutionGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IMarkerResolution[] internalGetResolutions(IMarker marker) {
	if (!internalHasResolutions(marker)) {
		return NO_RESOLUTIONS;
	}

	ICompilationUnit cu= getCompilationUnit(marker);
	if (cu != null) {
		IEditorInput input= EditorUtility.getEditorInput(cu);
		if (input != null) {
			IProblemLocation location= findProblemLocation(input, marker);
			if (location != null) {

				IInvocationContext context= new AssistContext(cu,  location.getOffset(), location.getLength());
				if (!hasProblem (context.getASTRoot().getProblems(), location))
					return NO_RESOLUTIONS;

				ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>();
				JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals);
				Collections.sort(proposals, new CompletionProposalComparator());

				int nProposals= proposals.size();
				IMarkerResolution[] resolutions= new IMarkerResolution[nProposals];
				for (int i= 0; i < nProposals; i++) {
					resolutions[i]= new CorrectionMarkerResolution(context.getCompilationUnit(), location.getOffset(), location.getLength(), proposals.get(i), marker);
				}
				return resolutions;
			}
		}
	}
	return NO_RESOLUTIONS;
}
 
Example #23
Source File: PyQuickFix.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker mk) {
    return new IMarkerResolution[] {};
    //        try {
    //           Object problem = mk.getAttribute("WhatsUp");
    //           return new IMarkerResolution[] {
    //              new MarkerResolution("Fix #1 for "+problem),
    //              new MarkerResolution("Fix #2 for "+problem),
    //           };
    //        }
    //        catch (CoreException e) {
    //           return new IMarkerResolution[0];
    //        }
}
 
Example #24
Source File: SpellChecker.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the given marker resolutions to completion proposals.
 * 
 * @param resolutions marker resolutions
 * @param marker marker that holds the given resolutions
 * @return completion proposals for the given marker
 */
private static ICompletionProposal[] convertAll(IMarkerResolution[] resolutions, IMarker marker) {
    
    ICompletionProposal[] array = new ICompletionProposal[resolutions.length];
    
    for (int i = 0; i < resolutions.length; i++) {
        SpellingMarkerResolution smr = (SpellingMarkerResolution) resolutions[i];
        array[i] = new SpellingCompletionProposal(smr.getSolution(), marker);
    }
    
    return array;
}
 
Example #25
Source File: BaseTest.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void runQuickFix(IResource resource) throws Exception {
	IMarker[] markers = getMarkers(resource);
	assertTrue("There should be at least one marker for " + resource.getName() + ": " + markers.length, markers.length > 0);

    IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(markers[0]);
    assertTrue("Did not get any marker resolutions.", resolutions.length > 0);
    resolutions[0].run(markers[0]);
    TestUtil.waitForJobs(10, 1);
}
 
Example #26
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 #27
Source File: AppEngineWebMarkerResolutionGeneratorTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetResolutions_versionElement() throws CoreException {
  AppEngineWebMarkerResolutionGenerator resolution = new AppEngineWebMarkerResolutionGenerator();
  IMarker marker = Mockito.mock(IMarker.class);
  Mockito.when(marker.getType())
      .thenReturn("com.google.cloud.tools.eclipse.appengine.validation.versionMarker");
  IMarkerResolution[] resolutions = resolution.getResolutions(marker);
  assertEquals(1, resolutions.length);
  assertEquals(VersionQuickFix.class, resolutions[0].getClass());
}
 
Example #28
Source File: AppEngineWebMarkerResolutionGeneratorTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetResolutions_applicationElement() throws CoreException {
  AppEngineWebMarkerResolutionGenerator resolution = new AppEngineWebMarkerResolutionGenerator();
  IMarker marker = Mockito.mock(IMarker.class);
  Mockito.when(marker.getType())
      .thenReturn("com.google.cloud.tools.eclipse.appengine.validation.applicationMarker");
  IMarkerResolution[] resolutions = resolution.getResolutions(marker);
  assertEquals(1, resolutions.length);
  assertEquals(ApplicationQuickFix.class, resolutions[0].getClass());
}
 
Example #29
Source File: ServletMarkerResolutionGeneratorTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetResolutions() {
  ServletMarkerResolutionGenerator resolution = new ServletMarkerResolutionGenerator();
  IMarker marker = Mockito.mock(IMarker.class);
  IMarkerResolution[] resolutions = resolution.getResolutions(marker);
  assertEquals(1, resolutions.length);
  assertNotNull(resolutions[0]);
}
 
Example #30
Source File: ServletMarkerResolutionGenerator.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
  IMarkerResolution[] markerResolutions = new IMarkerResolution[1];
  IMarkerResolution fix = new ToServlet25QuickFix();
  markerResolutions[0] = fix;
  return markerResolutions;
}