org.eclipse.xtext.util.JavaVersion Java Examples

The following examples show how to use org.eclipse.xtext.util.JavaVersion. 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: NewLanguageFeaturesCompilerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNewThread() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("new Thread [| ]");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("final Runnable _function = () -> {");
  _builder_1.newLine();
  _builder_1.append("};");
  _builder_1.newLine();
  _builder_1.append("Thread _thread = new Thread(_function);");
  _builder_1.newLine();
  _builder_1.append("return _thread;");
  _builder_1.newLine();
  this.compilesTo(_builder, _builder_1, JavaVersion.JAVA8);
}
 
Example #2
Source File: Main.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private static void printUsage() {
	PrintStream out = System.out;
	String allVersionQualifiers = Arrays.stream(JavaVersion.values())
			.map(v -> v.getQualifier())
			.collect(Collectors.joining(", "));
	out.println("Usage: Main <options> <source directories>");
	out.println("where possible options include:");
	out.println("-d <directory>                      Specify where to place generated xtend files");
	out.println("-tp <path>                          Temp directory to hold generated stubs and classes");
	out.println("-cp <path>                          Specify where to find user class files");
	out.println("-encoding <encoding>                Specify character encoding used by source files");
	out.println("-javaSourceVersion <version>        Create Java Source compatible to this version. Can be: " + allVersionQualifiers);
	out.println("-noSuppressWarningsAnnotation       Don't put @SuppressWarnings() into generated Java Code");
	out.println("-generateGeneratedAnnotation        Put @Generated into generated Java Code");
	out.println("-includeDateInGeneratedAnnnotation  If -generateGeneratedAnnotation is used, add the current date/time.");
	out.println("-generateAnnotationComment <string> If -generateGeneratedAnnotation is used, add a comment.");
	out.println("-useCurrentClassLoader              Use current classloader as parent classloader");
	out.println("-writeTraceFiles                    Write Trace-Files");
}
 
Example #3
Source File: XbaseBuilderPreferenceAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public JavaVersion getJavaVersion(Object context, IPreferenceStore preferenceStore) {
	boolean useCompilerSource = preferenceStore.getBoolean(PREF_USE_COMPILER_SOURCE);
	if (useCompilerSource) {
		IJavaProject javaProject = JavaCore.create(context instanceof IProject ? (IProject) context : null);
		String compilerSource;
		if (javaProject != null && javaProject.exists() && javaProject.getProject().isAccessible()) {
			compilerSource = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
		} else {
			compilerSource = JavaCore.getOption(JavaCore.COMPILER_SOURCE);
		}
		return fromCompilerSourceLevel(compilerSource);
	} else {
		String stringValue = preferenceStore.getString(PREF_JAVA_VERSION);
		try {
			return JavaVersion.valueOf(stringValue);
		} catch (IllegalArgumentException exception) {
			// Fall back to default value
		}
	}
	return JavaVersion.JAVA5;
}
 
Example #4
Source File: WorkbenchTestHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static IProject createPluginProject(String name, JavaVersion javaVersion, String... requiredBundles) throws CoreException {
	Injector injector = XtendActivator.getInstance().getInjector(XtendActivator.ORG_ECLIPSE_XTEND_CORE_XTEND);
	PluginProjectFactory projectFactory = injector.getInstance(PluginProjectFactory.class);
	projectFactory.setProjectName(name);
	projectFactory.setProjectDefaultCharset(StandardCharsets.ISO_8859_1.name());
	projectFactory.setBreeToUse(getBree(javaVersion));
	projectFactory.addFolders(Collections.singletonList("src"));
	projectFactory.addBuilderIds(XtextProjectHelper.BUILDER_ID, JavaCore.BUILDER_ID, "org.eclipse.pde.ManifestBuilder",
			"org.eclipse.pde.SchemaBuilder");
	projectFactory.addProjectNatures(
			XtextProjectHelper.NATURE_ID, JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature");
	projectFactory.addRequiredBundles(newArrayList(requiredBundles));
	IProject result = projectFactory.createProject(new NullProgressMonitor(), null);
	IJavaProject javaProject = JavaCore.create(result);
	if (javaVersion == null)
		JavaProjectSetupUtil.makeJava8Compliant(javaProject);
	else
		makeCompliantFor(javaProject, javaVersion);
	JavaProjectSetupUtil.addJreClasspathEntry(javaProject);
	return result;
}
 
Example #5
Source File: SameClassNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public IProject createPluginProject(final String name, final String... requiredBundles) throws CoreException {
  final PluginProjectFactory projectFactory = this.projectFactoryProvider.get();
  projectFactory.setProjectName(name);
  projectFactory.setBreeToUse(JREContainerProvider.PREFERRED_BREE);
  projectFactory.addFolders(Collections.<String>singletonList("src"));
  projectFactory.addBuilderIds(
    XtextProjectHelper.BUILDER_ID, 
    JavaCore.BUILDER_ID, 
    "org.eclipse.pde.ManifestBuilder", 
    "org.eclipse.pde.SchemaBuilder");
  projectFactory.addProjectNatures(
    XtextProjectHelper.NATURE_ID, JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature");
  projectFactory.addRequiredBundles(((List<String>)Conversions.doWrapArray(requiredBundles)));
  projectFactory.addExportedPackages(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("com.acme")));
  NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
  final IProject result = projectFactory.createProject(_nullProgressMonitor, null);
  final IJavaProject javaProject = JavaCore.create(result);
  WorkbenchTestHelper.makeCompliantFor(javaProject, JavaVersion.JAVA8);
  JavaProjectSetupUtil.addJreClasspathEntry(javaProject);
  return result;
}
 
Example #6
Source File: NewLanguageFeaturesCompilerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testBlockHasNoSuperfluousBraces_03() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("{ var (int)=>void fun = [ int i | new Object() new Object() ] }");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("final org.eclipse.xtext.xbase.lib.Procedures.Procedure1<Integer> _function = (Integer i) -> {");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("new Object();");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("new Object();");
  _builder_1.newLine();
  _builder_1.append("};");
  _builder_1.newLine();
  _builder_1.append("org.eclipse.xtext.xbase.lib.Procedures.Procedure1<? super Integer> fun = _function;");
  _builder_1.newLine();
  this.compilesTo(_builder, _builder_1, JavaVersion.JAVA8);
}
 
Example #7
Source File: NewLanguageFeaturesCompilerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testImplicitReferenceToSynonym_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("(null as Iterable<String[]>).forEach[ reverse ]");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("final java.util.function.Consumer<String[]> _function = (String[] it) -> {");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("org.eclipse.xtext.xbase.lib.ListExtensions.<String>reverse(((java.util.List<String>)org.eclipse.xtext.xbase.lib.Conversions.doWrapArray(it)));");
  _builder_1.newLine();
  _builder_1.append("};");
  _builder_1.newLine();
  _builder_1.append("((Iterable<String[]>) null).forEach(_function);");
  _builder_1.newLine();
  this.compilesTo(_builder, _builder_1, JavaVersion.JAVA8);
}
 
Example #8
Source File: Java8RuntimeInjectorProvider.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Injector internalCreateInjector() {
	return new RuntimeTestSetup() {
		
		@Override
		public Injector createInjector() {
			return Guice.createInjector(new XtendRuntimeTestModule() {
				@Override
				public ClassLoader bindClassLoaderToInstance() {
					return Java8RuntimeInjectorProvider.class.getClassLoader();
				}
			}, new JavaVersionModule(JavaVersion.JAVA8));
		}
		
	}.createInjectorAndDoEMFRegistration();
}
 
Example #9
Source File: NewLanguageFeaturesCompilerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testImplicitReferenceToMultitype() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("((null as Iterable<java.util.List<Object>>) + (null as Iterable<java.util.Set<Object>>)).forEach[ size ]");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("final java.util.function.Consumer<java.util.Collection<Object>> _function = (java.util.Collection<Object> it) -> {");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("it.size();");
  _builder_1.newLine();
  _builder_1.append("};");
  _builder_1.newLine();
  _builder_1.append("com.google.common.collect.Iterables.<java.util.Collection<Object>>concat(((Iterable<java.util.List<Object>>) null), ((Iterable<java.util.Set<Object>>) null)).forEach(_function);");
  _builder_1.newLine();
  this.compilesTo(_builder, _builder_1, JavaVersion.JAVA8);
}
 
Example #10
Source File: ResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected List<IResolvedOperation> computeAllOperations() {
	JvmType rawType = getRawType();
	if (!(rawType instanceof JvmDeclaredType)) {
		return Collections.emptyList();
	}
	Multimap<String, AbstractResolvedOperation> processedOperations = LinkedHashMultimap.create();
	for (IResolvedOperation resolvedOperation : getDeclaredOperations()) {
		processedOperations.put(resolvedOperation.getDeclaration().getSimpleName(), (AbstractResolvedOperation) resolvedOperation);
	}
	if (targetVersion.isAtLeast(JavaVersion.JAVA8)) {
		computeAllOperationsFromSortedSuperTypes((JvmDeclaredType) rawType, processedOperations);
	} else {
		Set<JvmType> processedTypes = Sets.newHashSet(rawType);
		computeAllOperationsFromSuperTypes((JvmDeclaredType) rawType, processedOperations, processedTypes);
	}
	// make sure the declared operations are the first in the list
	List<IResolvedOperation> result = new ArrayList<IResolvedOperation>(processedOperations.size());
	result.addAll(getDeclaredOperations());
	for (AbstractResolvedOperation operation : processedOperations.values()) {
		if (operation.getDeclaration().getDeclaringType() != rawType) {
			result.add(operation);
		}
	}
	return Collections.unmodifiableList(result);
}
 
Example #11
Source File: ResolvedFeatures.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void computeAllOperations(JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations) {
	for (JvmOperation operation: type.getDeclaredOperations()) {
		boolean addToResult = true;
		if (targetVersion.isAtLeast(JavaVersion.JAVA8)) {
			addToResult = handleOverridesAndConflicts(operation, processedOperations);
		} else {
			String simpleName = operation.getSimpleName();
			if (processedOperations.containsKey(simpleName)) {
				addToResult = !isOverridden(operation, processedOperations.get(simpleName));
			}
		}
		if (addToResult) {
			BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
			processedOperations.put(operation.getSimpleName(), resolvedOperation);
		}
	}
}
 
Example #12
Source File: NewLanguageFeaturesCompilerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testBug410797_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("{ val boolean bug = #[true, false, true].reduce[a,b|a && b] }");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("final org.eclipse.xtext.xbase.lib.Functions.Function2<Boolean, Boolean, Boolean> _function = (Boolean a, Boolean b) -> {");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("return Boolean.valueOf(((a).booleanValue() && (b).booleanValue()));");
  _builder_1.newLine();
  _builder_1.append("};");
  _builder_1.newLine();
  _builder_1.append("final boolean bug = (boolean) org.eclipse.xtext.xbase.lib.IterableExtensions.<Boolean>reduce(java.util.Collections.<Boolean>unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.<Boolean>newArrayList(Boolean.valueOf(true), Boolean.valueOf(false), Boolean.valueOf(true))), _function);");
  _builder_1.newLine();
  this.compilesTo(_builder, _builder_1, JavaVersion.JAVA8);
}
 
Example #13
Source File: Bug621ResolvedFeatures.java    From sarl with Apache License 2.0 6 votes vote down vote up
protected void computeAllOperations(boolean isSuperClassBranch, Multimap<String, AbstractResolvedOperation> superClassBranchOperations,
		JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations) {
	for (JvmOperation operation: type.getDeclaredOperations()) {
		boolean addToResult = true;
		if (targetVersion.isAtLeast(JavaVersion.JAVA8)) {
			addToResult = handleOverridesAndConflicts(isSuperClassBranch, operation, processedOperations, superClassBranchOperations);
		} else {
			String simpleName = operation.getSimpleName();
			if (processedOperations.containsKey(simpleName)) {
				addToResult = !isOverridden(operation, processedOperations.get(simpleName));
			}
		}
		if (addToResult) {
			BottomResolvedOperation resolvedOperation = createResolvedOperation(operation);
			processedOperations.put(operation.getSimpleName(), resolvedOperation);
			if (isSuperClassBranch) {
				superClassBranchOperations.put(operation.getSimpleName(), resolvedOperation);
			}
		}
	}
}
 
Example #14
Source File: JavaVersionCheckExtension.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
	// Check if the minimal version of Java is used for running the tests.
	final JavaVersion cVersion = JavaVersion.fromQualifier(System.getProperty("java.specification.version"));
	if (cVersion == null) {
		return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
	}
	final JavaVersion mVersion = JavaVersion.fromQualifier(SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
	if (mVersion == null || !cVersion.isAtLeast(mVersion)) {
		return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
	}
	final JavaVersion xVersion = JavaVersion.fromQualifier(SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
	// If null the max version that is specified into the SARL configuration is not yey supported by Xtext enumeration
	if (xVersion != null && cVersion.isAtLeast(xVersion)) {
		return ConditionEvaluationResult.disabled("You must use JDK strictly below " + SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " for running the tests.");
	}
	return ConditionEvaluationResult.enabled("supported version of JDK");
}
 
Example #15
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_04_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor4 _function = (String x, String[] y) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor4 a = _function;",
			"{var closures.IAcceptors.IAcceptor4 a = [x,y|]}",
			generatorConfig);
}
 
Example #16
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_06_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor6 _function = (String[] x, String[] y) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor6 a = _function;",
			"{var closures.IAcceptors.IAcceptor6 a = [x,y|]}",
			generatorConfig);
}
 
Example #17
Source File: AbstractSarlMavenTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public Injector getInjector() {
	return getInjectedInjector().createChildInjector(new Module() {
		@Override
		public void configure(Binder binder) {
			binder.bind(ProjectCreator.class).to(MavenProjectCreator.class);
			binder.bind(JavaVersion.class).toProvider(new Provider<JavaVersion>() {
				@Override
				public JavaVersion get() {
					return JavaVersion.JAVA8;
				}
			});
		}
	});
}
 
Example #18
Source File: AbstractSarlUiTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the injection modules to be used.
 *
 * @return the injection modules.
 */
protected Module[] getInjectionModules() {
	return new Module[] {
			new Module() {
				@Override
				public void configure(Binder binder) {
					final JavaVersion version = JavaVersion.JAVA8;
					binder.bind(JavaVersion.class).toProvider(() -> version);
					binder.bind(ProjectCreator.class).toProvider(() -> {
						return new JavaProjectCreator(version);
					}).asEagerSingleton();
				}
			},	
	};
}
 
Example #19
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_03_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor3 _function = (String... x) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor3 a = _function;",
			"{var closures.IAcceptors.IAcceptor3 a = [x|]}",
			generatorConfig);
}
 
Example #20
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkDuplicateAndOverriddenFunctions(XtendTypeDeclaration xtendType) {
	final JvmDeclaredType inferredType = associations.getInferredType(xtendType);
	if (inferredType instanceof JvmGenericType) {
		JavaVersion targetVersion = getGeneratorConfig(xtendType).getJavaSourceVersion();
		ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(inferredType, targetVersion);
		
		Set<EObject> flaggedOperations = Sets.newHashSet();
		doCheckDuplicateExecutables((JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
		doCheckOverriddenMethods(xtendType, (JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
		doCheckFunctionOverrides(resolvedFeatures, flaggedOperations);
	}
}
 
Example #21
Source File: OnTheFlyJavaCompiler2Test.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testJavaVersion7() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("java.util.List<String> list = new java.util.LinkedList<>();");
  _builder.newLine();
  this.assertJavaCompilation(_builder, 
    JavaVersion.JAVA7);
}
 
Example #22
Source File: CompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_07_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor7 _function = (String[] x, String... y) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor7 a = _function;",
			"{var closures.IAcceptors.IAcceptor7 a = [x,y|]}",
			generatorConfig);
}
 
Example #23
Source File: XbaseBuilderPreferenceAccess.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void initializeBuilderPreferences(IPreferenceStore store) {
	super.initializeBuilderPreferences(store);
	store.setDefault(PREF_GENERATE_SUPPRESS_WARNINGS, true);
	store.setDefault(PREF_GENERATE_GENERATED, false);
	store.setDefault(PREF_DATE_IN_GENERATED, false);
	store.setDefault(PREF_JAVA_VERSION, JavaVersion.JAVA5.toString());
	store.setDefault(PREF_USE_COMPILER_SOURCE, true);
}
 
Example #24
Source File: AbstractOutputComparingCompilerTests.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void compilesTo(final CharSequence xbaseCode, final CharSequence result,
		Pair<JavaVersion, JavaVersion> minAndMaxVersion) throws Exception {
	int min = minAndMaxVersion.getKey().ordinal();
	int max = minAndMaxVersion.getValue().ordinal();
	if (min > max)
		throw new IllegalArgumentException();
	for (int i = min; i <= max; i++) {
		JavaVersion version = JavaVersion.values()[i];
		assertCompilesTo(result, xbaseCode, version);
	}
}
 
Example #25
Source File: NewLanguageFeaturesCompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOverride() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("{ val x = #[\'a\', \'\', \'c\'].filter[!empty] }");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("final org.eclipse.xtext.xbase.lib.Functions.Function1<String, Boolean> _function = new org.eclipse.xtext.xbase.lib.Functions.Function1<String, Boolean>() {");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("@Override");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("public Boolean apply(final String it) {");
  _builder_1.newLine();
  _builder_1.append("    ");
  _builder_1.append("boolean _isEmpty = it.isEmpty();");
  _builder_1.newLine();
  _builder_1.append("    ");
  _builder_1.append("return Boolean.valueOf((!_isEmpty));");
  _builder_1.newLine();
  _builder_1.append("  ");
  _builder_1.append("}");
  _builder_1.newLine();
  _builder_1.append("};");
  _builder_1.newLine();
  _builder_1.append("final Iterable<String> x = org.eclipse.xtext.xbase.lib.IterableExtensions.<String>filter(java.util.Collections.<String>unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.<String>newArrayList(\"a\", \"\", \"c\")), _function);");
  _builder_1.newLine();
  Pair<JavaVersion, JavaVersion> _mappedTo = Pair.<JavaVersion, JavaVersion>of(JavaVersion.JAVA6, JavaVersion.JAVA7);
  this.compilesTo(_builder, _builder_1, _mappedTo);
}
 
Example #26
Source File: OnTheFlyJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getComplianceLevelArg() {
	JavaVersion javaVersion = JavaVersion.JAVA5;
	if (generatorConfigProvider != null) {
		GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
		javaVersion = generatorConfig.getJavaSourceVersion();
	}
	return javaVersion.getComplianceLevelArg();
}
 
Example #27
Source File: NewLanguageFeaturesCompilerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testExceptionOnClosure() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("{val java.beans.VetoableChangeListener x = []}");
  _builder.newLine();
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("final java.beans.VetoableChangeListener _function = (java.beans.PropertyChangeEvent it) -> {");
  _builder_1.newLine();
  _builder_1.append("};");
  _builder_1.newLine();
  _builder_1.append("final java.beans.VetoableChangeListener x = _function;");
  _builder_1.newLine();
  this.compilesTo(_builder, _builder_1, JavaVersion.JAVA8);
}
 
Example #28
Source File: WizardNewXtextProjectCreationPage.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void fillBreeCombo(Combo comboToFill) {
	Set<String> brees = Sets.newLinkedHashSet();
	Set<String> availableBrees = Sets.newHashSet();
	for (IExecutionEnvironment ee : JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments()) {
		availableBrees.add(ee.getId());
	}
	for (JavaVersion supportedVersion : JavaVersion.values()) {
		if (supportedVersion.isAtLeast(JavaVersion.JAVA6)) {
			String bree = supportedVersion.getBree();
			if (availableBrees.contains(bree))
				brees.add(bree);
		}
	}
	String[] array = brees.toArray(new String[] {});
	String selectionMemento = comboToFill.getText();
	comboToFill.setItems(array);
	int index = comboToFill.indexOf(selectionMemento);
	String defaultBree = JREContainerProvider.getDefaultBREE();
	if (index < 0) {
		if (brees.contains(defaultBree)) {
			comboToFill.select(comboToFill.indexOf(defaultBree));
		} else {
			comboToFill.select(array.length - 1);
		}
	}
	comboToFill.select(index);
}
 
Example #29
Source File: OnTheFlyJavaCompiler2Test.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private Class<?> assertJavaCompilation(final CharSequence input, final JavaVersion javaVersion) {
  Class<?> _xblockexpression = null;
  {
    if ((javaVersion != null)) {
      this.javaCompiler.setJavaVersion(javaVersion);
    }
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package tests;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class Main {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static void main(String args[]) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append(input, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _xblockexpression = this.javaCompiler.compileToClass("tests.Main", _builder.toString());
  }
  return _xblockexpression;
}
 
Example #30
Source File: OnTheFlyJavaCompiler2Test.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testJavaVersion8() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Runnable r = () -> {};");
  _builder.newLine();
  this.assertJavaCompilation(_builder, 
    JavaVersion.JAVA8);
}