Skip to content

Commit ecf06e2

Browse files
authored
Completely remove usage of Eclipse language server (microsoft#7552)
Completes the removal of Eclipse language server usage in the Java generator.
1 parent 422bb99 commit ecf06e2

40 files changed

+119
-4209
lines changed

packages/http-client-java/generator/http-client-generator-core/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@
6262
<artifactId>google-java-format</artifactId>
6363
<version>1.24.0</version>
6464
</dependency>
65-
<dependency>
66-
<groupId>org.apache.ant</groupId>
67-
<artifactId>ant</artifactId>
68-
<version>1.10.14</version>
69-
</dependency>
70-
<dependency>
71-
<groupId>org.eclipse.lsp4j</groupId>
72-
<artifactId>org.eclipse.lsp4j</artifactId>
73-
<version>0.21.1</version>
74-
</dependency>
7565
<dependency>
7666
<groupId>org.atteo</groupId>
7767
<artifactId>evo-inflector</artifactId>

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/Javagen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private boolean generateJava(JavaSettings settings) {
7878
// Step 4: Print to files
7979
// Then for each formatted file write the file. This is done synchronously as there is potential race
8080
// conditions that can lead to deadlocking.
81-
new Postprocessor(this, settings.isUseEclipseLanguageServer()).postProcess(javaPackage.getJavaFiles()
81+
new Postprocessor(this).postProcess(javaPackage.getJavaFiles()
8282
.stream()
8383
.collect(Collectors.toMap(JavaFile::getFilePath, file -> file.getContents().toString())));
8484

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/customization/ClassCustomization.java

Lines changed: 19 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -3,202 +3,41 @@
33

44
package com.microsoft.typespec.http.client.generator.core.customization;
55

6+
import com.github.javaparser.StaticJavaParser;
67
import com.github.javaparser.ast.CompilationUnit;
7-
import java.lang.reflect.Modifier;
8-
import java.util.List;
98
import java.util.function.Consumer;
109

1110
/**
1211
* The class level customization for an AutoRest generated class.
1312
*/
14-
public interface ClassCustomization extends CodeCustomization {
15-
/**
16-
* Gets the name of the class this customization is using.
17-
*
18-
* @return The name of the class.
19-
*/
20-
String getClassName();
13+
public final class ClassCustomization extends CodeCustomization {
14+
private final String className;
2115

22-
/**
23-
* Adds imports to the class.
24-
*
25-
* @param imports Imports to add.
26-
* @return A new {@link ClassCustomization} updated with the new imports for chaining.
27-
*/
28-
ClassCustomization addImports(String... imports);
29-
30-
/**
31-
* Adds a static block to the class. The {@code staticCodeBlock} should include the static keyword followed by
32-
* the static code.
33-
*
34-
* @param staticCodeBlock The static code block including the static keyword.
35-
* @return The updated {@link ClassCustomization}.
36-
*/
37-
ClassCustomization addStaticBlock(String staticCodeBlock);
38-
39-
/**
40-
* Adds a static block to the class.
41-
*
42-
* @param staticCodeBlock The static code block. If this is {@code null} or an empty string, the class is not
43-
* modified and the {@link ClassCustomization} instance is returned without any change.
44-
* @param importsToAdd The list of imports to add to the class.
45-
* @return The updated {@link ClassCustomization}.
46-
*/
47-
ClassCustomization addStaticBlock(String staticCodeBlock, List<String> importsToAdd);
48-
49-
/**
50-
* Gets the method level customization for a method in the class.
51-
*
52-
* @param methodNameOrSignature the method name or signature
53-
* @return the method level customization
54-
*/
55-
MethodCustomization getMethod(String methodNameOrSignature);
16+
ClassCustomization(Editor editor, String packageName, String className) {
17+
super(editor, packageName, className);
18+
this.className = className;
19+
}
5620

5721
/**
58-
* Gets the constructor level customization for a constructor in the class.
59-
* <p>
60-
* If only the constructor name is passed and the class has multiple constructors an error will be thrown to prevent
61-
* ambiguous runtime behavior.
62-
*
63-
* @param constructorNameOrSignature The constructor name or signature.
64-
* @return The constructor level customization.
65-
* @throws IllegalStateException If only the constructor name is passed and the class has multiple constructors.
66-
*/
67-
ConstructorCustomization getConstructor(String constructorNameOrSignature);
68-
69-
/**
70-
* Gets the property level customization for a property in the class.
71-
* <p>
72-
* For constant properties use {@link #getConstant(String)}.
73-
*
74-
* @param propertyName the property name
75-
* @return the property level customization
76-
*/
77-
PropertyCustomization getProperty(String propertyName);
78-
79-
/**
80-
* Gets the constant level customization for a constant in the class.
81-
* <p>
82-
* For instance properties use {@link #getProperty(String)}.
83-
*
84-
* @param constantName The constant name.
85-
* @return The constant level customization.
86-
*/
87-
ConstantCustomization getConstant(String constantName);
88-
89-
/**
90-
* Gets the Javadoc customization for this class.
91-
*
92-
* @return the Javadoc customization
93-
*/
94-
JavadocCustomization getJavadoc();
95-
96-
/**
97-
* Adds a constructor to this class.
98-
*
99-
* @param constructor The entire constructor as a literal string.
100-
* @return The constructor level customization for the added constructor.
101-
*/
102-
ConstructorCustomization addConstructor(String constructor);
103-
104-
/**
105-
* Adds a constructor to this class.
106-
*
107-
* @param constructor The entire constructor as a literal string.
108-
* @param importsToAdd Any additional imports required by the constructor. These will be custom types or types that
109-
* are ambiguous on which to use such as {@code List} or the utility class {@code Arrays}.
110-
* @return The constructor level customization for the added constructor.
111-
*/
112-
ConstructorCustomization addConstructor(String constructor, List<String> importsToAdd);
113-
114-
/**
115-
* Adds a method to this class.
116-
*
117-
* @param method The entire method as a literal string.
118-
* @return The method level customization for the added method.
119-
*/
120-
MethodCustomization addMethod(String method);
121-
122-
/**
123-
* Adds a method to this class.
124-
*
125-
* @param method The entire method as a literal string.
126-
* @param importsToAdd Any additional imports required by the constructor. These will be custom types or types that
127-
* are ambiguous on which to use such as {@code List} or the utility class {@code Arrays}.
128-
* @return The method level customization for the added method.
129-
*/
130-
MethodCustomization addMethod(String method, List<String> importsToAdd);
131-
132-
/**
133-
* Removes a method from this class.
134-
* <p>
135-
* If there exists multiple methods with the same name or signature only the first one found will be removed.
136-
* <p>
137-
* This method doesn't update usages of the method being removed. If the method was used elsewhere those usages will
138-
* have to be updated or removed in another customization, or customizations.
139-
* <p>
140-
* If this removes the only method contained in the class this will result in a class with no methods.
141-
*
142-
* @param methodNameOrSignature The name or signature of the method being removed.
143-
* @return The current ClassCustomization.
144-
*/
145-
ClassCustomization removeMethod(String methodNameOrSignature);
146-
147-
/**
148-
* Renames a class in the package.
149-
*
150-
* @param newName the new simple name for this class
151-
* @return The current ClassCustomization.
152-
*/
153-
ClassCustomization rename(String newName);
154-
155-
/**
156-
* Replace the modifier for this class.
157-
* <p>
158-
* For compound modifiers such as {@code public abstract} use bitwise OR ({@code |}) of multiple Modifiers, {@code
159-
* Modifier.PUBLIC | Modifier.ABSTRACT}.
160-
* <p>
161-
* Pass {@code 0} for {@code modifiers} to indicate that the method has no modifiers.
162-
*
163-
* @param modifiers The {@link Modifier Modifiers} for the class.
164-
* @return The updated ClassCustomization object.
165-
* @throws IllegalArgumentException If the {@code modifier} is less than {@code 0} or any {@link Modifier} included
166-
* in the bitwise OR isn't a valid class {@link Modifier}.
167-
*/
168-
ClassCustomization setModifier(int modifiers);
169-
170-
/**
171-
* Add an annotation on the class. The annotation class will be automatically imported.
172-
*
173-
* @param annotation the annotation to add to the class. The leading @ can be omitted.
174-
* @return the current class customization for chaining
175-
*/
176-
ClassCustomization addAnnotation(String annotation);
177-
178-
/**
179-
* Remove an annotation from the class.
180-
*
181-
* @param annotation the annotation to remove from the class. The leading @ can be omitted.
182-
* @return the current class customization for chaining
183-
*/
184-
ClassCustomization removeAnnotation(String annotation);
185-
186-
/**
187-
* Rename an enum member if the current class is an enum class.
22+
* Gets the name of the class this customization is using.
18823
*
189-
* @param enumMemberName the current enum member name
190-
* @param newName the new enum member name
191-
* @return the current class customization for chaining
24+
* @return The name of the class.
19225
*/
193-
ClassCustomization renameEnumMember(String enumMemberName, String newName);
26+
public String getClassName() {
27+
return className;
28+
}
19429

19530
/**
19631
* Allows for a fully controlled modification of the abstract syntax tree that represents this class.
19732
*
19833
* @param astCustomization The abstract syntax tree customization callback.
199-
* @return A new ClassCustomization for this class with the abstract syntax tree changes applied.
34+
* @return This ClassCustomization with the abstract syntax tree changes applied.
20035
*/
201-
ClassCustomization customizeAst(Consumer<CompilationUnit> astCustomization);
36+
public ClassCustomization customizeAst(Consumer<CompilationUnit> astCustomization) {
37+
CompilationUnit astToEdit = StaticJavaParser.parse(editor.getFileContent(fileName));
38+
astCustomization.accept(astToEdit);
39+
editor.replaceFile(fileName, astToEdit.toString());
20240

203-
ClassCustomization refreshSymbol();
41+
return this;
42+
}
20443
}

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/customization/CodeCustomization.java

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,33 @@
33

44
package com.microsoft.typespec.http.client.generator.core.customization;
55

6-
import com.microsoft.typespec.http.client.generator.core.customization.implementation.ls.EclipseLanguageClient;
7-
import com.microsoft.typespec.http.client.generator.core.extension.plugin.JavaSettings;
8-
import org.eclipse.lsp4j.SymbolInformation;
9-
106
/**
117
* Base interface for all code based customizations.
128
*/
13-
public interface CodeCustomization {
9+
public abstract class CodeCustomization {
10+
final Editor editor;
11+
final String fileName;
12+
13+
CodeCustomization(Editor editor, String packageName, String className) {
14+
this.editor = editor;
15+
this.fileName = "src/main/java/" + packageName.replace('.', '/') + "/" + className + ".java";
16+
}
1417

1518
/**
1619
* The Editor managing the state of the CodeCustomization.
1720
*
1821
* @return The Editor.
1922
*/
20-
Editor getEditor();
21-
22-
/**
23-
* The EclipseLanguageClient managing validation of the CodeCustomization.
24-
* <p>
25-
* If {@link JavaSettings#isUseEclipseLanguageServer()} returns true, an {@link EclipseLanguageClient} instance will
26-
* be returned, otherwise this returns null.
27-
*
28-
* @return The EclipseLanguageClient.
29-
*/
30-
EclipseLanguageClient getLanguageClient();
31-
32-
/**
33-
* The SymbolInformation managing information about the CodeCustomization.
34-
* <p>
35-
* If {@link JavaSettings#isUseEclipseLanguageServer()} returns true, a {@link SymbolInformation} instance will be
36-
* returned, otherwise this returns null.
37-
*
38-
* @return The SymbolInformation.
39-
*/
40-
SymbolInformation getSymbol();
41-
42-
/**
43-
* The URI of the file containing where the code for the CodeCustomization exists.
44-
*
45-
* @return The URI of the file.
46-
*/
47-
String getFileUri();
23+
public Editor getEditor() {
24+
return editor;
25+
}
4826

4927
/**
5028
* The name of the file containing where the code for the CodeCustomization exists.
5129
*
5230
* @return The name of the file.
5331
*/
54-
String getFileName();
32+
public String getFileName() {
33+
return fileName;
34+
}
5535
}

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/customization/ConstantCustomization.java

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

0 commit comments

Comments
 (0)