Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* A Gradle plugin for the creation of Minecraft mods and MinecraftForge plugins.
* Copyright (C) 2013-2019 Minecraft Forge
* Copyright (C) 2020-2021 anatawa12 and other contributors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package net.minecraftforge.gradle.util.mcp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraftforge.gradle.common.Constants;
import com.google.code.regexp.Matcher;
import com.google.code.regexp.Pattern;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
public class FmlCleanup
{
//private static final Pattern METHOD_REG = Pattern.compile("^ {4}(\\w+\\s+\\S.*\\(.*|static)$");
private static final Pattern METHOD_REG = Pattern.compile("^(?\\s+)(?(?:(?:" + FFPatcher.MODIFIERS + ") )*)(?:(?[\\w\\[\\]\\.$]+) )?(?[\\w$]+)\\((?.*?)\\)(?(?: throws (?[\\w$.]+(?:, [\\w$.]+)*))?)");
private static final Pattern CATCH_REG = Pattern.compile("catch \\((.*)\\)$");
private static final Pattern METHOD_DEC_END = Pattern.compile("(}|\\);|throws .+?;)$");
private static final Pattern CAPS_START = Pattern.compile("^[A-Z]");
private static final Pattern ARRAY = Pattern.compile("(\\[|\\.\\.\\.)");
private static final Pattern VAR_CALL = Pattern.compile("(?i)[a-z_$][a-z0-9_\\[\\]]+ var\\d+(?:x)*");
private static final Pattern VAR = Pattern.compile("var\\d+(?:x)*");
private static final Comparator COMPARATOR = new Comparator()
{
@Override
public int compare(String str1, String str2)
{
return str2.length() - str1.length();
}
};
public static String renameClass(String text)
{
String[] lines = text.split("(\r\n|\r|\n)");
List output = new ArrayList(lines.length);
MethodInfo method = null;
for (String line : lines)
{
Matcher matcher = METHOD_REG.matcher(line);
boolean found = matcher.find();
if (!line.endsWith(";") && !line.endsWith(",") && found)// && !line.contains("=") && !NESTED_PERINTH.matcher(line).find())
{
method = new MethodInfo(method, matcher.group("indent"));
method.lines.add(line);
boolean invalid = false; // Can't think of a better way to filter out enum declarations, so make sure that all the parameters have types
String args = matcher.group("parameters");
if (args != null)
{
for (String str : Splitter.on(',').trimResults().omitEmptyStrings().split(args))
{
if (str.indexOf(' ') == -1)
{
invalid = true;
break;
}
method.addVar(str);
}
}
if (invalid || METHOD_DEC_END.matcher(line).find())
{
if (method.parent != null)
{
method.parent.children.remove(method);
}
method = method.parent;
if (method == null) // dont output if there is a parent method.
output.add(line);
}
}
else if (method != null && method.ENDING.equals(line))
{
method.lines.add(line);
if (method.parent == null)
{
for (String l : Splitter.on(Constants.NEWLINE).split(method.rename(null)))
{
output.add(l);
}
}
method = method.parent;
}
else if (method != null)
{
method.lines.add(line);
matcher = CATCH_REG.matcher(line);
if (matcher.find())
{
method.addVar(matcher.group(1));
}
else
{
matcher = VAR_CALL.matcher(line);
while (matcher.find())
{
String match = matcher.group();
if (!match.startsWith("return") && !match.startsWith("throw"))
{
method.addVar(match);
}
}
}
}
else // If we get to here, then we are outside of all methods
{
output.add(line);
}
}
return Joiner.on(Constants.NEWLINE).join(output);
}
private static class MethodInfo
{
private MethodInfo parent = null;
private List