diff --git a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/formatting2/CheckFormatter.java b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/formatting2/CheckFormatter.java index 10977c95c..461da8ab6 100644 --- a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/formatting2/CheckFormatter.java +++ b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/formatting2/CheckFormatter.java @@ -11,7 +11,6 @@ package com.avaloq.tools.ddk.check.formatting2; import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.Keyword; import org.eclipse.xtext.common.types.JvmFormalParameter; import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; @@ -19,7 +18,6 @@ import org.eclipse.xtext.common.types.JvmTypeParameter; import org.eclipse.xtext.common.types.JvmWildcardTypeReference; import org.eclipse.xtext.formatting2.IFormattableDocument; -import org.eclipse.xtext.formatting2.IHiddenRegionFormatter; import org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion; import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion; import org.eclipse.xtext.resource.XtextResource; @@ -88,15 +86,15 @@ private void formatCurlyBracket(final EObject semanticElement, final IFormattabl // low priority so that it can be overridden by other custom formatting rules. final ISemanticRegion open = regionFor(semanticElement).keyword("{"); final ISemanticRegion close = regionFor(semanticElement).keyword("}"); - document.interior(open, close, (IHiddenRegionFormatter it) -> { + document.interior(open, close, it -> { it.lowPriority(); it.indent(); }); - document.append(open, (IHiddenRegionFormatter it) -> { + document.append(open, it -> { it.lowPriority(); it.newLine(); }); - document.prepend(close, (IHiddenRegionFormatter it) -> { + document.prepend(close, it -> { it.lowPriority(); it.newLine(); }); @@ -117,13 +115,13 @@ private void globalFormatting(final IEObjectRegion requestRoot, final IFormattab boolean firstRegion = true; for (final ISemanticRegion region : requestRoot.getAllSemanticRegions()) { if (firstRegion) { - document.prepend(region, (IHiddenRegionFormatter it) -> { + document.prepend(region, it -> { it.lowPriority(); it.autowrap(132); }); firstRegion = false; } else { - document.prepend(region, (IHiddenRegionFormatter it) -> { + document.prepend(region, it -> { it.lowPriority(); it.oneSpace(); it.autowrap(132); @@ -134,27 +132,27 @@ private void globalFormatting(final IEObjectRegion requestRoot, final IFormattab // CHECKSTYLE:CHECK-ON MagicNumber protected void _format(final CheckCatalog checkcatalog, final IFormattableDocument document) { - document.prepend(checkcatalog, (IHiddenRegionFormatter it) -> { + document.prepend(checkcatalog, it -> { it.noSpace(); it.setNewLines(0); }); - document.append(checkcatalog, (IHiddenRegionFormatter it) -> { + document.append(checkcatalog, it -> { it.noSpace(); it.setNewLines(0, 0, 1); }); final ISemanticRegion finalKw = regionFor(checkcatalog).keyword("final"); final ISemanticRegion catalog = regionFor(checkcatalog).keyword("catalog"); if (finalKw != null) { - document.prepend(finalKw, (IHiddenRegionFormatter it) -> { + document.prepend(finalKw, it -> { it.setNewLines(1, 2, 2); }); } else { - document.prepend(catalog, (IHiddenRegionFormatter it) -> { + document.prepend(catalog, it -> { it.setNewLines(1, 1, 2); }); } final ISemanticRegion forKw = regionFor(checkcatalog).keyword("for"); - document.prepend(forKw, (IHiddenRegionFormatter it) -> { + document.prepend(forKw, it -> { it.setNewLines(1, 1, 2); }); formatCurlyBracket(checkcatalog, document); @@ -186,7 +184,7 @@ protected void _format(final XImportSection ximportsection, final IFormattableDo // Generated model traversal for (final XImportDeclaration importDeclarations : ximportsection.getImportDeclarations()) { // ADDED: formatting added before each import - document.prepend(importDeclarations, (IHiddenRegionFormatter it) -> { + document.prepend(importDeclarations, it -> { it.setNewLines(1, 1, 2); }); @@ -195,7 +193,7 @@ protected void _format(final XImportSection ximportsection, final IFormattableDo } protected void _format(final Category category, final IFormattableDocument document) { - document.prepend(category, (IHiddenRegionFormatter it) -> { + document.prepend(category, it -> { it.setNewLines(1, 2, 2); }); formatCurlyBracket(category, document); @@ -207,17 +205,17 @@ protected void _format(final Category category, final IFormattableDocument docum } protected void _format(final Check check, final IFormattableDocument document) { - document.prepend(check, (IHiddenRegionFormatter it) -> { + document.prepend(check, it -> { it.setNewLines(1, 2, 2); }); final ISemanticRegion open = regionFor(check).keyword("("); final ISemanticRegion close = regionFor(check).keyword(")"); - document.interior(open, close, (IHiddenRegionFormatter it) -> { + document.interior(open, close, it -> { it.highPriority(); it.noSpace(); }); // High priority to override formatting from adjacent regions and parent formatter. final ISemanticRegion message = regionFor(check).keyword("message"); - document.prepend(message, (IHiddenRegionFormatter it) -> { + document.prepend(message, it -> { it.setNewLines(1, 1, 2); }); formatCurlyBracket(check, document); @@ -228,11 +226,11 @@ protected void _format(final Check check, final IFormattableDocument document) { // ADDED: formatting added around comma. // High priority to override formatting from adjacent regions and parent formatter. final ISemanticRegion comma = immediatelyFollowing(formalParameters).keyword(","); - document.prepend(comma, (IHiddenRegionFormatter it) -> { + document.prepend(comma, it -> { it.highPriority(); it.noSpace(); }); - document.append(comma, (IHiddenRegionFormatter it) -> { + document.append(comma, it -> { it.highPriority(); it.setNewLines(0, 0, 1); }); @@ -246,18 +244,18 @@ protected void _format(final Check check, final IFormattableDocument document) { protected void _format(final SeverityRange severityrange, final IFormattableDocument document) { final ISemanticRegion range = regionFor(severityrange).keyword("SeverityRange"); - document.surround(range, (IHiddenRegionFormatter it) -> { + document.surround(range, it -> { it.noSpace(); }); final ISemanticRegion open = regionFor(severityrange).keyword("("); - document.append(open, (IHiddenRegionFormatter it) -> { + document.append(open, it -> { it.noSpace(); }); final ISemanticRegion close = regionFor(severityrange).keyword(")"); - document.prepend(close, (IHiddenRegionFormatter it) -> { + document.prepend(close, it -> { it.noSpace(); }); - document.append(close, (IHiddenRegionFormatter it) -> { + document.append(close, it -> { it.newLine(); }); } @@ -272,7 +270,7 @@ protected void _format(final Member member, final IFormattableDocument document) } protected void _format(final Implementation implementation, final IFormattableDocument document) { - document.prepend(implementation, (IHiddenRegionFormatter it) -> { + document.prepend(implementation, it -> { it.setNewLines(1, 2, 2); }); @@ -299,7 +297,7 @@ protected void _format(final XListLiteral xlistliteral, final IFormattableDocume } protected void _format(final Context context, final IFormattableDocument document) { - document.surround(context, (IHiddenRegionFormatter it) -> { + document.surround(context, it -> { it.setNewLines(1, 2, 2); }); @@ -314,7 +312,7 @@ protected void _format(final ContextVariable contextvariable, final IFormattable } protected void _format(final XGuardExpression xguardexpression, final IFormattableDocument document) { - document.prepend(xguardexpression, (IHiddenRegionFormatter it) -> { + document.prepend(xguardexpression, it -> { it.setNewLines(1, 2, 2); }); @@ -324,37 +322,37 @@ protected void _format(final XGuardExpression xguardexpression, final IFormattab protected void _format(final XIssueExpression xissueexpression, final IFormattableDocument document) { // High priority to override formatting from adjacent regions and parent formatter. - document.prepend(xissueexpression, (IHiddenRegionFormatter it) -> { + document.prepend(xissueexpression, it -> { it.highPriority(); it.setNewLines(1, 2, 2); }); - checkGrammarAccess.getXIssueExpressionAccess().findKeywords("#").forEach((Keyword kw) -> { + checkGrammarAccess.getXIssueExpressionAccess().findKeywords("#").forEach(kw -> { final ISemanticRegion hash = regionFor(xissueexpression).keyword(kw); - document.surround(hash, (IHiddenRegionFormatter it) -> { + document.surround(hash, it -> { it.highPriority(); it.noSpace(); }); }); final ISemanticRegion openSquare = regionFor(xissueexpression).keyword("["); - document.surround(openSquare, (IHiddenRegionFormatter it) -> { + document.surround(openSquare, it -> { it.highPriority(); it.noSpace(); }); final ISemanticRegion closeSquare = regionFor(xissueexpression).keyword("]"); - document.prepend(closeSquare, (IHiddenRegionFormatter it) -> { + document.prepend(closeSquare, it -> { it.highPriority(); it.noSpace(); }); - checkGrammarAccess.getXIssueExpressionAccess().findKeywords("(").forEach((Keyword kw) -> { + checkGrammarAccess.getXIssueExpressionAccess().findKeywords("(").forEach(kw -> { final ISemanticRegion open = regionFor(xissueexpression).keyword(kw); - document.append(open, (IHiddenRegionFormatter it) -> { + document.append(open, it -> { it.highPriority(); it.noSpace(); }); }); - checkGrammarAccess.getXIssueExpressionAccess().findKeywords(")").forEach((Keyword kw) -> { + checkGrammarAccess.getXIssueExpressionAccess().findKeywords(")").forEach(kw -> { final ISemanticRegion close = regionFor(xissueexpression).keyword(kw); - document.prepend(close, (IHiddenRegionFormatter it) -> { + document.prepend(close, it -> { it.highPriority(); it.noSpace(); }); @@ -367,11 +365,11 @@ protected void _format(final XIssueExpression xissueexpression, final IFormattab for (final XExpression messageParameters : xissueexpression.getMessageParameters()) { // ADDED: formatting added around comma final ISemanticRegion comma = immediatelyFollowing(messageParameters).keyword(","); - document.prepend(comma, (IHiddenRegionFormatter it) -> { + document.prepend(comma, it -> { it.highPriority(); it.noSpace(); }); - document.append(comma, (IHiddenRegionFormatter it) -> { + document.append(comma, it -> { it.highPriority(); it.oneSpace(); }); @@ -381,11 +379,11 @@ protected void _format(final XIssueExpression xissueexpression, final IFormattab for (final XExpression issueData : xissueexpression.getIssueData()) { // ADDED: formatting added around comma final ISemanticRegion comma = immediatelyFollowing(issueData).keyword(","); - document.prepend(comma, (IHiddenRegionFormatter it) -> { + document.prepend(comma, it -> { it.highPriority(); it.noSpace(); }); - document.append(comma, (IHiddenRegionFormatter it) -> { + document.append(comma, it -> { it.highPriority(); it.oneSpace(); }); @@ -397,31 +395,31 @@ protected void _format(final XIssueExpression xissueexpression, final IFormattab @Override protected void _format(final XIfExpression xifexpression, final IFormattableDocument document) { // High priority to override formatting from adjacent regions and parent formatter. - document.prepend(xifexpression, (IHiddenRegionFormatter it) -> { + document.prepend(xifexpression, it -> { it.highPriority(); it.setNewLines(1, 1, 2); }); final ISemanticRegion open = regionFor(xifexpression).keyword("("); final ISemanticRegion close = regionFor(xifexpression).keyword(")"); - document.prepend(open, (IHiddenRegionFormatter it) -> { + document.prepend(open, it -> { it.highPriority(); it.oneSpace(); }); - document.append(open, (IHiddenRegionFormatter it) -> { + document.append(open, it -> { it.highPriority(); it.noSpace(); }); - document.prepend(close, (IHiddenRegionFormatter it) -> { + document.prepend(close, it -> { it.highPriority(); it.noSpace(); }); - document.append(close, (IHiddenRegionFormatter it) -> { + document.append(close, it -> { it.highPriority(); it.setNewLines(0); it.oneSpace(); }); final ISemanticRegion elseKw = regionFor(xifexpression).keyword("else"); - document.surround(elseKw, (IHiddenRegionFormatter it) -> { + document.surround(elseKw, it -> { it.highPriority(); it.setNewLines(0); it.oneSpace(); @@ -435,23 +433,23 @@ protected void _format(final XIfExpression xifexpression, final IFormattableDocu protected void _format(final XMemberFeatureCall xfeaturecall, final IFormattableDocument document) { // set no space after '::' in CheckUtil::hasQualifiedName(..., and also not after plain "." or "?." // High priority to override formatting from adjacent regions and parent formatter. - checkGrammarAccess.getXMemberFeatureCallAccess().findKeywords(".").forEach((Keyword kw) -> { + checkGrammarAccess.getXMemberFeatureCallAccess().findKeywords(".").forEach(kw -> { final ISemanticRegion dot = regionFor(xfeaturecall).keyword(kw); - document.append(dot, (IHiddenRegionFormatter it) -> { + document.append(dot, it -> { it.highPriority(); it.noSpace(); }); }); - checkGrammarAccess.getXMemberFeatureCallAccess().findKeywords("?.").forEach((Keyword kw) -> { + checkGrammarAccess.getXMemberFeatureCallAccess().findKeywords("?.").forEach(kw -> { final ISemanticRegion queryDot = regionFor(xfeaturecall).keyword(kw); - document.append(queryDot, (IHiddenRegionFormatter it) -> { + document.append(queryDot, it -> { it.highPriority(); it.noSpace(); }); }); - checkGrammarAccess.getXMemberFeatureCallAccess().findKeywords("::").forEach((Keyword kw) -> { + checkGrammarAccess.getXMemberFeatureCallAccess().findKeywords("::").forEach(kw -> { final ISemanticRegion colonColon = regionFor(xfeaturecall).keyword(kw); - document.append(colonColon, (IHiddenRegionFormatter it) -> { + document.append(colonColon, it -> { it.highPriority(); it.noSpace(); }); diff --git a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGenerator.java b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGenerator.java index 5161415f7..4b0eaff63 100644 --- a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGenerator.java +++ b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGenerator.java @@ -15,7 +15,6 @@ import java.util.Set; import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.common.types.JvmField; @@ -67,7 +66,7 @@ public void doGenerate(final Resource resource, final IFileSystemAccess fsa) { uri = resource.getURI(); } final CheckGeneratorConfig config = generatorConfigProvider.get(uri); - final Iterable catalogs = Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), CheckCatalog.class); + final Iterable catalogs = Iterables.filter(IteratorExtensions.toIterable(resource.getAllContents()), CheckCatalog.class); for (final CheckCatalog catalog : catalogs) { lfFsa.generateFile(checkGeneratorNaming.issueCodesFilePath(catalog), compileIssueCodes(catalog)); lfFsa.generateFile(checkGeneratorNaming.standaloneSetupPath(catalog), compileStandaloneSetup(catalog)); @@ -225,13 +224,13 @@ public CharSequence bodyDoc(final CheckCatalog catalog) { */ public CharSequence compileIssueCodes(final CheckCatalog catalog) { final Iterable allIssues = generatorExtensions.checkAndImplementationIssues(catalog); - final Function1 keyFunction = (final XIssueExpression issue) -> { + final Function1 keyFunction = issue -> { return CheckGeneratorExtensions.issueCode(issue); }; - final Function1 valueFunction = (final XIssueExpression issue) -> { + final Function1 valueFunction = issue -> { return CheckGeneratorExtensions.issueName(issue); }; - final Map allIssueNames = IterableExtensions.toMap(allIssues, keyFunction, valueFunction); + final Map allIssueNames = IterableExtensions.toMap(allIssues, keyFunction, valueFunction); StringConcatenation builder = new StringConcatenation(); if (!StringExtensions.isNullOrEmpty(catalog.getPackageName())) { builder.append("package "); @@ -255,7 +254,7 @@ public CharSequence compileIssueCodes(final CheckCatalog catalog) { builder.append(" {"); builder.newLineIfNotEmpty(); builder.newLine(); - final List sortedCodes = IterableExtensions.sort(allIssueNames.keySet()); + final List sortedCodes = IterableExtensions.sort(allIssueNames.keySet()); for (final String issueCode : sortedCodes) { builder.append(" "); builder.append("public static final String "); diff --git a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGeneratorExtensions.java b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGeneratorExtensions.java index 2b6d75aa7..3fed55f4f 100644 --- a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGeneratorExtensions.java +++ b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/generator/CheckGeneratorExtensions.java @@ -257,7 +257,7 @@ public Set getContents(final CheckCatalog catalog, final String path) { if (file.exists()) { try (InputStreamReader reader = new InputStreamReader(file.getContents(), StandardCharsets.UTF_8)) { final List content = CharStreams.readLines(reader); - return Sets.newTreeSet(content); + return Sets.newTreeSet(content); } catch (final RuntimeException e) { throw e; } catch (final Exception e) { @@ -276,7 +276,7 @@ public String qualifiedIssueCodeName(final EObject context) { return _qualifiedIssueCodeName(xIssueExpression); } else { throw new IllegalArgumentException("Unhandled parameter types: " - + Arrays.asList(context).toString()); + + Arrays.asList(context).toString()); } } @@ -287,7 +287,7 @@ public static String issueCode(final EObject check) { return _issueCode(xIssueExpression); } else { throw new IllegalArgumentException("Unhandled parameter types: " - + Arrays.asList(check).toString()); + + Arrays.asList(check).toString()); } } @@ -298,7 +298,7 @@ public static String issueName(final EObject check) { return _issueName(xIssueExpression); } else { throw new IllegalArgumentException("Unhandled parameter types: " - + Arrays.asList(check).toString()); + + Arrays.asList(check).toString()); } } @@ -309,7 +309,7 @@ public String issueLabel(final EObject check) { return _issueLabel(xIssueExpression); } else { throw new IllegalArgumentException("Unhandled parameter types: " - + Arrays.asList(check).toString()); + + Arrays.asList(check).toString()); } } } diff --git a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/jvmmodel/CheckJvmModelInferrer.java b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/jvmmodel/CheckJvmModelInferrer.java index 11505a2d2..79f0bab3a 100644 --- a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/jvmmodel/CheckJvmModelInferrer.java +++ b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/jvmmodel/CheckJvmModelInferrer.java @@ -57,13 +57,11 @@ import org.eclipse.xtext.xbase.lib.StringExtensions; import com.avaloq.tools.ddk.check.CheckConstants; -import com.avaloq.tools.ddk.check.check.Category; import com.avaloq.tools.ddk.check.check.Check; import com.avaloq.tools.ddk.check.check.CheckCatalog; import com.avaloq.tools.ddk.check.check.Context; import com.avaloq.tools.ddk.check.check.FormalParameter; import com.avaloq.tools.ddk.check.check.Implementation; -import com.avaloq.tools.ddk.check.check.Member; import com.avaloq.tools.ddk.check.check.XIssueExpression; import com.avaloq.tools.ddk.check.generator.CheckGeneratorExtensions; import com.avaloq.tools.ddk.check.generator.CheckGeneratorNaming; @@ -119,18 +117,18 @@ protected void _infer(final CheckCatalog catalog, final IJvmDeclaredTypeAcceptor } final JvmGenericType catalogClass = jvmTypesBuilder.toClass(catalog, checkGeneratorNaming.qualifiedCatalogClassName(catalog)); final JvmTypeReference issueCodeToLabelMapTypeRef = _typeReferenceBuilder.typeRef(ImmutableMap.class, _typeReferenceBuilder.typeRef(String.class), _typeReferenceBuilder.typeRef(String.class)); - acceptor.accept(catalogClass, (final JvmGenericType it) -> { + acceptor.accept(catalogClass, it -> { final JvmTypeReference parentType = checkedTypeRef(catalog, AbstractIssue.class); if (parentType != null) { it.getSuperTypes().add(parentType); } - Iterables.addAll(it.getAnnotations(), createAnnotation(checkedTypeRef(catalog, Singleton.class), (final JvmAnnotationReference it1) -> { + Iterables.addAll(it.getAnnotations(), createAnnotation(checkedTypeRef(catalog, Singleton.class), it1 -> { })); jvmTypesBuilder.setDocumentation(it, "Issues for " + catalog.getName() + "."); Iterables.addAll(it.getMembers(), createInjectedField(catalog, "checkConfigurationStoreService", checkedTypeRef(catalog, ICheckConfigurationStoreService.class))); // Create map of issue code to label and associated getter - it.getMembers().add(jvmTypesBuilder.toField(catalog, checkGeneratorNaming.issueCodeToLabelMapFieldName(), issueCodeToLabelMapTypeRef, (final JvmField it1) -> { + it.getMembers().add(jvmTypesBuilder.toField(catalog, checkGeneratorNaming.issueCodeToLabelMapFieldName(), issueCodeToLabelMapTypeRef, it1 -> { it1.setStatic(true); it1.setFinal(true); // Get all issue codes and labels @@ -148,17 +146,9 @@ protected void _infer(final CheckCatalog catalog, final IJvmDeclaredTypeAcceptor throw new IllegalArgumentException("Multiple issues found with qualified issue code name: " + qualifiedIssueCodeName); } } - jvmTypesBuilder.setInitializer(it1, (final ITreeAppendable appendable) -> { + jvmTypesBuilder.setInitializer(it1, appendable -> { final StringConcatenation builder = new StringConcatenation(); - builder.append(ImmutableMap.class.getSimpleName()); - builder.append(".<"); - builder.append(String.class.getSimpleName()); - builder.append(", "); - builder.append(String.class.getSimpleName()); - builder.append(">builderWithExpectedSize("); - builder.append(sortedUniqueQualifiedIssueCodeNamesAndLabels.entrySet().size()); - builder.append(")"); - builder.newLineIfNotEmpty(); + builder.append("ImmutableMap.builderWithExpectedSize(%d)\n".formatted(sortedUniqueQualifiedIssueCodeNamesAndLabels.entrySet().size())); for (final Map.Entry qualifiedIssueCodeNameAndLabel : sortedUniqueQualifiedIssueCodeNamesAndLabels.entrySet()) { builder.append(" "); builder.append(".put("); @@ -174,7 +164,7 @@ protected void _infer(final CheckCatalog catalog, final IJvmDeclaredTypeAcceptor appendable.append(builder); }); })); - it.getMembers().add(jvmTypesBuilder.toMethod(catalog, checkGeneratorNaming.fieldGetterName(checkGeneratorNaming.issueCodeToLabelMapFieldName()), issueCodeToLabelMapTypeRef, (final JvmOperation it1) -> { + it.getMembers().add(jvmTypesBuilder.toMethod(catalog, checkGeneratorNaming.fieldGetterName(checkGeneratorNaming.issueCodeToLabelMapFieldName()), issueCodeToLabelMapTypeRef, it1 -> { final StringConcatenation builder = new StringConcatenation(); builder.append("Get map of issue code to label for "); builder.append(catalog.getName()); @@ -188,13 +178,13 @@ protected void _infer(final CheckCatalog catalog, final IJvmDeclaredTypeAcceptor jvmTypesBuilder.setDocumentation(it1, builder.toString()); it1.setStatic(true); it1.setFinal(true); - jvmTypesBuilder.setBody(it1, (final ITreeAppendable appendable) -> appendable.append("return " + checkGeneratorNaming.issueCodeToLabelMapFieldName() + ";")); + jvmTypesBuilder.setBody(it1, appendable -> appendable.append("return " + checkGeneratorNaming.issueCodeToLabelMapFieldName() + ";")); })); - Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(Iterables.concat(ListExtensions.>map(catalog.getAllChecks(), (final Check c) -> createIssue(catalog, c))))); + Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(Iterables.concat(ListExtensions.map(catalog.getAllChecks(), c -> createIssue(catalog, c))))); }); - acceptor.accept(jvmTypesBuilder.toClass(catalog, checkGeneratorNaming.qualifiedValidatorClassName(catalog)), (final JvmGenericType it) -> { + acceptor.accept(jvmTypesBuilder.toClass(catalog, checkGeneratorNaming.qualifiedValidatorClassName(catalog)), it -> { final JvmTypeReference parentType = checkedTypeRef(catalog, DispatchingCheckImpl.class); if (parentType != null) { it.getSuperTypes().add(parentType); @@ -204,40 +194,40 @@ protected void _infer(final CheckCatalog catalog, final IJvmDeclaredTypeAcceptor // Create catalog injections Iterables.addAll(it.getMembers(), createInjectedField(catalog, checkGeneratorNaming.catalogInstanceName(catalog), _typeReferenceBuilder.typeRef(catalogClass))); // Create fields - Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(ListExtensions.map(catalog.getMembers(), (final Member m) -> jvmTypesBuilder.toField(m, m.getName(), m.getType(), (final JvmField it1) -> { + Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(ListExtensions.map(catalog.getMembers(), m -> jvmTypesBuilder.toField(m, m.getName(), m.getType(), it1 -> { jvmTypesBuilder.setInitializer(it1, m.getValue()); jvmTypesBuilder.addAnnotations(it1, m.getAnnotations()); })))); // Create catalog name function - it.getMembers().add(jvmTypesBuilder.toMethod(catalog, "getQualifiedCatalogName", _typeReferenceBuilder.typeRef(String.class), (final JvmOperation it1) -> { - jvmTypesBuilder.setBody(it1, (final ITreeAppendable appendable) -> appendable.append("return \"" + catalog.getPackageName() + "." + catalog.getName() + "\";")); + it.getMembers().add(jvmTypesBuilder.toMethod(catalog, "getQualifiedCatalogName", _typeReferenceBuilder.typeRef(String.class), it1 -> { + jvmTypesBuilder.setBody(it1, appendable -> appendable.append("return \"" + catalog.getPackageName() + "." + catalog.getName() + "\";")); })); // Create getter for map of issue code to label - it.getMembers().add(jvmTypesBuilder.toMethod(catalog, checkGeneratorNaming.fieldGetterName(checkGeneratorNaming.issueCodeToLabelMapFieldName()), issueCodeToLabelMapTypeRef, (final JvmOperation it1) -> { + it.getMembers().add(jvmTypesBuilder.toMethod(catalog, checkGeneratorNaming.fieldGetterName(checkGeneratorNaming.issueCodeToLabelMapFieldName()), issueCodeToLabelMapTypeRef, it1 -> { it1.setFinal(true); - jvmTypesBuilder.setBody(it1, (final ITreeAppendable appendable) -> appendable.append("return " + checkGeneratorNaming.catalogClassName(catalog) + "." + checkGeneratorNaming.fieldGetterName(checkGeneratorNaming.issueCodeToLabelMapFieldName()) + "();")); + jvmTypesBuilder.setBody(it1, appendable -> appendable.append("return " + checkGeneratorNaming.catalogClassName(catalog) + "." + checkGeneratorNaming.fieldGetterName(checkGeneratorNaming.issueCodeToLabelMapFieldName()) + "();")); })); it.getMembers().add(createDispatcherMethod(catalog)); // Create methods for contexts in checks final List checks = catalog.getChecks(); - final Iterable flattenedCategoryChecks = Iterables.concat(ListExtensions.>map(catalog.getCategories(), (final Category cat) -> cat.getChecks())); - final Iterable allChecks = Iterables.concat(checks, flattenedCategoryChecks); - Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(Iterables.concat(IterableExtensions.>map(allChecks, (final Check chk) -> createCheck(chk))))); + final Iterable flattenedCategoryChecks = Iterables.concat(ListExtensions.map(catalog.getCategories(), cat -> cat.getChecks())); + final Iterable allChecks = Iterables.concat(checks, flattenedCategoryChecks); + Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(Iterables.concat(IterableExtensions.map(allChecks, chk -> createCheck(chk))))); // Create methods for stand-alone context implementations - Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(ListExtensions.map(catalog.getImplementations(), (final Implementation impl) -> createCheckMethod(impl.getContext())))); + Iterables.addAll(it.getMembers(), IterableExtensions.filterNull(ListExtensions.map(catalog.getImplementations(), impl -> createCheckMethod(impl.getContext())))); }); - acceptor.accept(jvmTypesBuilder.toClass(catalog, checkGeneratorNaming.qualifiedPreferenceInitializerClassName(catalog)), (final JvmGenericType it) -> { + acceptor.accept(jvmTypesBuilder.toClass(catalog, checkGeneratorNaming.qualifiedPreferenceInitializerClassName(catalog)), it -> { final JvmTypeReference parentType = checkedTypeRef(catalog, AbstractPreferenceInitializer.class); if (parentType != null) { it.getSuperTypes().add(parentType); } - it.getMembers().add(jvmTypesBuilder.toField(catalog, "RUNTIME_NODE_NAME", _typeReferenceBuilder.typeRef(String.class), (final JvmField it1) -> { + it.getMembers().add(jvmTypesBuilder.toField(catalog, "RUNTIME_NODE_NAME", _typeReferenceBuilder.typeRef(String.class), it1 -> { it1.setStatic(true); it1.setFinal(true); - jvmTypesBuilder.setInitializer(it1, (final ITreeAppendable appendable) -> appendable.append("\"" + checkGeneratorExtensions.bundleName(catalog) + "\"")); + jvmTypesBuilder.setInitializer(it1, appendable -> appendable.append("\"" + checkGeneratorExtensions.bundleName(catalog) + "\"")); })); Iterables.addAll(it.getMembers(), createFormalParameterFields(catalog)); Iterables.addAll(it.getMembers(), createPreferenceInitializerMethods(catalog)); @@ -247,14 +237,14 @@ protected void _infer(final CheckCatalog catalog, final IJvmDeclaredTypeAcceptor private JvmOperation createDispatcherMethod(final CheckCatalog catalog) { final JvmTypeReference objectBaseJavaTypeRef = checkedTypeRef(catalog, EObject.class); - return jvmTypesBuilder.toMethod(catalog, "validate", _typeReferenceBuilder.typeRef("void"), (final JvmOperation it) -> { + return jvmTypesBuilder.toMethod(catalog, "validate", _typeReferenceBuilder.typeRef("void"), it -> { it.setVisibility(JvmVisibility.PUBLIC); it.getParameters().add(jvmTypesBuilder.toParameter(catalog, "checkMode", checkedTypeRef(catalog, CheckMode.class))); it.getParameters().add(jvmTypesBuilder.toParameter(catalog, "object", objectBaseJavaTypeRef)); it.getParameters().add(jvmTypesBuilder.toParameter(catalog, "diagnosticCollector", checkedTypeRef(catalog, DiagnosticCollector.class))); - Iterables.addAll(it.getAnnotations(), createAnnotation(checkedTypeRef(catalog, Override.class), (final JvmAnnotationReference it1) -> { + Iterables.addAll(it.getAnnotations(), createAnnotation(checkedTypeRef(catalog, Override.class), it1 -> { })); - jvmTypesBuilder.setBody(it, (final ITreeAppendable out) -> emitDispatcherMethodBody(out, catalog, objectBaseJavaTypeRef)); + jvmTypesBuilder.setBody(it, out -> emitDispatcherMethodBody(out, catalog, objectBaseJavaTypeRef)); }); } @@ -266,9 +256,9 @@ private void emitDispatcherMethodBody(final ITreeAppendable out, final CheckCata * we can include categorized checks by using getAllChecks(). * We only consider Context objects with a typed contextVariable. */ - final Iterable checkContexts = Iterables.concat(ListExtensions.>map(catalog.getAllChecks(), (final Check chk) -> chk.getContexts())); - final Iterable implementationContexts = IterableExtensions.filterNull(ListExtensions.map(catalog.getImplementations(), (final Implementation impl) -> impl.getContext())); - final Iterable allContexts = IterableExtensions.filter(Iterables.concat(checkContexts, implementationContexts), (final Context ctx) -> { + final Iterable checkContexts = Iterables.concat(ListExtensions.map(catalog.getAllChecks(), chk -> chk.getContexts())); + final Iterable implementationContexts = IterableExtensions.filterNull(ListExtensions.map(catalog.getImplementations(), impl -> impl.getContext())); + final Iterable allContexts = IterableExtensions.filter(Iterables.concat(checkContexts, implementationContexts), ctx -> { JvmTypeReference type = null; if (ctx.getContextVariable() != null) { type = ctx.getContextVariable().getType(); @@ -317,7 +307,7 @@ private void emitInstanceOfConditionals(final ITreeAppendable out, final List contextVarTypes = ListExtensions.map(contexts, (final Context x) -> x.getContextVariable().getType()); + final List contextVarTypes = ListExtensions.map(contexts, x -> x.getContextVariable().getType()); final InstanceOfCheckOrderer.Forest forest = InstanceOfCheckOrderer.orderTypes(contextVarTypes); emitInstanceOfTree(out, forest, null, contextsByVarType, catalog, baseTypeName, 0); @@ -391,21 +381,21 @@ private String toJavaLiteral(final String... strings) { private Iterable createInjectedField(final CheckCatalog context, final String fieldName, final JvmTypeReference type) { // Generate @Inject private typeName fieldName; if (type == null) { - return Collections.emptyList(); + return Collections.emptyList(); } final JvmField field = typesFactory.createJvmField(); field.setSimpleName(fieldName); field.setVisibility(JvmVisibility.PRIVATE); field.setType(jvmTypesBuilder.cloneWithProxies(type)); - Iterables.addAll(field.getAnnotations(), createAnnotation(checkedTypeRef(context, Inject.class), (final JvmAnnotationReference it) -> { + Iterables.addAll(field.getAnnotations(), createAnnotation(checkedTypeRef(context, Inject.class), it -> { })); - return Collections.singleton(field); + return Collections.singleton(field); } private Iterable createCheck(final Check chk) { // If we don't have FormalParameters, there's no need to do all this song and dance with inner classes. if (chk.getFormalParameters().isEmpty()) { - return ListExtensions.map(chk.getContexts(), (final Context ctx) -> createCheckMethod(ctx)); + return ListExtensions.map(chk.getContexts(), ctx -> createCheckMethod(ctx)); } else { return createCheckWithParameters(chk); } @@ -419,22 +409,22 @@ private Iterable createCheckWithParameters(final Check chk) { // This is the only way I found to make those formal parameters visible in the check constraints... // The generated Java looks a bit strange, because we suppress actually generating these fields, as we // don't use them; we only need them for scoping based on this inferred model. - final List newMembers = Lists.newArrayList(); + final List newMembers = Lists.newArrayList(); // First the class - final JvmGenericType checkClass = jvmTypesBuilder.toClass(chk, StringExtensions.toFirstUpper(chk.getName()) + "Class", (final JvmGenericType it) -> { + final JvmGenericType checkClass = jvmTypesBuilder.toClass(chk, StringExtensions.toFirstUpper(chk.getName()) + "Class", it -> { it.getSuperTypes().add(_typeReferenceBuilder.typeRef(Object.class)); it.setVisibility(JvmVisibility.PRIVATE); // Add a fields for the parameters, so that they can be linked. We suppress generation of these fields in the generator, // and replace all references by calls to the getter function in the catalog. - Iterables.addAll(it.getMembers(), IterableExtensions.map(IterableExtensions.filter(chk.getFormalParameters(), (final FormalParameter f) -> f.getType() != null && f.getName() != null), (final FormalParameter f) -> jvmTypesBuilder.toField(f, f.getName(), f.getType(), (final JvmField it1) -> it1.setFinal(true)))); + Iterables.addAll(it.getMembers(), IterableExtensions.map(IterableExtensions.filter(chk.getFormalParameters(), f -> f.getType() != null && f.getName() != null), f -> jvmTypesBuilder.toField(f, f.getName(), f.getType(), it1 -> it1.setFinal(true)))); }); newMembers.add(checkClass); - newMembers.add(jvmTypesBuilder.toField(chk, StringExtensions.toFirstLower(chk.getName()) + "Impl", _typeReferenceBuilder.typeRef(checkClass), (final JvmField it) -> { - jvmTypesBuilder.setInitializer(it, (final ITreeAppendable appendable) -> appendable.append("new " + checkClass.getSimpleName() + "()")); + newMembers.add(jvmTypesBuilder.toField(chk, StringExtensions.toFirstLower(chk.getName()) + "Impl", _typeReferenceBuilder.typeRef(checkClass), it -> { + jvmTypesBuilder.setInitializer(it, appendable -> appendable.append("new " + checkClass.getSimpleName() + "()")); })); - Iterables.addAll(newMembers, IterableExtensions.filterNull(ListExtensions.map(chk.getContexts(), (final Context ctx) -> createCheckCaller(ctx, chk)))); + Iterables.addAll(newMembers, IterableExtensions.filterNull(ListExtensions.map(chk.getContexts(), ctx -> createCheckCaller(ctx, chk)))); // If we create these above in the class initializer, the types of the context variables somehow are not resolved yet. - Iterables.addAll(checkClass.getMembers(), IterableExtensions.filterNull(ListExtensions.map(chk.getContexts(), (final Context ctx) -> createCheckExecution(ctx)))); + Iterables.addAll(checkClass.getMembers(), IterableExtensions.filterNull(ListExtensions.map(chk.getContexts(), ctx -> createCheckExecution(ctx)))); return newMembers; } @@ -449,7 +439,7 @@ private JvmOperation createCheckExecution(final Context ctx) { } final String functionName = "run" + StringExtensions.toFirstUpper(simpleName); // CPD-OFF — migrated Xtend generator code, kept faithful - return jvmTypesBuilder.toMethod(ctx, functionName, _typeReferenceBuilder.typeRef("void"), (final JvmOperation it) -> { + return jvmTypesBuilder.toMethod(ctx, functionName, _typeReferenceBuilder.typeRef("void"), it -> { final String parameterName = ctx.getContextVariable().getName() == null ? CheckConstants.IT : ctx.getContextVariable().getName(); it.getParameters().add(jvmTypesBuilder.toParameter(ctx, parameterName, ctx.getContextVariable().getType())); it.getParameters().add(jvmTypesBuilder.toParameter(ctx, "diagnosticCollector", checkedTypeRef(ctx, DiagnosticCollector.class))); @@ -461,7 +451,7 @@ private JvmOperation createCheckExecution(final Context ctx) { private Iterable createCheckAnnotation(final Context ctx) { final JvmTypeReference checkTypeTypeRef = checkedTypeRef(ctx, CheckType.class); if (checkTypeTypeRef == null) { - return Collections.emptyList(); + return Collections.emptyList(); } final XFeatureCall featureCall = XbaseFactory.eINSTANCE.createXFeatureCall(); featureCall.setFeature(checkTypeTypeRef.getType()); @@ -480,7 +470,7 @@ private Iterable createCheckAnnotation(final Context ctx // We add it as a separate model to the context's resource. ctx.eResource().getContents().add(memberCall); - return createAnnotation(checkedTypeRef(ctx, org.eclipse.xtext.validation.Check.class), (final JvmAnnotationReference it) -> { + return createAnnotation(checkedTypeRef(ctx, org.eclipse.xtext.validation.Check.class), it -> { it.getExplicitValues().add(jvmTypesBuilder.toJvmAnnotationValue(memberCall)); }); } @@ -499,12 +489,12 @@ private JvmOperation createCheckCaller(final Context ctx, final Check chk) { // into the XBlockExpression of ctx.constraint. Just copying them doesn't work; modifies the source model! // Therefore, we generate something new: each check becomes a local class - return jvmTypesBuilder.toMethod(ctx, functionName, _typeReferenceBuilder.typeRef("void"), (final JvmOperation it) -> { + return jvmTypesBuilder.toMethod(ctx, functionName, _typeReferenceBuilder.typeRef("void"), it -> { it.getParameters().add(jvmTypesBuilder.toParameter(ctx, "context", ctx.getContextVariable().getType())); it.getParameters().add(jvmTypesBuilder.toParameter(ctx, "diagnosticCollector", checkedTypeRef(ctx, DiagnosticCollector.class))); Iterables.addAll(it.getAnnotations(), createCheckAnnotation(ctx)); jvmTypesBuilder.setDocumentation(it, functionName + "."); // Well, that's not very helpful, but it is what the old compiler did... - jvmTypesBuilder.setBody(it, (final ITreeAppendable appendable) -> { + jvmTypesBuilder.setBody(it, appendable -> { final JvmTypeReference innerContextVariableType = ctx.getContextVariable().getType(); String innerSimpleName = null; if (innerContextVariableType != null) { @@ -522,7 +512,7 @@ private JvmOperation createCheckMethod(final Context ctx) { } final String functionName = generateContextMethodName(ctx); - return jvmTypesBuilder.toMethod(ctx, functionName, _typeReferenceBuilder.typeRef("void"), (final JvmOperation it) -> { + return jvmTypesBuilder.toMethod(ctx, functionName, _typeReferenceBuilder.typeRef("void"), it -> { final String parameterName = ctx.getContextVariable().getName() == null ? CheckConstants.IT : ctx.getContextVariable().getName(); it.getParameters().add(jvmTypesBuilder.toParameter(ctx, parameterName, ctx.getContextVariable().getType())); it.getParameters().add(jvmTypesBuilder.toParameter(ctx, "diagnosticCollector", checkedTypeRef(ctx, DiagnosticCollector.class))); @@ -554,7 +544,7 @@ private String generateContextMethodName(final Context ctx) { // CHECKSTYLE:CHECK-OFF LambdaBodyLength the model-inference closures mirror the Xtext JvmTypesBuilder API and are kept whole private Iterable createIssue(final CheckCatalog catalog, final Check check) { - final List members = Lists.newArrayList(); + final List members = Lists.newArrayList(); for (final FormalParameter parameter : check.getFormalParameters()) { final JvmTypeReference returnType = parameter.getType(); if (returnType != null && !returnType.eIsProxy()) { @@ -582,7 +572,7 @@ private Iterable createIssue(final CheckCatalog catalog, final Check // as default value is just a safety measure if something went wrong and the property shouldn't be set. } final String javaDefaultValue = checkGeneratorNaming.preferenceInitializerClassName(catalog) + "." + defaultName; - members.add(jvmTypesBuilder.toMethod(parameter, checkGeneratorNaming.formalParameterGetterName(parameter), returnType, (final JvmOperation it) -> { + members.add(jvmTypesBuilder.toMethod(parameter, checkGeneratorNaming.formalParameterGetterName(parameter), returnType, it -> { final StringConcatenation builder = new StringConcatenation(); builder.append("Gets the run-time value of formal parameter "); builder.append(parameter.getName()); @@ -609,21 +599,21 @@ private Iterable createIssue(final CheckCatalog catalog, final Check if (eObjectTypeRef != null) { it.getParameters().add(jvmTypesBuilder.toParameter(parameter, "context", eObjectTypeRef)); } - jvmTypesBuilder.setBody(it, (final ITreeAppendable appendable) -> appendable.append("return checkConfigurationStoreService.getCheckConfigurationStore(context)." + operation + "(\"" + parameterKey + "\", " + javaDefaultValue + ");")); + jvmTypesBuilder.setBody(it, appendable -> appendable.append("return checkConfigurationStoreService.getCheckConfigurationStore(context)." + operation + "(\"" + parameterKey + "\", " + javaDefaultValue + ");")); })); } // end if } // end for - members.add(jvmTypesBuilder.toMethod(check, "get" + StringExtensions.toFirstUpper(check.getName()) + "Message", _typeReferenceBuilder.typeRef(String.class), (final JvmOperation it) -> { + members.add(jvmTypesBuilder.toMethod(check, "get" + StringExtensions.toFirstUpper(check.getName()) + "Message", _typeReferenceBuilder.typeRef(String.class), it -> { jvmTypesBuilder.setDocumentation(it, CheckJvmModelInferrerUtil.GET_MESSAGE_DOCUMENTATION); // Generate one parameter "Object... bindings" it.setVarArgs(true); it.getParameters().add(jvmTypesBuilder.toParameter(check, "bindings", jvmTypesBuilder.addArrayTypeDimension(_typeReferenceBuilder.typeRef(Object.class)))); - jvmTypesBuilder.setBody(it, (final ITreeAppendable appendable) -> appendable.append("return org.eclipse.osgi.util.NLS.bind(\"" + Strings.convertToJavaString(check.getMessage()) + "\", bindings);")); + jvmTypesBuilder.setBody(it, appendable -> appendable.append("return org.eclipse.osgi.util.NLS.bind(\"" + Strings.convertToJavaString(check.getMessage()) + "\", bindings);")); // TODO (minor): how to get NLS into the imports? })); final JvmTypeReference severityType = checkedTypeRef(check, SeverityKind.class); if (severityType != null) { - members.add(jvmTypesBuilder.toMethod(check, "get" + StringExtensions.toFirstUpper(check.getName()) + "SeverityKind", severityType, (final JvmOperation it) -> { + members.add(jvmTypesBuilder.toMethod(check, "get" + StringExtensions.toFirstUpper(check.getName()) + "SeverityKind", severityType, it -> { final StringConcatenation builder = new StringConcatenation(); builder.append("Gets the {@link SeverityKind severity kind} of check"); builder.newLine(); @@ -660,7 +650,7 @@ private Iterable createIssue(final CheckCatalog catalog, final Check if (eObjectTypeRef != null) { it.getParameters().add(jvmTypesBuilder.toParameter(check, "context", eObjectTypeRef)); } - jvmTypesBuilder.setBody(it, (final ITreeAppendable appendable) -> { + jvmTypesBuilder.setBody(it, appendable -> { final StringConcatenation bodyBuilder = new StringConcatenation(); bodyBuilder.append("final int result = checkConfigurationStoreService.getCheckConfigurationStore(context).getInt(\""); bodyBuilder.append(CheckPropertiesGenerator.checkSeverityKey(check)); @@ -683,14 +673,14 @@ private Iterable createFormalParameterFields(final CheckCatalog catal // For each formal parameter, create a public static final field with a unique name derived from the formal parameter and // set it to its right-hand side expression. We let Java evaluate this! final List checks = catalog.getChecks(); - final Iterable flattenedCategoryChecks = Iterables.concat(ListExtensions.>map(catalog.getCategories(), (final Category cat) -> cat.getChecks())); - final Iterable allChecks = Iterables.concat(checks, flattenedCategoryChecks); - final List result = Lists.newArrayList(); + final Iterable flattenedCategoryChecks = Iterables.concat(ListExtensions.map(catalog.getCategories(), cat -> cat.getChecks())); + final Iterable allChecks = Iterables.concat(checks, flattenedCategoryChecks); + final List result = Lists.newArrayList(); for (final Check c : allChecks) { for (final FormalParameter parameter : c.getFormalParameters()) { if (parameter.getType() != null && parameter.getRight() != null) { final String defaultName = CheckGeneratorExtensions.splitCamelCase(checkGeneratorNaming.formalParameterGetterName(parameter)).toUpperCase() + "_DEFAULT"; - result.add(jvmTypesBuilder.toField(parameter, defaultName, parameter.getType(), (final JvmField it) -> { + result.add(jvmTypesBuilder.toField(parameter, defaultName, parameter.getType(), it -> { it.setVisibility(JvmVisibility.PUBLIC); it.setFinal(true); it.setStatic(true); @@ -705,22 +695,22 @@ private Iterable createFormalParameterFields(final CheckCatalog catal // CHECKSTYLE:CHECK-OFF LambdaBodyLength the model-inference closures mirror the Xtext JvmTypesBuilder API and are kept whole private Iterable createPreferenceInitializerMethods(final CheckCatalog catalog) { final JvmTypeReference prefStore = checkedTypeRef(catalog, IEclipsePreferences.class); - final List result = Lists.newArrayList(); + final List result = Lists.newArrayList(); if (prefStore != null) { - result.add(jvmTypesBuilder.toMethod(catalog, "initializeDefaultPreferences", _typeReferenceBuilder.typeRef("void"), (final JvmOperation it) -> { - Iterables.addAll(it.getAnnotations(), createAnnotation(checkedTypeRef(catalog, Override.class), (final JvmAnnotationReference it1) -> { + result.add(jvmTypesBuilder.toMethod(catalog, "initializeDefaultPreferences", _typeReferenceBuilder.typeRef("void"), it -> { + Iterables.addAll(it.getAnnotations(), createAnnotation(checkedTypeRef(catalog, Override.class), it1 -> { })); it.setVisibility(JvmVisibility.PUBLIC); - jvmTypesBuilder.setBody(it, (final ITreeAppendable appendable) -> appendable.append("IEclipsePreferences preferences = org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE.getNode(RUNTIME_NODE_NAME);\n\ninitializeSeverities(preferences);\ninitializeFormalParameters(preferences);")); + jvmTypesBuilder.setBody(it, appendable -> appendable.append("IEclipsePreferences preferences = org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE.getNode(RUNTIME_NODE_NAME);\n\ninitializeSeverities(preferences);\ninitializeFormalParameters(preferences);")); })); final List checks = catalog.getChecks(); - final Iterable flattenedCategoryChecks = Iterables.concat(ListExtensions.>map(catalog.getCategories(), (final Category cat) -> cat.getChecks())); - final Iterable allChecks = Iterables.concat(checks, flattenedCategoryChecks); - result.add(jvmTypesBuilder.toMethod(catalog, "initializeSeverities", _typeReferenceBuilder.typeRef("void"), (final JvmOperation it) -> { + final Iterable flattenedCategoryChecks = Iterables.concat(ListExtensions.map(catalog.getCategories(), cat -> cat.getChecks())); + final Iterable allChecks = Iterables.concat(checks, flattenedCategoryChecks); + result.add(jvmTypesBuilder.toMethod(catalog, "initializeSeverities", _typeReferenceBuilder.typeRef("void"), it -> { it.setVisibility(JvmVisibility.PRIVATE); it.getParameters().add(jvmTypesBuilder.toParameter(catalog, "preferences", prefStore)); - jvmTypesBuilder.setBody(it, (final ITreeAppendable appendable) -> { + jvmTypesBuilder.setBody(it, appendable -> { final StringConcatenation builder = new StringConcatenation(); for (final Check c : allChecks) { builder.newLineIfNotEmpty(); @@ -734,10 +724,10 @@ private Iterable createPreferenceInitializerMethods(final CheckCatalo appendable.append(builder); }); })); - result.add(jvmTypesBuilder.toMethod(catalog, "initializeFormalParameters", _typeReferenceBuilder.typeRef("void"), (final JvmOperation it) -> { + result.add(jvmTypesBuilder.toMethod(catalog, "initializeFormalParameters", _typeReferenceBuilder.typeRef("void"), it -> { it.setVisibility(JvmVisibility.PRIVATE); it.getParameters().add(jvmTypesBuilder.toParameter(catalog, "preferences", jvmTypesBuilder.cloneWithProxies(prefStore))); - jvmTypesBuilder.setBody(it, (final ITreeAppendable appendable) -> { + jvmTypesBuilder.setBody(it, appendable -> { for (final Check c : allChecks) { for (final FormalParameter parameter : c.getFormalParameters()) { if (parameter.getRight() != null) { @@ -749,7 +739,7 @@ private Iterable createPreferenceInitializerMethods(final CheckCatalo // Marshal lists. final List args = ((JvmParameterizedTypeReference) jvmType).getArguments(); if (args != null && args.size() == 1) { - final String baseTypeName = IterableExtensions.head(args).getSimpleName(); + final String baseTypeName = IterableExtensions.head(args).getSimpleName(); final StringConcatenation builder = new StringConcatenation(); builder.append("preferences.put(\""); builder.append(key); @@ -806,14 +796,14 @@ private Iterable createPreferenceInitializerMethods(final CheckCatalo private Iterable createAnnotation(final JvmTypeReference typeRef, final Procedure1 initializer) { if (typeRef == null) { - return Collections.emptyList(); + return Collections.emptyList(); } final JvmAnnotationReference annotation = typesFactory.createJvmAnnotationReference(); annotation.setAnnotation((JvmAnnotationType) typeRef.getType()); Objects.requireNonNull(initializer, "Initializer is null").apply(annotation); - return Collections.singletonList(annotation); + return Collections.singletonList(annotation); } // Error handling etc. @@ -853,7 +843,7 @@ public void infer(final EObject catalog, final IJvmDeclaredTypeAcceptor acceptor } else if (catalog != null) { _infer(catalog, acceptor, preIndexingPhase); } else { - throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.asList(catalog, acceptor, preIndexingPhase).toString()); + throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.asList(catalog, acceptor, preIndexingPhase).toString()); } } }