Java Code Examples for org.eclipse.xtext.validation.IResourceValidator#validate()
The following examples show how to use
org.eclipse.xtext.validation.IResourceValidator#validate() .
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: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug345433_02() throws Exception { String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + " org.eclipse.xtext.Grammar grammar\n" + " def function1() {\n" + " grammar.containedRuleCalls.filter(e0 | " + " !e0.isAssigned() && !e0.isEObjectRuleCall()" + " ).map(e1 | e1.rule)\n" + " }\n" + "}"; XtendClass clazz = clazz(classAsString); IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator(); List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl); assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty()); XtendFunction function = (XtendFunction) clazz.getMembers().get(1); XExpression body = function.getExpression(); LightweightTypeReference bodyType = getType(body); assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier()); XBlockExpression block = (XBlockExpression) body; XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0); XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0); JvmFormalParameter e1 = closure.getFormalParameters().get(0); assertEquals("e1", e1.getSimpleName()); assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier()); }
Example 2
Source File: ValidMarkerUpdateJob.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * 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); } }
Example 3
Source File: ComparisonExpressionValidator.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
public IStatus validateXtextResource(final Injector injector, Resource resource, ResourceSet resourceSet) throws OperationCanceledError { final IResourceValidator xtextResourceChecker = injector.getInstance(IResourceValidator.class); final MultiStatus status = new MultiStatus(ExpressionEditorPlugin.PLUGIN_ID, 0, "", null); final ConditionModelJavaValidator validator = injector.getInstance(ConditionModelJavaValidator.class); validator.setCurrentResourceSet(resourceSet); final List<Issue> issues = xtextResourceChecker.validate(resource, CheckMode.FAST_ONLY, null); if(issues.isEmpty()){ updateDependencies(resource); } for(final Issue issue : issues){ int severity = IStatus.ERROR; final Severity issueSeverity = issue.getSeverity(); if(issueSeverity == Severity.WARNING){ severity = IStatus.WARNING; } status.add(new Status(severity, ExpressionEditorPlugin.PLUGIN_ID, issue.getMessage())); } return status; }
Example 4
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example 5
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 6
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 7
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 8
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 9
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 10
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 11
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 12
Source File: XtextValidationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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()); }
Example 13
Source File: IncrementalBuilder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Validate the resource and return true, if the build should proceed for the current state. */ protected boolean validate(Resource resource) { IResourceValidator resourceValidator = getResourceServiceProvider(resource).getResourceValidator(); if (resourceValidator == null) { return true; } List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, request.getCancelIndicator()); return request.getAfterValidate().afterValidate(resource.getURI(), validationResult); }
Example 14
Source File: XtendBatchCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected List<Issue> validate(ResourceSet resourceSet) { List<Issue> issues = Lists.newArrayList(); List<Resource> resources = Lists.newArrayList(resourceSet.getResources()); for (Resource resource : resources) { IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE .getResourceServiceProvider(resource.getURI()); if (resourceServiceProvider != null && isSourceFile(resource)) { IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator(); List<Issue> result = resourceValidator.validate(resource, CheckMode.ALL, null); addAll(issues, result); } } return issues; }
Example 15
Source File: OpenFileContext.java From n4js with Eclipse Public License 1.0 | 5 votes |
public List<Issue> validateOpenFile(CancelIndicator cancelIndicator) { // validate IResourceServiceProvider resourceServiceProvider = languagesRegistry.getResourceServiceProvider(mainURI); IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator(); List<Issue> issues = resourceValidator.validate(mainResource, CheckMode.ALL, cancelIndicator); operationCanceledManager.checkCanceled(cancelIndicator); // #validate() sometimes returns null when canceled! // notify LSP client publishIssues(issues, cancelIndicator); return issues; }
Example 16
Source File: XStatefulIncrementalBuilder.java From n4js with Eclipse Public License 1.0 | 5 votes |
private Delta buildClustured(Resource resource, XSource2GeneratedMapping newSource2GeneratedMapping, XIndexer.XIndexResult result) { CancelIndicator cancelIndicator = request.getCancelIndicator(); operationCanceledManager.checkCanceled(cancelIndicator); // trigger init resource.getContents(); EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl); operationCanceledManager.checkCanceled(cancelIndicator); URI source = resource.getURI(); IResourceServiceProvider serviceProvider = getResourceServiceProvider(resource); IResourceDescription.Manager manager = serviceProvider.getResourceDescriptionManager(); IResourceValidator resourceValidator = serviceProvider.getResourceValidator(); IResourceDescription description = manager.getResourceDescription(resource); SerializableResourceDescription copiedDescription = SerializableResourceDescription.createCopy(description); result.getNewIndex().addDescription(source, copiedDescription); operationCanceledManager.checkCanceled(cancelIndicator); if (request.canValidate()) { List<Issue> issues = resourceValidator.validate(resource, CheckMode.ALL, cancelIndicator); List<LSPIssue> lspIssues = lspIssueConverter.convertToLSPIssues(resource, issues, cancelIndicator); operationCanceledManager.checkCanceled(cancelIndicator); request.setResultIssues(request.getProjectName(), source, lspIssues); boolean proceedGenerate = !request.containsValidationErrors(source); if (proceedGenerate) { operationCanceledManager.checkCanceled(cancelIndicator); generate(resource, newSource2GeneratedMapping, serviceProvider); } else { removeGeneratedFiles(resource.getURI(), newSource2GeneratedMapping); } } IResourceDescription old = context.getOldState().getResourceDescriptions().getResourceDescription(source); return manager.createDelta(old, copiedDescription); }
Example 17
Source File: ScriptEngineImpl.java From smarthome with Eclipse Public License 2.0 | 4 votes |
protected List<Issue> validate(EObject model) { IResourceValidator validator = ((XtextResource) model.eResource()).getResourceServiceProvider() .getResourceValidator(); return validator.validate(model.eResource(), CheckMode.ALL, CancelIndicator.NullImpl); }
Example 18
Source File: ValidationTestHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.8 */ public List<Issue> validate(Resource resource) { IResourceValidator validator = ((XtextResource) resource).getResourceServiceProvider() .getResourceValidator(); return validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl); }
Example 19
Source File: StandaloneBuilder.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected boolean validate(Resource resource) { LOG.info("Starting validation for input: '" + resource.getURI().lastSegment() + "'"); IResourceValidator resourceValidator = languageAccess(resource.getURI()).getResourceValidator(); List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, null); return issueHandler.handleIssue(validationResult); }
Example 20
Source File: ScriptEngineImpl.java From openhab-core with Eclipse Public License 2.0 | 4 votes |
protected List<Issue> validate(EObject model) { IResourceValidator validator = ((XtextResource) model.eResource()).getResourceServiceProvider() .getResourceValidator(); return validator.validate(model.eResource(), CheckMode.ALL, CancelIndicator.NullImpl); }