Java Code Examples for org.eclipse.emf.mwe.core.issues.Issues#addError()

The following examples show how to use org.eclipse.emf.mwe.core.issues.Issues#addError() . 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: LanguageConfig.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	super.checkConfiguration(issues);
	if (isCheckFileExtension()) {
		for (String extension : fileExtensions) {
			char[] charArray = extension.toCharArray();
			if (!Character.isJavaIdentifierPart(charArray[0])) {
				issues.addError("file extension '"+extension+"' starts with a non identifier letter : '"+charArray[0]+"'", this);
			}
			for (int i = 1; i < charArray.length; i++) {
				char c = charArray[i];
				if (!Character.isJavaIdentifierPart(c)) {
					issues.addError("file extension '"+extension+"' contains non identifier letter : '"+c+"'", this);
				}
			}
		}
	}
	if (getGrammar() == null) {
		issues.addError("property 'uri' is mandatory for element 'language'.", this);
	}
}
 
Example 2
Source File: ValidatorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=322645
 */
@Test public void testBugFix322645() throws Exception {
	Issues issues = issues();
	Issue a = new Issue.IssueImpl();
	Issue b = new Issue.IssueImpl();
	issues.addError("foo", a);
	issues.addWarning(null, a);
	issues.addError(null, b);
	MWEDiagnostic[] errors = issues.getErrors();
	assertEquals(2, errors.length);
	final Validator validator = new Validator();
	final String string = validator.toString(issues);
	assert(string.contains("foo"));
}
 
Example 3
Source File: XcoreReader.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
		Issues issues) {
	ResourceSet resourceSet = getResourceSet();

	// due to some Xcore peculiarity we have to access the IAllContainerState here
	// to trigger some lazy init logic
	IAllContainersState allContainerState = (IAllContainersState) EcoreUtil.getAdapter(resourceSet.eAdapters(),
			IAllContainersState.class);
	allContainerState.isEmpty("");

	Multimap<String, URI> uris = getPathTraverser().resolvePathes(pathes,
			new Predicate<URI>() {
		@Override
		public boolean apply(URI input) {
			return input.fileExtension().equals(XCORE_FILE_EXT);
		}
	});
	List<Resource> resources = new ArrayList<>();
	for (URI uri : uris.values()) {
		LOGGER.info(uri);
		try {
			resources.add(parse(uri, resourceSet));
		} catch (Exception e) {
			LOGGER.error("Problem during loading of resource @ " + uri, e);
		}
	}
	installIndex(resourceSet);
	for (Resource r : resources) {
		EcoreUtil.resolveAll(r);
		for (Diagnostic x : r.getErrors()) {
			issues.addError(x.getMessage(), x);
		}

	}
	ctx.set(slot, resources);
}
 
Example 4
Source File: XtextGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void handleException(final Exception ex, final Issues issues) {
  if ((ex instanceof CompositeGeneratorException)) {
    final Consumer<Exception> _function = (Exception it) -> {
      this.handleException(it, issues);
    };
    ((CompositeGeneratorException)ex).getExceptions().forEach(_function);
  } else {
    issues.addError(this, "GeneratorException: ", null, ex, null);
  }
}
 
Example 5
Source File: AbstractReader.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void checkConfigurationInternal(Issues issues) {
	super.checkConfigurationInternal(issues);
	if (injectors.isEmpty())
		issues.addError(this,"No setup has been registered (example: register=foo.bar.MyLanguageStandaloneSetup{})");
	if (slotEntries.isEmpty()) {
		issues.addError(this,"No slot entries configured (example: load={slot='mySlot' type='Type'}).");
	}
}
 
Example 6
Source File: UriBasedReader.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void checkConfigurationInternal(Issues issues) {
	super.checkConfigurationInternal(issues);
	if (uris.isEmpty())
		issues.addError(this, "No resource uri configured (property 'uri')");
	for (String uri : uris) {
		try {
			uris2.add(URI.createURI(uri));
		} catch (Exception e) {
			issues.addError(this, "Invalid URI '" + uri + "' (" + e.getMessage() + ")");
		}
	}
}
 
Example 7
Source File: Validator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void validate(ResourceSet resourceSet, IResourceServiceProvider.Registry registry, Issues issues) {
	List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
	for (Resource resource : resources) {
		try {
			resource.load(null);
			IResourceServiceProvider provider = registry.getResourceServiceProvider(resource.getURI());
			if (provider != null) {
				List<Issue> result = provider.getResourceValidator().validate(resource, CheckMode.ALL, null);
				for (Issue issue : result) {
					switch (issue.getSeverity()) {
						case ERROR:
							issues.addError(issue.getMessage(), issue);
							break;
						case WARNING:
							issues.addWarning(issue.getMessage(), issue);
							break;
						case INFO:
							issues.addInfo(issue.getMessage(), issue);
							break;
						case IGNORE:
							break;
					}
				}
			}
		} catch (IOException e) {
			throw new WorkflowInterruptedException("Couldn't load resource (" + resource.getURI() + ")", e);
		}
	}
	if (isStopOnError() && issues.hasErrors()) {
		String errorMessage = toString(issues);
		throw new WorkflowInterruptedException("Validation problems: \n" + errorMessage);
	}
}
 
Example 8
Source File: Ecore2XtextGenerator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void checkConfigurationInternal(Issues issues) {
	if (genPath == null) {
		issues.addError("genPath not set");
	}
	if (rootElementClassName == null) {
		issues.addError("rootElement not set");
	}
	if (!issues.hasErrors()) {
		createXtextProjectInfo(issues);
	}
}
 
Example 9
Source File: Ecore2XtextGenerator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void invokeInternal(final WorkflowContext ctx, ProgressMonitor monitor, final Issues issues) {
	createXtextProjectInfo(issues);
	CharSequence grammar = xtextProjectInfo.getRuntimeProject().grammar();
	try {
		Files.asCharSink(new File(genPath, xtextProjectInfo.getRuntimeProject().getGrammarFilePath()), Charsets.ISO_8859_1).write(grammar);
	} catch (IOException e) {
		String message = "Can't create grammar file";
		log.error(message, e);
		issues.addError(Ecore2XtextGenerator.this, message, this, e, null);
	}
}
 
Example 10
Source File: BasicUiGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	issues.addWarning("Fragment org.eclipse.xtext.ui.generator.BasicUiGeneratorFragment is deprecated and not needed anymore. Just remove it from the mwe configuration.");
	if (fileExtensions!=null)
		issues.addError("the fileExtensions property has been moved to the main language configuration. \n\tPlease change your *.mwe file to something like \n\n\t"
					+ "<language uri='${grammarURI}' fileExtensions='" + fileExtensions + "'> \n\t\t <-- fragments go here ... --> \n\t</languageConfig>\n\n",this);
}
 
Example 11
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void handleCompositeException(Issues issues, CompositeGeneratorException e) {
	for (Exception ex : e.getExceptions()) {
		if (ex instanceof CompositeGeneratorException) {
			handleCompositeException(issues, (CompositeGeneratorException) ex);
		} else if (!(ex instanceof GeneratorWarning)) {
			issues.addError(this, "GeneratorException: ", null, ex, null);
		}
	}
}
 
Example 12
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void checkConfigurationInternal(Issues issues) {
	naming.setProjectNameRt(getProjectNameRt());
	naming.setProjectNameIde(getProjectNameIde());
	naming.setIdeBasePackage(!isIde() && isUi() ? getProjectNameUi() : getProjectNameIde());
	naming.setProjectNameUi(getProjectNameUi());
	naming.setUiBasePackage(getProjectNameUi());
	naming.setActivatorName(getActivator());
	naming.setPathTestProject(getPathTestProject());
	naming.setFileHeader(getFileHeader());
	naming.setClassAnnotations(getClassAnnotationsAsString());
	naming.setAnnotationImports(getAnnotationImportsAsString());
	naming.setHasUI(isUi());
	naming.setHasIde(isIde());
	Map<String, Grammar> uris = new HashMap<String, Grammar>();
	for (LanguageConfig config : languageConfigs) {
		config.registerNaming(naming);
		config.checkConfiguration(issues);
		Grammar grammar = config.getGrammar();
		List<GeneratedMetamodel> select = EcoreUtil2.typeSelect(grammar.getMetamodelDeclarations(),
				GeneratedMetamodel.class);
		for (GeneratedMetamodel generatedMetamodel : select) {
			String nsURI = generatedMetamodel.getEPackage().getNsURI();
			if (uris.containsKey(nsURI)) {
				issues.addError("Duplicate generated grammar with nsURI '" + nsURI + "' in "
						+ uris.get(nsURI).getName() + " and " + grammar.getName());
			} else {
				uris.put(nsURI, grammar);
			}
		}
	}
	if (getProjectNameRt() == null)
		issues.addError("The property 'projectNameRt' is mandatory");
	if (isUiMergedIntoRt() && getPathIdeProject() != null && ! isIdeMergedIntoRt()) {
		issues.addError("Cannot have a dedicated ide project when ui project is merged into runtime project");
	}
}
 
Example 13
Source File: AntlrDelegatingFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	super.checkConfiguration(issues);
	if (getInstance() == null) {
		issues.addError(getMessage());
	}
	else {
		getInstance().checkConfiguration(issues);
	}
}
 
Example 14
Source File: XtextAntlrUiGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	super.checkConfiguration(issues);
	if (getOptions().isBacktrackLexer()) {
		issues.addError("This fragment does not support the option 'backtracking' for the lexer. Use 'org.eclipse.xtext.generator.parser.antlr.ex.ca.ContentAssistParserGeneratorFragment' instead");
	}
	if (getOptions().isIgnoreCase()) {
		issues.addError("This fragment does not support the option 'ignoreCase'. Use 'org.eclipse.xtext.generator.parser.antlr.ex.ca.ContentAssistParserGeneratorFragment' instead");
	}
}
 
Example 15
Source File: XtextAntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	super.checkConfiguration(issues);
	if (getOptions().isBacktrackLexer()) {
		issues.addError("This fragment does not support the option 'backtracking' for the lexer. Use 'org.eclipse.xtext.generator.parser.antlr.ex.rt.AntlrGeneratorFragment' instead");
	}
	if (getOptions().isIgnoreCase()) {
		issues.addError("This fragment does not support the option 'ignorecase'. Use 'org.eclipse.xtext.generator.parser.antlr.ex.rt.AntlrGeneratorFragment' instead");
	}
}
 
Example 16
Source File: AbstractAntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	super.checkConfiguration(issues);
	if (!antlrTool.isWorkable()) {
		issues.addError("\n\n*ATTENTION*\nIt is highly recommended to use ANTLR's parser generator (get it from 'http://xtext.itemis.com/'). \nAs an alternative to ANTLR you could also use the alternative implementation shipped with Xtext.\nTo do so use the generator fragment '"
				+ PackratParserFragment.class.getName() + "' in your mwe2 file instead.");
	}
}
 
Example 17
Source File: AntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	super.checkConfiguration(issues);
	if(getOptions().isBacktrackLexer() && getOptions().isIgnoreCase())
		issues.addError("Backtracking lexer and ignorecase cannot be combined for now.");
}
 
Example 18
Source File: ExternalAntlrLexerFragment.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void checkConfiguration(Issues issues) {
	if (contentAssist && highlighting || runtime && highlighting || contentAssist && runtime) {
		issues.addError("Only one of those flags is allowed: contentAssist, runtime, highlighting flag");
	}
}