Java Code Examples for org.eclipse.xtext.util.Strings#concat()

The following examples show how to use org.eclipse.xtext.util.Strings#concat() . 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: MarkerAssertions.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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 2
Source File: PerformanceTestProjectSetup.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static void setUp() throws Exception {
	testProject = createJavaProject("performance.test.project",
			new String[] {
					JavaCore.NATURE_ID,
					"org.eclipse.pde.PluginNature"
			}
	);
	new ToggleXtextNatureCommand().toggleNature(testProject.getProject());
	IFolder sourceFolder = JavaProjectSetupUtil.addSourceFolder(testProject, "src");
	JavaProjectSetupUtil.addSourceFolder(testProject, "xtend-gen");

	List<String> filesToCopy = readResource("/files.list");
	
	for(String fileToCopy: filesToCopy) {
		IPath filePath = new Path(fileToCopy);
		IFolder packageFolder = sourceFolder.getFolder(filePath.removeLastSegments(1));
		if (!packageFolder.exists())
			createFolderRecursively(packageFolder);
		List<String> content = readResource(fileToCopy);
		String contentAsString = Strings.concat("\n", content);
		String fileName = filePath.lastSegment();
		createFile(fileName.substring(0, fileName.length() - ".txt".length()), packageFolder, contentAsString);
	}
	waitForBuild();
}
 
Example 3
Source File: SemverSerializer.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return string representation of {@link QualifierTag} */
static public String serialize(QualifierTag qt) {
	if (qt == null)
		return "";

	String str = Strings.concat(".", qt.getParts());
	return str;
}
 
Example 4
Source File: AbstractAntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.7
 */
protected void normalizeTokens(String grammarFileName, Charset encoding) {
	String tokenFile = toTokenFileName(grammarFileName);
	String content = readFileIntoString(tokenFile, encoding);
	content = new NewlineNormalizer(getLineDelimiter()).normalizeLineDelimiters(content);
	List<String> splitted = Strings.split(content, getLineDelimiter());
	Collections.sort(splitted);
	content = Strings.concat(getLineDelimiter(), splitted) + getLineDelimiter();
	writeStringIntoFile(tokenFile, content, encoding);
}
 
Example 5
Source File: ExternalAntlrLexerFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private void normalizeTokens(String grammarFileName, Charset encoding) {
	String tokenFile = toTokenFileName(grammarFileName);
	String content = readFileIntoString(tokenFile, encoding);
	content = new NewlineNormalizer(getLineDelimiter()).normalizeLineDelimiters(content);
	List<String> splitted = Strings.split(content, getLineDelimiter());
	Collections.sort(splitted);
	content = Strings.concat(getLineDelimiter(), splitted) + getLineDelimiter();
	writeStringIntoFile(tokenFile, content, encoding);
}
 
Example 6
Source File: EObjectDescriptionBasedStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getJavaFileName(IEObjectDescription description) {
	if (!isJvmDeclaredType(description)) {
		return null;
	}
	QualifiedName typeName = description.getName();
	return Strings.concat("/", typeName.getSegments()) + ".java";
}
 
Example 7
Source File: XtextGrammarQuickfixProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFixInvalidMetaModelName() throws Exception {
	String model = Strings.concat("\n", Arrays.asList("grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals",
			"generate MYDSL \"http://www.xtext.org/example/mydsl/MyDsl\"", "Model: a=ID;"));
	XtextEditor xtextEditor = openInEditor(model);
	assertAndApplySingleResolution(xtextEditor, INVALID_METAMODEL_NAME, 1, "Fix metamodel name 'MYDSL'");
}
 
Example 8
Source File: XtextGrammarQuickfixProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void fixAddActionForGrammarWithAlias() throws Exception {
	String model = Strings.concat("\n",
			Arrays.asList("grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals",
					"generate myDsl \"http://www.xtext.org/example/mydsl/MyDsl\" as my",
					"Model returns my::Greeting: greetings+=Greeting*;", "Greeting returns my::Greeting: 'Hello' name=ID? '!';"));
	XtextEditor xtextEditor = openInEditor(model);
	assertAndApplySingleResolution(xtextEditor, RuleWithoutInstantiationInspector.ISSUE_CODE, 0,
			"Add actions to ensure object creation");
}
 
Example 9
Source File: XtextGrammarQuickfixProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private String grammarGeneratingModel(String... bodyContent) {
	List<String> list = new ArrayList<>();
	list.add("grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals");
	list.add("generate myDsl \"http://www.xtext.org/example/mydsl/MyDsl\"");
	list.addAll(Arrays.asList(bodyContent));
	return Strings.concat("\n", list);
}
 
Example 10
Source File: MockJavaProjectProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void setUp() throws Exception {
	if(javaProject != null)
		return;
	TargetPlatformUtil.setTargetPlatform(MockJavaProjectProvider.class);
	javaProject = createJavaProject("projectWithoutSources",
			new String[] {
					JavaCore.NATURE_ID,
					"org.eclipse.pde.PluginNature"
			}
	);
	String path = "/org/eclipse/xtext/common/types/testSetups";
	String jarFileName = "/testData.jar";
	IFile jarFile = PluginUtil.copyFileToWorkspace(TestsActivator.getInstance(), path + jarFileName, javaProject.getProject(), 
			jarFileName);
	JavaProjectSetupUtil.addJarToClasspath(javaProject, jarFile);
	
	javaProjectWithSources = createJavaProject("projectWithSources",
			new String[] {
					JavaCore.NATURE_ID,
					"org.eclipse.pde.PluginNature"
			}
	);
	IFolder sourceFolder = JavaProjectSetupUtil.addSourceFolder(javaProjectWithSources, "src");
	
	List<String> filesToCopy = readResource(path + "/files.list");
	IFolder srcFolder = sourceFolder.getFolder(new Path(path));
	createFolderRecursively(srcFolder);
	for(String fileToCopy: filesToCopy) {
		List<String> content = readResource(path + "/" + fileToCopy);
		String contentAsString = Strings.concat("\n", content);
		createFile(fileToCopy.substring(0, fileToCopy.length() - ".txt".length()), srcFolder, contentAsString);
	}
	createFile("ClassWithDefaultPackage.java", sourceFolder, "public class ClassWithDefaultPackage {}");
	PreferenceConstants.getPreferenceStore().putValue(PreferenceConstants.TYPEFILTER_ENABLED, "*.javafx.*;");
	IResourcesSetupUtil.waitForBuild();
}
 
Example 11
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void normalizeTokens(final IXtextGeneratorFileSystemAccess fsa, final String tokenFile) {
  String content = fsa.readTextFile(tokenFile).toString();
  content = this.newLineNormalizer.postProcess(fsa.getURI(tokenFile), content).toString();
  final List<String> splitted = Strings.split(content, this.codeConfig.getLineDelimiter());
  Collections.<String>sort(splitted);
  String _concat = Strings.concat(this.codeConfig.getLineDelimiter(), splitted);
  String _lineDelimiter = this.codeConfig.getLineDelimiter();
  String _plus = (_concat + _lineDelimiter);
  content = _plus;
  fsa.generateFile(tokenFile, content);
}
 
Example 12
Source File: TextAttributeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public String getMergedIds(String[] ids) {
	return "$$$Merged:" + Strings.concat("/", Arrays.asList(ids)) + "$$$";
}
 
Example 13
Source File: ExamplesTestUtils.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Assert that the given list contains no issue.
 *
 * @param issues the list to test.
 */
public static void assertNoIssue(List<String> issues) {
	if (!issues.isEmpty()) {
		throw new AssertionFailedError("Errors in the example code", "", Strings.concat("\n", issues));
	}
}