Java Code Examples for org.eclipse.core.resources.IFile#findMarkers()

The following examples show how to use org.eclipse.core.resources.IFile#findMarkers() . These examples are extracted from open source projects. 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 Project: tlaplus   File: Model.java    License: MIT License 6 votes vote down vote up
private boolean isMarkerSet(String markerType, final String attributeName) {
	// marker
	final IFile resource = getFile();
	if (resource.exists()) {
		try {
			final IMarker[] foundMarkers = resource.findMarkers(markerType, false, IResource.DEPTH_ZERO);
			if (foundMarkers.length > 0) {
				boolean set = foundMarkers[0].getAttribute(attributeName, false);
				// remove trash if any
				for (int i = 1; i < foundMarkers.length; i++) {
					foundMarkers[i].delete();
				}
				return set;
			} else {
				return false;
			}
		} catch (CoreException shouldNotHappen) {
			TLCActivator.logError(shouldNotHappen.getMessage(), shouldNotHappen);
		}
	}
	return false;
}
 
Example 2
/**
 * Callback that'll check if there are error markers in the mod1.py resource
 */
private ICallback<Boolean, Object> getHasSyntaxErrorMarkersCondition(final IFile file) {
    return new ICallback<Boolean, Object>() {

        @Override
        public Boolean call(Object arg) {
            try {
                //must have only syntax error
                IMarker[] markers = file.findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO);
                if (markers.length > 0) {
                    //analysis error can be there or not
                    //                        markers = file.findMarkers(AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
                    //                        if(markers.length == 0){
                    return true;
                    //                        }
                }
                return false;
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
        }

    };
}
 
Example 3
@Test
public void testXsdValidation_appengineWebXml() throws CoreException {
  String xml = "<appengine-web-app xmlns='http://appengine.google.com/ns/1.0'>"
      + "<runtime>java8</runtime>"
      + "<foo></foo>"
      + "</appengine-web-app>";
  IProject project = appEngineStandardProjectCreator.getProject();
  IFile file = project.getFile("WebContent/WEB-INF/appengine-web.xml");
  file.setContents(
      new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)), true, false, null);
  ProjectUtils.waitForProjects(project);  // Wait until Eclipse puts an error marker.

  IMarker[] markers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
  ArrayAssertions.assertSize(1, markers);
  assertTrue(markers[0].getAttribute(IMarker.MESSAGE).toString().contains(
      "Invalid content was found starting with element 'foo'."));
}
 
Example 4
/**
 * Callback that'll check if there are error markers in the mod1.py resource
 */
private ICallback<Boolean, Object> getHasBothErrorMarkersCondition(final IFile file) {
    return new ICallback<Boolean, Object>() {

        @Override
        public Boolean call(Object arg) {
            try {
                //must have both problems: syntax and analysis error!!
                IMarker[] markers = file.findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO);
                if (markers.length > 0) {
                    markers = file.findMarkers(AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER, false,
                            IResource.DEPTH_ZERO);
                    if (markers.length > 0) {
                        return true;
                    }
                }
                return false;
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
        }

    };
}
 
Example 5
/**
 * Callback that'll check if there are NO error markers in the mod1.py resource
 */
private ICallback<Boolean, Object> getNoErrorMarkersCondition(final IFile file) {
    return new ICallback<Boolean, Object>() {

        @Override
        public Boolean call(Object arg) {
            try {
                IMarker[] markers = file.findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO);
                if (markers.length != 0) {
                    return false;
                }
                markers = file.findMarkers(AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER, false,
                        IResource.DEPTH_ZERO);
                if (markers.length != 0) {
                    return false;
                }
                return true;
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
        }

    };
}
 
Example 6
public void assertHasErrors(final IFile file, final String msgPart) {
  try {
    final IMarker[] findMarkers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    for (final IMarker iMarker : findMarkers) {
      {
        final String message = MarkerUtilities.getMessage(iMarker);
        if (((MarkerUtilities.getSeverity(iMarker) == IMarker.SEVERITY_ERROR) && message.contains(msgPart))) {
          return;
        }
      }
    }
    IPath _fullPath = file.getFullPath();
    String _plus = ((("Expected an error marker containing \'" + msgPart) + "\' on ") + _fullPath);
    String _plus_1 = (_plus + " but found ");
    final Function1<IMarker, String> _function = (IMarker it) -> {
      return MarkerUtilities.getMessage(it);
    };
    String _join = IterableExtensions.join(ListExtensions.<IMarker, String>map(((List<IMarker>)Conversions.doWrapArray(findMarkers)), _function), ",");
    String _plus_2 = (_plus_1 + _join);
    Assert.fail(_plus_2);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source Project: tlaplus   File: Model.java    License: MIT License 6 votes vote down vote up
private void setMarker(final String markerType, final String attributeName, boolean value) {
	final IFile resource = getFile();
	if (resource.exists()) {
		try {
			IMarker marker;
			final IMarker[] foundMarkers = resource.findMarkers(markerType, false, IResource.DEPTH_ZERO);
			if (foundMarkers.length > 0) {
				marker = foundMarkers[0];
				// remove trash if any
				for (int i = 1; i < foundMarkers.length; i++) {
					foundMarkers[i].delete();
				}
			} else {
				marker = resource.createMarker(markerType);
			}

			marker.setAttribute(attributeName, value);
		} catch (CoreException shouldNotHappen) {
			TLCActivator.logError(shouldNotHappen.getMessage(), shouldNotHappen);
		}
	}
}
 
Example 8
Source Project: Pydev   File: TddTestWorkbench.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Callback that'll check if there are error markers in the mod1.py resource
 */
private ICallback<Boolean, Object> getHasBothErrorMarkersCondition(final IFile file) {
    return new ICallback<Boolean, Object>() {

        @Override
        public Boolean call(Object arg) {
            try {
                //must have both problems: syntax and analysis error!!
                IMarker[] markers = file.findMarkers(AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER, false,
                        IResource.DEPTH_ZERO);
                return markers.length > 0;
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
 
Example 9
Source Project: tlaplus   File: Model.java    License: MIT License 6 votes vote down vote up
/**
 * Looks up if the model has a stale marker. The stale marker is installed
 * when the TLC process crashed (terminated with exit code > 0).
 */
public boolean isStale() {
       final IFile resource = getFile();
	if (resource.exists()) {
		IMarker[] foundMarkers;
		try {
			foundMarkers = resource.findMarkers(TLC_CRASHED_MARKER, false, IResource.DEPTH_ZERO);
			if (foundMarkers.length > 0) {
				return true;
			} else {
				return false;
			}
		} catch (CoreException shouldNotHappen) {
			TLCActivator.logError(shouldNotHappen.getMessage(), shouldNotHappen);
		}
	}
	return false;
}
 
Example 10
public void assertErrorMarker(IFile file, String issueCode, int expectedIssuesCount) throws CoreException {
	IMarker[] findMarkers = file.findMarkers(null, true, IResource.DEPTH_INFINITE);
	int matchingIssuesFound = 0;
	List<String> allCodes = new ArrayList<String>();
	for (IMarker iMarker : findMarkers) {
		String code = issueUtil.getCode(iMarker);
		if (code != null) {
			allCodes.add(code);
			if (issueCode.equals(code)) {
				matchingIssuesFound++;
			}
		}
	}
	String message = "Expected error marker not found: '" + issueCode
			+ (allCodes.isEmpty() ? "'" : "' but found '" + Strings.concat(",", allCodes) + "'");
	assertTrue(message, matchingIssuesFound > 0);
	assertEquals("Expected error marker count for '" + issueCode + "'", expectedIssuesCount, matchingIssuesFound);
}
 
Example 11
private static boolean containsRelevantMarkers(IFile file) throws CoreException {
	IMarker[] bookmarks= file.findMarkers(IMarker.BOOKMARK, true, IResource.DEPTH_INFINITE);
	if (bookmarks.length != 0)
		return true;

	IMarker[] tasks= file.findMarkers(IMarker.TASK, true, IResource.DEPTH_INFINITE);
	if (tasks.length != 0)
		return true;

	IMarker[] breakpoints= file.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
	if (breakpoints.length != 0)
		return true;

	return false;
}
 
Example 12
@Test
public void testValidate_withProblemElements() throws IOException, CoreException {
  XmlValidator validator = new XmlValidator();
  validator.setHelper(new AppEngineWebXmlValidator());

  IFile file = createBogusProjectFile();
  byte[] bytes = XML.getBytes(StandardCharsets.UTF_8);
  validator.validate(file, bytes);

  IMarker[] markers = file.findMarkers(APPLICATION_MARKER, true, IResource.DEPTH_ZERO);
  ArrayAssertions.assertSize(1, markers);
  String message = Messages.getString("application.element");
  assertEquals(message, markers[0].getAttribute(IMarker.MESSAGE));
  assertEquals("line 1", markers[0].getAttribute(IMarker.LOCATION));
}
 
Example 13
Source Project: tlaplus   File: Model.java    License: MIT License 5 votes vote down vote up
public IMarker[] getMarkers() {
	final IFile resource = getFile();
	if (resource.exists()) {
		try {
			return resource.findMarkers(TLC_MODEL_ERROR_MARKER, true, IResource.DEPTH_ZERO);
		} catch (CoreException shouldNotHappen) {
			TLCActivator.logError(shouldNotHappen.getMessage(), shouldNotHappen);
		}
	}
	return new IMarker[0];
}
 
Example 14
private Set<IMarker> findJavaProblemMarker(IFile javaFile, int maxSeverity) throws CoreException {
	Set<IMarker> problems = newHashSet();
	for (IMarker marker : javaFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
			IResource.DEPTH_ZERO)) {
		if (MarkerUtilities.getSeverity(marker) >= maxSeverity) {
			problems.add(marker);
		}
	}
	return problems;
}
 
Example 15
@Test
public void testXtendAndJavaDifferentProject() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package acme;");
    _builder.newLine();
    _builder.append("public class A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    IResourcesSetupUtil.createFile("first.p384008/src/acme/A.java", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package acme");
    _builder_1.newLine();
    _builder_1.append("class A {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final IFile secondFile = IResourcesSetupUtil.createFile("second.p384008/src/acme/B.xtend", _builder_1.toString());
    final IWorkspaceRunnable _function = (IProgressMonitor it) -> {
      this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
      this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    };
    this.runInWorkspace(_function);
    final IMarker[] secondFileMarkers = secondFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    Assert.assertEquals(IResourcesSetupUtil.printMarker(secondFileMarkers), 0, secondFileMarkers.length);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 16
protected IMarker[] getMarkers(IFile file) {
	IResourcesSetupUtil.waitForBuild();
	try {
		return file.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_INFINITE);
	} catch (CoreException e) {
		Exceptions.sneakyThrow(e);
		return null;
	}
}
 
Example 17
@Ignore("Since the name acme.A is considered to be derived, it is filtered from the Java delta")
@Test
public void testXtendAndJavaSameProjectXtendFirst() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package acme");
    _builder.newLine();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IFile firstFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/B.xtend", _builder.toString());
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package acme;");
    _builder_1.newLine();
    _builder_1.append("class A2 {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final IFile javaFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/A.java", _builder_1.toString());
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    StringInputStream _stringInputStream = new StringInputStream("package acme; class A{}");
    javaFile.setContents(_stringInputStream, false, false, null);
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    final IMarker[] markers = firstFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    Assert.assertEquals(IResourcesSetupUtil.printMarker(markers), 1, markers.length);
    Assert.assertEquals("The type A is already defined in A.java.", IterableExtensions.<IMarker>head(((Iterable<IMarker>)Conversions.doWrapArray(markers))).getAttribute(IMarker.MESSAGE));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 18
Source Project: n4js   File: BuilderUtil.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/***/
public static void assertNumberOfMarkers(IFile file, int numberOfMarkers) throws CoreException {
	IMarker[] markers = file.findMarkers(EValidator.MARKER, true, 1);
	assertEquals(printMarker(markers), numberOfMarkers, markers.length);
}
 
Example 19
protected int countMarkers(IFile file) throws CoreException {
	return file.findMarkers(EValidator.MARKER, true, IResource.DEPTH_INFINITE).length;
}
 
Example 20
private int countMarkers(IFile file) throws CoreException {
	return file.findMarkers(EValidator.MARKER, true, IResource.DEPTH_INFINITE).length;
}