Skip to content

Commit

Permalink
Merge branch 'reflection_mapping' of https://github.com/LogicFan/Sponge
Browse files Browse the repository at this point in the history
… into forge-prod

Closes #3470
  • Loading branch information
zml2008 committed Aug 23, 2021
2 parents 5adda51 + 64d5f31 commit 5de812e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/launch/java/org/spongepowered/common/launch/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.spongepowered.api.plugin.PluginManager;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.common.applaunch.plugin.PluginPlatform;
import org.spongepowered.common.launch.mapping.SpongeMappingManager;
import org.spongepowered.common.launch.plugin.SpongePluginManager;
import org.spongepowered.plugin.PluginContainer;

Expand Down Expand Up @@ -91,6 +92,8 @@ public void setLifecycle(final Lifecycle lifecycle) {
this.lifecycle = lifecycle;
}

public abstract SpongeMappingManager mappingManager();

public final Logger logger() {
return this.logger;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.launch.mapping;

/**
* A mapping manager provide the necessary tool to convert
* from Mojang mapping to the current runtime mapping. This
* is intended to facility the reflection across different
* mapping.
*/
public interface SpongeMappingManager {
String toRuntimeClassName(String srcName);

String toRuntimeFieldName(Class<?> owner, String srcName);

String toRuntimeMethodName(Class<?> owner, String srcName, Class<?> ...params);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static boolean doesMethodExist(
final String methodName,
final Class<?>[] methodParameters
) {
final String targetMethodForEnvironment = Launch.instance().developerEnvironment() ? methodName : methodName;
final String targetMethodForEnvironment = Launch.instance().mappingManager().toRuntimeMethodName(targetClass, methodName, methodParameters);
try {
final Class<?> declaringClass = targetClass.getMethod(targetMethodForEnvironment, methodParameters).getDeclaringClass();
return !ignoredClass.equals(declaringClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
import org.spongepowered.common.inject.SpongeCommonModule;
import org.spongepowered.common.inject.SpongeModule;
import org.spongepowered.common.launch.Launch;
import org.spongepowered.common.launch.mapping.SpongeMappingManager;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.jvm.locator.JVMPluginResourceLocatorService;
import org.spongepowered.plugin.metadata.PluginMetadata;
import org.spongepowered.plugin.metadata.util.PluginMetadataHelper;
import org.spongepowered.vanilla.applaunch.plugin.VanillaPluginPlatform;
import org.spongepowered.vanilla.launch.inject.SpongeVanillaModule;
import org.spongepowered.vanilla.launch.plugin.VanillaDummyPluginContainer;
import org.spongepowered.vanilla.launch.mapping.VanillaMappingManager;
import org.spongepowered.vanilla.launch.plugin.VanillaPluginManager;

import java.io.IOException;
Expand All @@ -54,12 +56,14 @@ public abstract class VanillaLaunch extends Launch {

private final Stage injectionStage;
private final VanillaPluginManager pluginManager;
private final VanillaMappingManager mappingManager;
private PluginContainer vanillaPlugin;

protected VanillaLaunch(final VanillaPluginPlatform pluginPlatform, final Stage injectionStage) {
super(pluginPlatform);
this.injectionStage = injectionStage;
this.pluginManager = new VanillaPluginManager();
this.mappingManager = new VanillaMappingManager();
}

@Override
Expand Down Expand Up @@ -90,6 +94,11 @@ public final VanillaPluginManager pluginManager() {
return this.pluginManager;
}

@Override
public SpongeMappingManager mappingManager() {
return this.mappingManager;
}

@Override
public Injector createInjector() {
final List<Module> modules = Lists.newArrayList(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.vanilla.launch.mapping;

import org.spongepowered.common.launch.mapping.SpongeMappingManager;

public final class VanillaMappingManager implements SpongeMappingManager {
@Override
public String toRuntimeClassName(final String srcName) {
return srcName;
}

@Override
public String toRuntimeFieldName(final Class<?> owner, final String srcName) {
return srcName;
}

@Override
public String toRuntimeMethodName(final Class<?> owner, final String srcName, final Class<?>... params) {
return srcName;
}
}

0 comments on commit 5de812e

Please sign in to comment.