Skip to content

Commit d66599e

Browse files
joaodinissfclaude
andcommitted
refactor: migrate Xtend to Java - com.avaloq.tools.ddk.xtext.check.generator
Convert the module's two remaining Xtend generator fragments to hand-written Java, byte-faithful to the xtend-gen ground truth: CheckValidatorFragment2 and quickfix/CheckQuickfixProviderFragment2 (StringConcatenation(Client) templates preserved exactly, bracketed with CHECKSTYLE:CONSTANTS-OFF/ON). Remove the now-unused per-module Xtend build wiring (xtend-gen entry in build.properties/.classpath, xtextBuilder/xtextNature in .project, the xtend-gen directory). Require-Bundle is unchanged: the templates legitimately use org.eclipse.xtend2.lib, provided transitively via org.eclipse.xtext(.xtext.generator). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b43b7c7 commit d66599e

7 files changed

Lines changed: 112 additions & 105 deletions

File tree

com.avaloq.tools.ddk.xtext.check.generator/.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="src" path="xtend-gen"/>
54
<classpathentry kind="output" path="bin"/>
65
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
76
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">

com.avaloq.tools.ddk.xtext.check.generator/.project

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
<arguments>
2121
</arguments>
2222
</buildCommand>
23-
<buildCommand>
24-
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
25-
<arguments>
26-
</arguments>
27-
</buildCommand>
2823
<buildCommand>
2924
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
3025
<arguments>
@@ -44,7 +39,6 @@
4439
<natures>
4540
<nature>org.eclipse.jdt.core.javanature</nature>
4641
<nature>org.eclipse.pde.PluginNature</nature>
47-
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
4842
<nature>net.sourceforge.pmd.eclipse.plugin.pmdNature</nature>
4943
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
5044
<nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
source.. = src/,\
2-
xtend-gen/
1+
source.. = src/
32
output.. = bin/
43
bin.includes = META-INF/,\
54
.

com.avaloq.tools.ddk.xtext.check.generator/src/com/avaloq/tools/ddk/xtext/check/generator/CheckValidatorFragment2.xtend renamed to com.avaloq.tools.ddk.xtext.check.generator/src/com/avaloq/tools/ddk/xtext/check/generator/CheckValidatorFragment2.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@
99
* Avaloq Group AG - initial API and implementation
1010
*******************************************************************************/
1111

12-
package com.avaloq.tools.ddk.xtext.check.generator
12+
package com.avaloq.tools.ddk.xtext.check.generator;
1313

14-
import org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment
15-
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
16-
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess
17-
import com.avaloq.tools.ddk.check.runtime.validation.AbstractCheckValidator
18-
import com.avaloq.tools.ddk.check.runtime.validation.DefaultCheckValidator
14+
import org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment;
15+
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess;
16+
import org.eclipse.xtext.xtext.generator.model.TypeReference;
1917

20-
class CheckValidatorFragment2 extends AbstractXtextGeneratorFragment {
18+
import com.avaloq.tools.ddk.check.runtime.validation.AbstractCheckValidator;
19+
import com.avaloq.tools.ddk.check.runtime.validation.DefaultCheckValidator;
2120

22-
static val RUNTIME_PLUGIN = "com.avaloq.tools.ddk.check.runtime.core"
2321

24-
override generate() {
25-
new GuiceModuleAccess.BindingFactory().addTypeToTypeEagerSingleton(AbstractCheckValidator.typeRef,
26-
DefaultCheckValidator.typeRef).contributeTo(language.runtimeGenModule)
22+
@SuppressWarnings("nls")
23+
public class CheckValidatorFragment2 extends AbstractXtextGeneratorFragment {
2724

28-
if (projectConfig.runtime.manifest !== null) {
29-
projectConfig.runtime.manifest.requiredBundles += RUNTIME_PLUGIN
25+
private static final String RUNTIME_PLUGIN = "com.avaloq.tools.ddk.check.runtime.core";
26+
27+
@Override
28+
public void generate() {
29+
new GuiceModuleAccess.BindingFactory().addTypeToTypeEagerSingleton(TypeReference.typeRef(AbstractCheckValidator.class),
30+
TypeReference.typeRef(DefaultCheckValidator.class)).contributeTo(getLanguage().getRuntimeGenModule());
31+
32+
if (getProjectConfig().getRuntime().getManifest() != null) {
33+
getProjectConfig().getRuntime().getManifest().getRequiredBundles().add(RUNTIME_PLUGIN);
3034
}
3135
}
32-
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016 Avaloq Group AG and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Avaloq Group AG - initial API and implementation
10+
*******************************************************************************/
11+
12+
package com.avaloq.tools.ddk.xtext.check.generator.quickfix;
13+
14+
import org.eclipse.xtend2.lib.StringConcatenationClient;
15+
import org.eclipse.xtext.Grammar;
16+
import org.eclipse.xtext.GrammarUtil;
17+
import org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment;
18+
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming;
19+
import org.eclipse.xtext.xtext.generator.model.FileAccessFactory;
20+
import org.eclipse.xtext.xtext.generator.model.TypeReference;
21+
22+
import com.google.inject.Inject;
23+
24+
25+
@SuppressWarnings("nls")
26+
public class CheckQuickfixProviderFragment2 extends AbstractXtextGeneratorFragment {
27+
28+
private static final String UI_PLUGIN = "com.avaloq.tools.ddk.check.runtime.ui";
29+
30+
@Inject
31+
private XtextGeneratorNaming xtextGeneratorNaming;
32+
33+
@Inject
34+
private FileAccessFactory fileAccessFactory;
35+
36+
protected TypeReference getQuickfixProviderClass(final Grammar g) {
37+
return new TypeReference(
38+
xtextGeneratorNaming.getEclipsePluginBasePackage(g) + ".quickfix." + GrammarUtil.getSimpleName(g) + "QuickfixProvider");
39+
}
40+
41+
@Override
42+
public void generate() {
43+
if (getProjectConfig().getEclipsePlugin().getManifest() != null) {
44+
getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles().add(UI_PLUGIN);
45+
}
46+
47+
if (getProjectConfig().getEclipsePlugin().getSrc() != null) {
48+
generateQuickfixProvider();
49+
}
50+
51+
if (getProjectConfig().getEclipsePlugin().getPluginXml() != null) {
52+
addRegistrationToPluginXml();
53+
}
54+
}
55+
56+
protected void generateQuickfixProvider() {
57+
final StringConcatenationClient content = new StringConcatenationClient() {
58+
@Override
59+
protected void appendTo(final TargetStringConcatenation builder) {
60+
builder.append("""
61+
public class %s extends DefaultCheckQuickfixProvider {
62+
63+
// @Fix(MyJavaValidator.INVALID_NAME)
64+
// public void capitalizeName(final Issue issue, IssueResolutionAcceptor acceptor) {
65+
// acceptor.accept(issue, "Capitalize name", "Capitalize the name.", "upcase.png", new IModification() {
66+
// public void apply(IModificationContext context) throws BadLocationException {
67+
// IXtextDocument xtextDocument = context.getXtextDocument();
68+
// String firstLetter = xtextDocument.get(issue.getOffset(), 1);
69+
// xtextDocument.replace(issue.getOffset(), 1, firstLetter.toUpperCase());
70+
// }
71+
// });
72+
// }
73+
74+
}
75+
""".formatted(getQuickfixProviderClass(getGrammar()).getSimpleName()));
76+
}
77+
};
78+
fileAccessFactory.createJavaFile(getQuickfixProviderClass(getGrammar()), content).writeTo(getProjectConfig().getEclipsePlugin().getSrc());
79+
}
80+
81+
protected void addRegistrationToPluginXml() {
82+
final TypeReference executableExtensionFactory = xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(getGrammar());
83+
getProjectConfig().getEclipsePlugin().getPluginXml().getEntries().add("""
84+
<!-- quickfix marker resolution generator -->
85+
<extension
86+
point="org.eclipse.ui.ide.markerResolution">
87+
<markerResolutionGenerator
88+
class="%s:org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator">
89+
</markerResolutionGenerator>
90+
</extension>
91+
""".formatted(executableExtensionFactory));
92+
}
93+
}

com.avaloq.tools.ddk.xtext.check.generator/src/com/avaloq/tools/ddk/xtext/check/generator/quickfix/CheckQuickfixProviderFragment2.xtend

Lines changed: 0 additions & 82 deletions
This file was deleted.

com.avaloq.tools.ddk.xtext.check.generator/xtend-gen/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)