Java Code Examples for org.eclipse.xtext.util.JavaVersion

The following examples show how to use org.eclipse.xtext.util.JavaVersion. These examples are extracted from open source projects. 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 Project: xtext-extras   Source File: ResolvedFeatures.java    License: 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 2
Source Project: xtext-extras   Source File: ResolvedFeatures.java    License: 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 3
Source Project: sarl   Source File: Bug621ResolvedFeatures.java    License: 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 4
Source Project: xtext-xtend   Source File: SameClassNamesTest.java    License: 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 5
@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 6
Source Project: sarl   Source File: JavaVersionCheckExtension.java    License: 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 7
@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 8
@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 9
@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 10
@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 11
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 12
@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 13
Source Project: xtext-xtend   Source File: WorkbenchTestHelper.java    License: 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 14
Source Project: xtext-xtend   Source File: Main.java    License: 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 15
Source Project: xtext-extras   Source File: OnTheFlyJavaCompiler.java    License: 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 16
Source Project: xtext-xtend   Source File: XtendBatchCompiler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
 * @since 2.7
 * @see <a href="https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html">Java 9 Release Notes</a>
 */
public void setBootClassPath(String bootClassPath) {
	JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
	if (version.isAtLeast(JavaVersion.JAVA9)) {
		if (!bootClassPath.isEmpty()) {
			log.warn("Option bootClassPath is only valid for Java 8 and lower. The value '"+bootClassPath+"' will be ignored.");
		}
	} else {
		this.bootClassPath = bootClassPath;
	}
}
 
Example 17
Source Project: xtext-extras   Source File: InMemoryJavaCompiler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public InMemoryJavaCompiler(final ClassLoader parent, final JavaVersion javaVersion) {
  InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment _classLoaderBasedNameEnvironment = new InMemoryJavaCompiler.ClassLoaderBasedNameEnvironment(parent);
  this.nameEnv = _classLoaderBasedNameEnvironment;
  this.parentClassLoader = parent;
  CompilerOptions _compilerOptions = new CompilerOptions();
  this.compilerOptions = _compilerOptions;
  this.setJavaVersion(javaVersion);
  this.compilerOptions.inlineJsrBytecode = true;
  this.compilerOptions.preserveAllLocalVariables = true;
}
 
Example 18
Source Project: xtext-extras   Source File: InMemoryJavaCompiler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.11
 */
public long setJavaVersion(final JavaVersion javaVersion) {
  long _xblockexpression = (long) 0;
  {
    final long classFmt = this.toClassFmt(javaVersion);
    this.setSourceLevel(classFmt);
    this.setComplianceLevel(classFmt);
    _xblockexpression = this.compilerOptions.targetJDK = classFmt;
  }
  return _xblockexpression;
}
 
Example 19
@BeforeClass
public static void createProjects() {
  try {
    TargetPlatformUtil.setTargetPlatform(ActiveAnnotationsProcessingInIDETest.class);
    ActiveAnnotationsProcessingInIDETest.macroProject = JavaCore.create(WorkbenchTestHelper.createPluginProject("macroProject", JavaVersion.JAVA8));
    ActiveAnnotationsProcessingInIDETest.userProject = JavaCore.create(
      WorkbenchTestHelper.createPluginProject("userProject", JavaVersion.JAVA8, "com.google.inject", "org.eclipse.xtend.lib", 
        "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.ide.tests.data", "org.junit", "macroProject"));
    WorkbenchTestHelper.addExportedPackages(ActiveAnnotationsProcessingInIDETest.macroProject.getProject(), "myannotation");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 20
Source Project: xtext-extras   Source File: JvmModelGenerator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected ITreeAppendable _generateModifier(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateVisibilityModifier(it, appendable);
    if ((it.isAbstract() && (!this.isDeclaredWithinInterface(it)))) {
      appendable.append("abstract ");
    }
    boolean _isStatic = it.isStatic();
    if (_isStatic) {
      appendable.append("static ");
    }
    if (((((!it.isAbstract()) && (!it.isStatic())) && config.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8)) && this.isDeclaredWithinInterface(it))) {
      appendable.append("default ");
    }
    boolean _isFinal = it.isFinal();
    if (_isFinal) {
      appendable.append("final ");
    }
    boolean _isSynchronized = it.isSynchronized();
    if (_isSynchronized) {
      appendable.append("synchronized ");
    }
    boolean _isStrictFloatingPoint = it.isStrictFloatingPoint();
    if (_isStrictFloatingPoint) {
      appendable.append("strictfp ");
    }
    ITreeAppendable _xifexpression = null;
    boolean _isNative = it.isNative();
    if (_isNative) {
      _xifexpression = appendable.append("native ");
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 21
Source Project: sarl   Source File: SarlBatchCompiler.java    License: Apache License 2.0 5 votes vote down vote up
/** Change the boot classpath.
 * This option is only supported on JDK 8 and older and will be ignored when source level is 9 or newer.
 *
 * <p>The boot classpath is a list the names of folders or jar files that are separated by {@link File#pathSeparator}.
 *
 * @param bootClasspath the new boot classpath.
 * @see "https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html"
 */
public void setBootClassPath(String bootClasspath) {
	final JavaVersion version = JavaVersion.fromQualifier(getJavaSourceVersion());
	if (version.isAtLeast(JavaVersion.JAVA9)) {
		reportInternalWarning(MessageFormat.format(Messages.SarlBatchCompiler_63, bootClasspath));
	}
	if (Strings.isEmpty(bootClasspath)) {
		this.bootClasspath = null;
	} else {
		this.bootClasspath = new ArrayList<>();
		for (final String path : Strings.split(bootClasspath, File.pathSeparator)) {
			this.bootClasspath.add(normalizeFile(path));
		}
	}
}
 
Example 22
protected CompilerOptions getCompilerOptions(JavaConfig javaConfig) {
	JavaVersion sourceVersion = JavaVersion.JAVA8;
	JavaVersion targetVersion = JavaVersion.JAVA8;
	if (javaConfig != null) {
		if (javaConfig.getJavaSourceLevel() != null) {
			sourceVersion = javaConfig.getJavaSourceLevel();
		}
		if (javaConfig.getJavaTargetLevel() != null) {
			targetVersion = javaConfig.getJavaTargetLevel();

		}
	}
	if (JavaVersion.JAVA7.equals(sourceVersion)) {
		JavaDerivedStateComputer.LOG.warn(
				"The java source language has been configured with Java 7. JDT will not produce signature information for generic @Override methods in this version, which might lead to follow up issues.");
	}
	long sourceLevel = toJdtVersion(sourceVersion);
	long targetLevel = toJdtVersion(targetVersion);
	CompilerOptions compilerOptions = new CompilerOptions();
	compilerOptions.targetJDK = targetLevel;
	compilerOptions.inlineJsrBytecode = true;
	compilerOptions.sourceLevel = sourceLevel;
	compilerOptions.produceMethodParameters = true;
	compilerOptions.produceReferenceInfo = true;
	compilerOptions.originalSourceLevel = targetLevel;
	compilerOptions.complianceLevel = sourceLevel;
	compilerOptions.originalComplianceLevel = targetLevel;
	return compilerOptions;
}
 
Example 23
Source Project: xtext-extras   Source File: CompilerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug472265_01_lamda() throws Exception {
	GeneratorConfig generatorConfig = generatorConfigProvider.get(null);
	generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8);
	assertCompilesTo("final closures.IAcceptors.IAcceptor _function = (String x) -> {\n"
			+ "};\n"
			+ "closures.IAcceptors.IAcceptor a = _function;",
			"{var closures.IAcceptors.IAcceptor a = [x|]}",
			generatorConfig);
}
 
Example 24
Source Project: xtext-extras   Source File: CompilerTest.java    License: 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 25
Source Project: xtext-extras   Source File: CompilerTest.java    License: 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 26
Source Project: sarl   Source File: AbstractSarlMavenTest.java    License: 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 27
Source Project: xtext-extras   Source File: CompilerTest.java    License: 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 28
Source Project: xtext-extras   Source File: CompilerTest.java    License: 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 29
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 30
@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);
}