diff --git a/build.gradle.kts b/build.gradle.kts index a7a1a6e..a4716ef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -81,6 +81,7 @@ val extract = task("extractJdt") { include("org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java") include("org/eclipse/jdt/internal/core/dom/rewrite/imports/*.java") + include("org/eclipse/jdt/internal/core/util/BindingKeyResolver*.java") } tasks["applyPatches"].inputs.files(extract) tasks["resetSources"].inputs.files(extract) @@ -95,8 +96,11 @@ val renames = listOf( "org.eclipse.jdt.core.dom.rewrite" to "$og_group.$artifactId.jdt.rewrite.imports", "org.eclipse.jdt.internal.core.dom.rewrite.imports" to "$og_group.$artifactId.jdt.internal.rewrite.imports" ) +val classRenames = listOf( + "org.eclipse.jdt.internal.core.util.BindingKeyResolver" to "$og_group.$artifactId.shadow.org.eclipse.jdt.internal.core.util.BindingKeyResolver", +) -fun createRenameTask(prefix: String, inputDir: File, outputDir: File, renames: List>): Task +fun createRenameTask(prefix: String, inputDir: File, outputDir: File, renames: List>, classRenames: List>): Task = task("${prefix}renameJdt") { destinationDir = file(outputDir) @@ -105,14 +109,26 @@ fun createRenameTask(prefix: String, inputDir: File, outputDir: File, renames: L into("${new.replace('.', '/')}/") } } + classRenames.forEach { (old, new) -> + val oldPkg = old.substringBeforeLast('.') + val newPkg = new.substringBeforeLast('.') + from("$inputDir/${oldPkg.replace('.', '/')}") { + into("${newPkg.replace('.', '/')}/") + filter { + if (it.startsWith("package ")) it.replace(oldPkg, newPkg) + else it + } + } + } filter { renames.fold(it) { s, (from, to) -> s.replace(from, to) } } + filter { classRenames.fold(it) { s, (from, to) -> s.replace(from, to) } } } -val renameTask = createRenameTask("", patches.target, jdtSrcDir, renames) +val renameTask = createRenameTask("", patches.target, jdtSrcDir, renames, classRenames) renameTask.inputs.files(tasks["applyPatches"]) -tasks["makePatches"].inputs.files(createRenameTask("un", jdtSrcDir, patches.target, renames.map { (a,b) -> b to a })) +tasks["makePatches"].inputs.files(createRenameTask("un", jdtSrcDir, patches.target, renames.map { (a,b) -> b to a }, classRenames.map { (a,b) -> b to a })) sourceSets["main"].java.srcDirs(renameTask) tasks.jar.configure { @@ -141,6 +157,7 @@ tasks.shadowJar { relocate("org.apache", "org.cadixdev.mercury.shadow.org.apache") relocate("org.eclipse", "org.cadixdev.mercury.shadow.org.eclipse") relocate("org.osgi", "org.cadixdev.mercury.shadow.org.osgi") + exclude("org/eclipse/jdt/internal/core/util/BindingKeyResolver.class") } val sourceJar = task("sourceJar") { @@ -233,11 +250,11 @@ publishing { } repositories { - if (System.getenv("MAVEN_PASS") != null) { - maven("https://deploy.shedaniel.me/") { + if (System.getenv("MAVEN_URL") != null) { + maven(System.getenv("MAVEN_URL")) { credentials { - username = "shedaniel" - password = System.getenv("MAVEN_PASS") + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") } } } diff --git a/gradle.properties b/gradle.properties index 51be355..69b288f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -group = dev.architectury +group = org.sinytra og_group = org.cadixdev name = Mercury base_version = 0.1.4 diff --git a/patches/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java.patch b/patches/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java.patch index fb25443..df5c841 100644 --- a/patches/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java.patch +++ b/patches/org/eclipse/jdt/core/dom/rewrite/ImportRewrite.java.patch @@ -147,10 +147,10 @@ return ImportRewriteContext.RES_NAME_FOUND; } + } - + if (this.astRoot != null) { List types = this.astRoot.types(); -@@ -1304,7 +1357,28 @@ +@@ -1305,7 +1358,28 @@ * @throws CoreException the exception is thrown if the rewrite fails. */ public final TextEdit rewriteImports(IProgressMonitor monitor) throws CoreException { @@ -179,7 +179,7 @@ SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.bind(Messages.importRewrite_processDescription), 2); if (!hasRecordedChanges()) { -@@ -1325,7 +1399,7 @@ +@@ -1326,7 +1400,7 @@ ImportRewriteConfiguration config= buildImportRewriteConfiguration(); ImportRewriteAnalyzer computer= @@ -188,7 +188,7 @@ for (String addedImport : this.addedImports) { boolean isStatic = STATIC_PREFIX == addedImport.charAt(0); -@@ -1368,11 +1442,17 @@ +@@ -1369,11 +1443,17 @@ configBuilder.setTypeOnDemandThreshold(this.importOnDemandThreshold); configBuilder.setStaticOnDemandThreshold(this.staticImportOnDemandThreshold); diff --git a/patches/org/eclipse/jdt/internal/core/dom/rewrite/imports/ImportRewriteAnalyzer.java.patch b/patches/org/eclipse/jdt/internal/core/dom/rewrite/imports/ImportRewriteAnalyzer.java.patch index 90a4b82..afa12be 100644 --- a/patches/org/eclipse/jdt/internal/core/dom/rewrite/imports/ImportRewriteAnalyzer.java.patch +++ b/patches/org/eclipse/jdt/internal/core/dom/rewrite/imports/ImportRewriteAnalyzer.java.patch @@ -1,6 +1,6 @@ --- a/org/eclipse/jdt/internal/core/dom/rewrite/imports/ImportRewriteAnalyzer.java +++ b/org/eclipse/jdt/internal/core/dom/rewrite/imports/ImportRewriteAnalyzer.java -@@ -46,8 +46,11 @@ +@@ -47,8 +47,11 @@ import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.dom.rewrite.imports.ConflictIdentifier.Conflicts; import org.eclipse.jdt.internal.core.util.Util; @@ -12,7 +12,7 @@ import org.eclipse.text.edits.TextEdit; /** -@@ -261,10 +264,10 @@ +@@ -262,10 +265,10 @@ } private static RewriteSite determineRewriteSite( @@ -25,7 +25,7 @@ boolean hasPrecedingElements = surroundingRegion.getOffset() != 0; -@@ -302,7 +305,7 @@ +@@ -303,7 +306,7 @@ * Determines the region to be occupied by imports, their associated comments, and surrounding * whitespace. */ @@ -34,7 +34,7 @@ NavigableMap nodesTreeMap = mapTopLevelNodes(compilationUnit); int surroundingStart; -@@ -331,12 +334,24 @@ +@@ -344,12 +347,24 @@ } int surroundingEnd = positionAfterImports; @@ -59,7 +59,7 @@ return new Region(surroundingStart, surroundingEnd - surroundingStart); } -@@ -432,6 +447,7 @@ +@@ -445,6 +460,7 @@ public ImportRewriteAnalyzer( ICompilationUnit cu, CompilationUnit astRoot, @@ -67,7 +67,7 @@ ImportRewriteConfiguration configuration) throws JavaModelException { this.originalImportEntries = Collections.unmodifiableList(readOriginalImports(astRoot)); -@@ -460,7 +476,7 @@ +@@ -473,7 +489,7 @@ ImportGroupComparator importGroupComparator = new ImportGroupComparator(configuration.importOrder); @@ -76,7 +76,7 @@ this.importAdder = configuration.originalImportHandling.createImportAdder(new ImportComparator( importGroupComparator, -@@ -468,31 +484,39 @@ +@@ -481,31 +497,39 @@ configuration.staticContainerSorting.createContainerComparator(javaProject))); this.implicitImportContainerNames = @@ -120,7 +120,7 @@ this.importDeclarationWriter); } -@@ -566,18 +590,18 @@ +@@ -579,18 +603,18 @@ Set touchedContainers = determineTouchedContainers(); diff --git a/patches/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java.patch b/patches/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java.patch new file mode 100644 index 0000000..909c6f1 --- /dev/null +++ b/patches/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java.patch @@ -0,0 +1,25 @@ +--- a/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java ++++ b/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java +@@ -57,6 +57,8 @@ + import org.eclipse.jdt.internal.compiler.lookup.VariableBinding; + import org.eclipse.jdt.internal.compiler.lookup.WildcardBinding; + import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; ++import org.eclipse.jdt.internal.core.util.BindingKeyParser; ++import org.eclipse.jdt.internal.core.util.Util; + + @SuppressWarnings({"rawtypes", "unchecked"}) + public class BindingKeyResolver extends BindingKeyParser { +@@ -354,7 +356,12 @@ + @Override + public void consumeLocalType(char[] uniqueKey) { + if (this.parsedUnit == null) { +- this.typeBinding = null; ++ char[][] subtypeName = new char[this.compoundName.length][]; ++ System.arraycopy(this.compoundName, 0, subtypeName, 0, this.compoundName.length); ++ String[] subTypeParts = String.copyValueOf(uniqueKey).split("/"); ++ String subTypeClassName = subTypeParts[subTypeParts.length - 1]; ++ subtypeName[subtypeName.length - 1] = subTypeClassName.substring(0, subTypeClassName.length() - 1).toCharArray(); ++ this.typeBinding = this.environment.getType(subtypeName); + return; + } + for (LocalTypeBinding localTypeBinding : this.parsedUnit.localTypes.values()) { diff --git a/src/main/java/org/cadixdev/mercury/Mercury.java b/src/main/java/org/cadixdev/mercury/Mercury.java index 2996fe9..b3229e5 100644 --- a/src/main/java/org/cadixdev/mercury/Mercury.java +++ b/src/main/java/org/cadixdev/mercury/Mercury.java @@ -152,12 +152,12 @@ public Map getContext() { } public Optional createTypeBinding(String className) { - if (isAnonymousOrLocalType(className)) { - // TODO: Anonymous or local types are currently not supported - // Eclipse uses source lines in their binding keys that are impossible - // to know in advance. Since it may return incorrect results, abort early. - return Optional.empty(); - } +// if (isAnonymousOrLocalType(className)) { +// // TODO: Anonymous or local types are currently not supported +// // Eclipse uses source lines in their binding keys that are impossible +// // to know in advance. Since it may return incorrect results, abort early. +// return Optional.empty(); +// } IBinding binding = this.requestor.createBindings(new String[]{'L' + className.replace('.', '/') + ';'})[0]; return binding != null && binding.getKind() == IBinding.TYPE ? Optional.of((ITypeBinding) binding) : Optional.empty();