
net.minecraftforge.gradle.extrastuff.GLConstantFixer Maven / Gradle / Ivy
package net.minecraftforge.gradle.extrastuff;
import argo.jdom.JdomParser;
import argo.jdom.JsonNode;
import argo.jdom.JsonRootNode;
import argo.jdom.JsonStringNode;
import argo.saj.InvalidSyntaxException;
import com.google.common.base.Joiner;
import com.google.common.io.Resources;
import net.minecraftforge.gradle.common.Constants;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class GLConstantFixer
{
private static final String[] PACKAGES = {
"GL11",
"GL12",
"GL13",
"GL14",
"GL15",
"GL20",
"GL21",
"ARBMultitexture",
"ARBOcclusionQuery",
"ARBVertexBufferObject",
"ARBShaderObjects"
};
private static final JdomParser JDOM_PARSER = new JdomParser();
private final JsonRootNode json;
public static final Pattern CALL_REGEX = Pattern.compile("(" + Joiner.on("|").join(PACKAGES) + ")\\.([\\w]+)\\(.+\\)");
public static final Pattern CONSTANT_REGEX = Pattern.compile("(? entry : listNode.getFields().entrySet())
{
// find the actual constant for the number from the regex
if (entry.getValue().isNode(constant))
{
// construct the final line
answer = entry.getKey().getText() + "." + entry.getValue().getStringValue(constant);
}
}
}
}
// replace the final line.
if (answer != null)
{
constantMatcher.appendReplacement(innerOut, Matcher.quoteReplacement(answer));
}
}
constantMatcher.appendTail(innerOut);
// replace the final line.
if (fullCall != null)
{
rootMatch.appendReplacement(out, Matcher.quoteReplacement(innerOut.toString()));
}
}
rootMatch.appendTail(out);
return out.toString();
}
private boolean jsonArrayContains(List nodes, String str)
{
boolean hasMethod = false;
for (JsonNode testMethod : nodes)
{
hasMethod = testMethod.getText().equals(str);
if (hasMethod)
{
return hasMethod;
}
}
return false;
}
private String updateImports(String text, String imp)
{
if (!text.contains("import " + imp + ";"))
{
text = text.replace(IMPORT_REPLACE, IMPORT_REPLACE + Constants.NEWLINE + "import " + imp + ";");
}
return text;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy