/** * 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 https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html */ 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; } }
protected void setOverride(JvmOperation operation) { if (generatorConfig.getJavaSourceVersion().isAtLeast(JAVA6) && !containsAnnotation(operation, Override.class)) { operation.getAnnotations().add(_annotationTypesBuilder.annotationRef(Override.class)); } }
protected GeneratorConfig getGeneratorConfig(EObject element) { GeneratorConfig result = (GeneratorConfig) getContext().get(GeneratorConfig.class); if (result == null) { result = generatorConfigProvider.get(element); getContext().put(GeneratorConfig.class, result); if (result.getJavaSourceVersion().isAtLeast(JAVA8)) { methodInInterfaceModifierValidator = new ModifierValidator( newArrayList("public", "abstract", "static", "def", "override"), this); } else { methodInInterfaceModifierValidator = new ModifierValidator( newArrayList("public", "abstract", "def", "override"), this); } } return result; }
/** Replies if the generation is for Java version 8 at least. * * @param context the context. * @return {@code true} if Java 8 or newer. */ protected boolean isAtLeastJava8(EObject context) { return this.generatorConfigProvider.get(EcoreUtil.getRootContainer(context)).getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8); }
/** Replies if the compiler is using Java8 or higher. * * @return <code>true</code> if the compiler uses Java8 or higher. Otherwise <code>false</code>. */ public boolean isAtLeastJava8() { final JavaVersion javaVersion = JavaVersion.fromQualifier(SARLVersion.MINIMAL_JDK_VERSION); return javaVersion != null && getGeneratorConfig().getJavaSourceVersion().isAtLeast(javaVersion); }
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); }
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); } } }
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); } } } }
if (!version.isAtLeast(JavaVersion.JAVA9)) { List<String> bootClassPathEntries = getBootClassPathEntries(); if (!isEmpty(bootClassPathEntries)) {
protected void _toJavaStatement(XSwitchExpression expr, ITreeAppendable b, boolean isReferenced) { GeneratorConfig config = b.getGeneratorConfig(); boolean compileToSwitch; if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA7)) { compileToSwitch = isCompiledToJava7Switch(expr); } else { compileToSwitch = isCompiledToJavaSwitch(expr); } if (compileToSwitch) { _toJavaSwitchStatement(expr, b, isReferenced); } else { _toJavaIfElseStatement(expr, b, isReferenced); } }
@Override protected String getInvalidWritableVariableAccessMessage(XVariableDeclaration variable, XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes) { // Overriding for proper lambda expression. final EObject containingStructure = getNearestClosureOrTypeDeclaration(featureCall, resolvedTypes); if (containingStructure instanceof XClosure && !EcoreUtil.isAncestor(containingStructure, variable)) { final GeneratorConfig generatorConfig = this.generatorConfigProvider.get( EcoreUtil.getRootContainer(containingStructure)); if (generatorConfig != null && generatorConfig.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8)) { return null; } } return super.getInvalidWritableVariableAccessMessage(variable, featureCall, resolvedTypes); }
protected void _toJavaStatement(final XClosure closure, final ITreeAppendable b, boolean isReferenced) { if (!isReferenced) throw new IllegalArgumentException("a closure definition does not cause any side-effects"); LightweightTypeReference type = getLightweightType(closure); JvmOperation operation = findImplementingOperation(type); if (operation != null) { b.newLine().append("final "); b.append(type); b.append(" "); String variableName = b.declareSyntheticVariable(closure, "_function"); b.append(variableName).append(" = "); GeneratorConfig config = b.getGeneratorConfig(); if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA8) && canCompileToJavaLambda(closure, type, operation)) { toLambda(closure, b, type, operation, false); } else { toAnonymousClass(closure, b, type, operation); } b.append(";"); } }
protected void appendOperationVisibility(final ITreeAppendable b, JvmOperation operation) { b.newLine(); JvmDeclaredType declaringType = operation.getDeclaringType(); GeneratorConfig config = b.getGeneratorConfig(); if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA6) || declaringType instanceof JvmGenericType && !((JvmGenericType) declaringType).isInterface()) { b.append("@").append(Override.class).newLine(); } switch(operation.getVisibility()) { case DEFAULT: break; case PUBLIC: b.append("public "); return; case PROTECTED: b.append("protected "); return; case PRIVATE: b.append("private "); return; } }
if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA7)) { b.append(numberLiterals.toJavaLiteral(expr, false)); } else {
protected void _toJavaExpression(final XClosure closure, final ITreeAppendable b) { if (b.hasName(closure)) { b.trace(closure, false).append(getVarName(closure, b)); } else { LightweightTypeReference type = getLightweightType(closure); JvmOperation operation = findImplementingOperation(type); if (operation != null) { GeneratorConfig config = b.getGeneratorConfig(); if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA8) && canCompileToJavaLambda(closure, type, operation)) { toLambda(closure, b.trace(closure, false), type, operation, true); } else { toAnonymousClass(closure, b.trace(closure, false), type, operation); } } } }
boolean _isAtLeast = config.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8); if (_isAtLeast) { Iterable<JvmTypeReference> _extendedInterfaces = declaredType.getExtendedInterfaces();
if (!getGeneratorConfig(function).getJavaSourceVersion().isAtLeast(JAVA8)) { error(Messages.SARLValidator_86, XTEND_FUNCTION__NAME, -1, ABSTRACT_METHOD_WITH_BODY); return;
appendable.append("static "); if ((((((!it.isAbstract()) && (!it.isStatic())) && config.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8)) && (it.eContainer() instanceof JvmGenericType)) && ((JvmGenericType) it.eContainer()).isInterface())) { appendable.append("default ");
methodInInterfaceModifierValidator.checkModifiers(method, "method " + method.getName()); int abstractIndex = method.getModifiers().indexOf("abstract"); if (config.getJavaSourceVersion().isAtLeast(JAVA8) && method.getExpression() != null && abstractIndex != -1) { error("Method " + method.getName() + " with a body cannot be abstract", XTEND_MEMBER__MODIFIERS, abstractIndex, INVALID_MODIFIER);
if (!getGeneratorConfig(function).getJavaSourceVersion().isAtLeast(JAVA8)) { error("Abstract methods do not specify a body", XTEND_FUNCTION__NAME, -1, ABSTRACT_METHOD_WITH_BODY);