|
| 1 | +/* |
| 2 | + * Copyright 2026 DiffPlug |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package lombok.launch; |
| 17 | + |
| 18 | +/** |
| 19 | + * Stub implementation of {@code lombok.launch.PatchFixesHider} used only |
| 20 | + * within the {@code FeatureClassLoader} isolation boundary. |
| 21 | + * |
| 22 | + * <p>When lombok is loaded as a JVM agent (e.g. {@code -javaagent:lombok.jar}), |
| 23 | + * it patches ECJ's {@code Parser} class so that its static initializer |
| 24 | + * references inner classes of {@code PatchFixesHider} such as |
| 25 | + * {@code ModuleClassLoading} and {@code Transform}. Spotless's |
| 26 | + * {@code FeatureClassLoader} isolates formatter JARs from the build-tool |
| 27 | + * class-loader, so it cannot see the real {@code PatchFixesHider} that was |
| 28 | + * injected by the agent. Loading this stub instead allows ECJ's |
| 29 | + * {@code Parser.<clinit>} to complete without a {@link NoClassDefFoundError}. |
| 30 | + * |
| 31 | + * <p>Every method in every inner class is a no-op stub. No real formatting |
| 32 | + * logic lives here. |
| 33 | + */ |
| 34 | +@SuppressWarnings("unused") |
| 35 | +final class PatchFixesHider { |
| 36 | + |
| 37 | + private PatchFixesHider() {} |
| 38 | + |
| 39 | + /** Stub for {@code PatchFixesHider.ModuleClassLoading}. */ |
| 40 | + public static final class ModuleClassLoading { |
| 41 | + private ModuleClassLoading() {} |
| 42 | + |
| 43 | + /** Stub – performs no class-loader manipulation. */ |
| 44 | + public static void parserClinit() { |
| 45 | + // no-op stub |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /** Stub for {@code PatchFixesHider.Transform}. */ |
| 50 | + public static final class Transform { |
| 51 | + private Transform() {} |
| 52 | + |
| 53 | + /** Stub – performs no AST transformation. */ |
| 54 | + public static void transform(Object parser, Object ast) { |
| 55 | + // no-op stub |
| 56 | + } |
| 57 | + |
| 58 | + /** Stub – performs no AST transformation. */ |
| 59 | + public static void transform_swapped(Object ast, Object parser) { |
| 60 | + // no-op stub |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /** Stub for {@code PatchFixesHider.PatchFixes}. */ |
| 65 | + public static final class PatchFixes { |
| 66 | + private PatchFixes() {} |
| 67 | + |
| 68 | + /** Stub – always returns {@code false}. */ |
| 69 | + public static boolean isGenerated(Object node) { |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + /** Stub – always returns {@code false}. */ |
| 74 | + public static boolean returnFalse(Object object) { |
| 75 | + return false; |
| 76 | + } |
| 77 | + |
| 78 | + /** Stub – always returns {@code true}. */ |
| 79 | + public static boolean returnTrue(Object object) { |
| 80 | + return true; |
| 81 | + } |
| 82 | + |
| 83 | + /** Stub – always returns {@code false}. */ |
| 84 | + public static boolean isBlockedVisitorAndGenerated(Object node, Object visitor) { |
| 85 | + return false; |
| 86 | + } |
| 87 | + |
| 88 | + /** Stub – returns 0-length array. */ |
| 89 | + public static Object[] listRewriteHandleGeneratedMethods(Object rewriteEvent) { |
| 90 | + return new Object[0]; |
| 91 | + } |
| 92 | + |
| 93 | + /** Stub – returns {@code sourceEnd} unchanged. */ |
| 94 | + public static int getSourceEndFixed(int sourceEnd, Object node) { |
| 95 | + return sourceEnd; |
| 96 | + } |
| 97 | + |
| 98 | + /** Stub – returns {@code original} unchanged. */ |
| 99 | + public static int fixRetrieveStartingCatchPosition(int original, int start) { |
| 100 | + return original == -1 ? start : original; |
| 101 | + } |
| 102 | + |
| 103 | + /** Stub – returns {@code original} unchanged. */ |
| 104 | + public static int fixRetrieveRightBraceOrSemiColonPosition(int original, int end) { |
| 105 | + return original == -1 ? end : original; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + /** Stub for {@code PatchFixesHider.ValPortal}. */ |
| 110 | + public static final class ValPortal { |
| 111 | + private ValPortal() {} |
| 112 | + |
| 113 | + /** Stub – no-op. */ |
| 114 | + public static void copyInitializationOfForEachIterable(Object parser) {} |
| 115 | + |
| 116 | + /** Stub – no-op. */ |
| 117 | + public static void copyInitializationOfLocalDeclaration(Object parser) {} |
| 118 | + |
| 119 | + /** Stub – no-op. */ |
| 120 | + public static void addFinalAndValAnnotationToVariableDeclarationStatement(Object converter, Object out, Object in) {} |
| 121 | + |
| 122 | + /** Stub – no-op. */ |
| 123 | + public static void addFinalAndValAnnotationToSingleVariableDeclaration(Object converter, Object out, Object in) {} |
| 124 | + } |
| 125 | + |
| 126 | + /** Stub for {@code PatchFixesHider.Val}. */ |
| 127 | + public static final class Val { |
| 128 | + private Val() {} |
| 129 | + |
| 130 | + /** Stub – always returns {@code false}. */ |
| 131 | + public static boolean handleValForLocalDeclaration(Object local, Object scope) { |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | + /** Stub – always returns {@code false}. */ |
| 136 | + public static boolean handleValForForEach(Object forEach, Object scope) { |
| 137 | + return false; |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + /** Stub for {@code PatchFixesHider.ExtensionMethod}. */ |
| 142 | + public static final class ExtensionMethod { |
| 143 | + private ExtensionMethod() {} |
| 144 | + |
| 145 | + /** Stub – returns {@code resolvedType} unchanged. */ |
| 146 | + public static Object resolveType(Object resolvedType, Object methodCall, Object scope) { |
| 147 | + return resolvedType; |
| 148 | + } |
| 149 | + |
| 150 | + /** Stub – no-op. */ |
| 151 | + public static void errorNoMethodFor(Object problemReporter, Object messageSend, Object recType, Object params) {} |
| 152 | + |
| 153 | + /** Stub – no-op. */ |
| 154 | + public static void invalidMethod(Object problemReporter, Object messageSend, Object method) {} |
| 155 | + |
| 156 | + /** Stub – no-op. */ |
| 157 | + public static void invalidMethod(Object problemReporter, Object messageSend, Object method, Object scope) {} |
| 158 | + |
| 159 | + /** Stub – no-op. */ |
| 160 | + public static void nonStaticAccessToStaticMethod(Object problemReporter, Object location, Object method, Object messageSend) {} |
| 161 | + |
| 162 | + /** Stub – returns {@code original} unchanged. */ |
| 163 | + public static Object modifyMethodPattern(Object original) { |
| 164 | + return original; |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + /** Stub for {@code PatchFixesHider.Delegate}. */ |
| 169 | + public static final class Delegate { |
| 170 | + private Delegate() {} |
| 171 | + |
| 172 | + /** Stub – always returns {@code false}. */ |
| 173 | + public static boolean handleDelegateForType(Object classScope) { |
| 174 | + return false; |
| 175 | + } |
| 176 | + |
| 177 | + /** Stub – returns an empty array. */ |
| 178 | + public static Object[] addGeneratedDelegateMethods(Object returnValue, Object javaElement) { |
| 179 | + return new Object[0]; |
| 180 | + } |
| 181 | + |
| 182 | + /** Stub – always returns {@code false}. */ |
| 183 | + public static boolean isDelegateSourceMethod(Object sourceMethod) { |
| 184 | + return false; |
| 185 | + } |
| 186 | + |
| 187 | + /** Stub – always returns {@code null}. */ |
| 188 | + public static Object returnElementInfo(Object delegateSourceMethod) { |
| 189 | + return null; |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + /** Stub for {@code PatchFixesHider.Util}. */ |
| 194 | + public static final class Util { |
| 195 | + private Util() {} |
| 196 | + } |
| 197 | + |
| 198 | + /** Stub for {@code PatchFixesHider.LombokDeps}. */ |
| 199 | + public static final class LombokDeps { |
| 200 | + private LombokDeps() {} |
| 201 | + } |
| 202 | + |
| 203 | + /** Stub for {@code PatchFixesHider.Javadoc}. */ |
| 204 | + public static final class Javadoc { |
| 205 | + private Javadoc() {} |
| 206 | + |
| 207 | + /** Stub – returns {@code original} unchanged. */ |
| 208 | + public static String getHTMLContentFromSource(String original, Object member) { |
| 209 | + return original; |
| 210 | + } |
| 211 | + } |
| 212 | +} |
0 commit comments