当前位置: 首页>>代码示例>>Java>>正文


Java IResourceValidator.validate方法代码示例

本文整理汇总了Java中org.eclipse.xtext.validation.IResourceValidator.validate方法的典型用法代码示例。如果您正苦于以下问题:Java IResourceValidator.validate方法的具体用法?Java IResourceValidator.validate怎么用?Java IResourceValidator.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.validation.IResourceValidator的用法示例。


在下文中一共展示了IResourceValidator.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRuleCalledSuper

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testRuleCalledSuper() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: super=super;\n" + 
			"super: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("Discouraged rule name 'super'", issues.get(0).getMessage());
	Grammar grammar = (Grammar) resource.getContents().get(0);
	AbstractRule model = grammar.getRules().get(0);
	Assignment assignment = (Assignment) model.getAlternatives();
	RuleCall ruleCall = (RuleCall) assignment.getTerminal();
	assertSame(grammar.getRules().get(1), ruleCall.getRule());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:XtextValidationTest.java

示例2: validate

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
/**
 * Validate the given resource and create the corresponding markers. The CheckMode is a constant calculated from the constructor
 * parameters.
 *
 * @param resourceValidator
 *          the resource validator (not null)
 * @param file
 *          the EFS file (not null)
 * @param resource
 *          the EMF resource (not null)
 * @param monitor
 *          the monitor (not null)
 */
protected void validate(final IResourceValidator resourceValidator, final IFile file, final Resource resource, final IProgressMonitor monitor) {
  try {
    monitor.subTask("validating " + file.getName()); //$NON-NLS-1$

    final List<Issue> list = resourceValidator.validate(resource, checkMode, getCancelIndicator(monitor));
    if (list != null) {
      // resourceValidator.validate returns null if canceled (and not an empty list)
      file.deleteMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
      file.deleteMarkers(MarkerTypes.NORMAL_VALIDATION, true, IResource.DEPTH_ZERO);
      if (performExpensiveValidation) {
        file.deleteMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO);
      }
      for (final Issue issue : list) {
        markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
      }
    }
  } catch (final CoreException e) {
    LOGGER.error(e.getMessage(), e);
  } finally {
    monitor.worked(1);
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:36,代码来源:ValidMarkerUpdateJob.java

示例3: validateProject

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
/**
 * Validates all non-external Xtext resources of the given project. Prints issues and adds them to the given issue
 * acceptor.
 *
 * @param markedProject
 *            the project to validate
 * @param recorder
 *            the progress recorder
 * @param issueAcceptor
 *            the issue acceptor
 * @throws N4JSCompileErrorException
 *             if an error occurs during validation
 */
private void validateProject(MarkedProject markedProject, N4ProgressStateRecorder recorder,
		IssueAcceptor issueAcceptor) throws N4JSCompileErrorException {

	if (logger.isVerbose())
		logger.info(" Validating project " + markedProject);
	IssueCollector issueCollector = new IssueCollector();
	IssueFilter issueFilter = new IssueFilter(issueCollector, issue -> issue.getSeverity() == Severity.ERROR);
	issueAcceptor = new IssueAcceptorTee(issueAcceptor, issueFilter);

	// validation TODO see IDE-1426 redesign validation calls with generators
	for (Resource resource : markedProject.resources) {
		if (resource instanceof XtextResource && // is Xtext resource
				(!n4jsCore.isNoValidate(resource.getURI())) && // is validating
				(!markedProject.externalResources.contains(resource)) // not in external folder
		) {
			if (logger.isCreateDebugOutput())
				logger.debug("   Validating resource " + resource.getURI());
			XtextResource xtextResource = (XtextResource) resource;
			IResourceValidator validator = xtextResource.getResourceServiceProvider().getResourceValidator();
			List<Issue> issues = validator.validate(xtextResource, CheckMode.ALL, CancelIndicator.NullImpl);

			if (!issues.isEmpty()) {
				recorder.markResourceIssues(resource, issues);
				issueAcceptor.acceptAll(issues);
				issues.stream().forEach(logger::issue);
			}
		}
	}

	// Projects should not compile if there are severe errors:
	if (!isKeepOnCompiling()) {
		failOnErrors(issueCollector.getCollectedIssues(), markedProject.project.getProjectId());
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:48,代码来源:N4HeadlessCompiler.java

示例4: validate

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
protected boolean validate(final Resource resource) {
  String _lastSegment = resource.getURI().lastSegment();
  String _plus = ("Starting validation for input: \'" + _lastSegment);
  String _plus_1 = (_plus + "\'");
  StandaloneBuilder.LOG.info(_plus_1);
  final IResourceValidator resourceValidator = this.languageAccess(resource.getURI()).getResourceValidator();
  final List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, null);
  return this.issueHandler.handleIssue(validationResult);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:10,代码来源:StandaloneBuilder.java

示例5: validate

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
protected boolean validate(final Resource resource) {
  final IResourceValidator resourceValidator = this.context.getResourceServiceProvider(resource.getURI()).getResourceValidator();
  if ((resourceValidator == null)) {
    return true;
  }
  String _lastSegment = resource.getURI().lastSegment();
  String _plus = ("Starting validation for input: \'" + _lastSegment);
  String _plus_1 = (_plus + "\'");
  IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.info(_plus_1);
  final List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, null);
  return this.request.getAfterValidate().afterValidate(resource.getURI(), validationResult);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:IncrementalBuilder.java

示例6: testExplicitOverride01

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testExplicitOverride01() throws Exception {
	IResourceValidator validator = get(IResourceValidator.class);
	
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"terminal ID_2: ('a'..'z'|'A'..'Z'|'_');");
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 0, issues.size());
	
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:11,代码来源:XtextValidationTest.java

示例7: testExplicitOverride04

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testExplicitOverride04() throws Exception {
	IResourceValidator validator = get(IResourceValidator.class);
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"@Override\n" +
			"terminal ID: ('a'..'z'|'A'..'Z'|'_');");
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 0, issues.size());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:XtextValidationTest.java

示例8: testMissingArgument

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testMissingArgument() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<First=true, Second=false>;\n" + 
			"Rule<First, Missing, Second>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("Missing argument for parameter Missing", issues.get(0).getMessage());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:XtextValidationTest.java

示例9: testMissingArgument2

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testMissingArgument2() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<First=true>;\n" + 
			"Rule<First, Missing, AlsoMissing>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("2 missing arguments for the following parameters: Missing, AlsoMissing", issues.get(0).getMessage());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:XtextValidationTest.java

示例10: testMissingArgument3

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testMissingArgument3() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<true>;\n" + 
			"Rule<First, Missing, AlsoMissing>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("Expected 3 arguments but got 1", issues.get(0).getMessage());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:XtextValidationTest.java

示例11: testOutOfSequenceArgument_01

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testOutOfSequenceArgument_01() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<true, C=false, B=true>;\n" + 
			"Rule<A, B, C>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 2, issues.size());
	assertEquals("Out of sequence named argument. Expected value for B", issues.get(0).getMessage());
	assertEquals("Out of sequence named argument. Expected value for C", issues.get(1).getMessage());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:XtextValidationTest.java

示例12: testOutOfSequenceArgument_02

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testOutOfSequenceArgument_02() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<true, B=false, C=true>;\n" + 
			"Rule<A, B, C>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 0, issues.size());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:XtextValidationTest.java

示例13: testOutOfSequenceArgument_03

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testOutOfSequenceArgument_03() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<A=true, C=false, B=true>;\n" + 
			"Rule<A, B, C>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 0, issues.size());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:XtextValidationTest.java

示例14: testDuplicateArgument

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testDuplicateArgument() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<Single=true, Single=false>;\n" + 
			"Rule<Single>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("Duplicate value for parameter Single", issues.get(0).getMessage());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:XtextValidationTest.java

示例15: testSupressedWarning_01

import org.eclipse.xtext.validation.IResourceValidator; //导入方法依赖的package包/类
@Test public void testSupressedWarning_01() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			 
			"Model: child=Child;\n" + 
			"/* SuppressWarnings[noInstantiation] */\n" +
			"Child: name=ID?;");
	assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
	assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertTrue(issues.toString(), issues.isEmpty());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:16,代码来源:XtextValidationTest.java


注:本文中的org.eclipse.xtext.validation.IResourceValidator.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。