Skip to content

Commit

Permalink
[fixes projectlombok#2950] Patch language server semantic highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Sep 28, 2021
1 parent ba2b47b commit b50aa64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
15 changes: 6 additions & 9 deletions src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
Expand Up @@ -87,7 +87,6 @@ public String mapResourceName(int classFileFormatVersion, String resourceName) {
patchHideGeneratedNodes(sm);
patchPostCompileHookEclipse(sm);
patchFixSourceTypeConverter(sm);
patchDisableLombokForCodeCleanup(sm);
patchListRewriteHandleGeneratedMethods(sm);
patchSyntaxAndOccurrencesHighlighting(sm);
patchSortMembersOperation(sm);
Expand Down Expand Up @@ -206,14 +205,6 @@ private static void patchSyntaxAndOccurrencesHighlighting(ScriptManager sm) {
.build());
}

private static void patchDisableLombokForCodeCleanup(ScriptManager sm) {
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isRefactoringVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
.request(StackRequest.THIS, StackRequest.PARAM1)
.build());
}

private static void patchListRewriteHandleGeneratedMethods(ScriptManager sm) {
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.replaceMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter", "rewriteList"))
Expand Down Expand Up @@ -308,6 +299,12 @@ private static void patchHideGeneratedNodes(ScriptManager sm) {
"org.eclipse.jdt.core.dom.SimpleName[]"))
.request(StackRequest.RETURN_VALUE).build());

sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isBlockedVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
.request(StackRequest.THIS, StackRequest.PARAM1)
.build());

patchRefactorScripts(sm);
patchFormatters(sm);
}
Expand Down
15 changes: 3 additions & 12 deletions src/eclipseAgent/lombok/launch/PatchFixesHider.java
Expand Up @@ -414,23 +414,14 @@ public static boolean isGenerated(org.eclipse.jdt.internal.compiler.ast.ASTNode
return result;
}

public static boolean isRefactoringVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
public static boolean isBlockedVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
if (visitor == null) return false;

String className = visitor.getClass().getName();
if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix"))) return false;
if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix") || className.startsWith("org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokensVisitor"))) return false;
if (className.equals("org.eclipse.jdt.internal.corext.fix.VariableDeclarationFixCore$WrittenNamesFinder")) return false;

boolean result = false;
try {
result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) {
result = isGenerated(node.getParent());
}
} catch (Exception e) {
// better to assume it isn't generated
}
return result;
return isGenerated(node);
}

public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) {
Expand Down

0 comments on commit b50aa64

Please sign in to comment.