Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.nullbool.editor.impl.model.code;
- import java.io.InputStream;
- import java.util.concurrent.atomic.AtomicReference;
- import org.nullbool.editor.model.code.ICompiler;
- import org.nullbool.editor.util.PrefixedStringBuilder;
- import org.objectweb.asm.tree.ClassNode;
- /**
- * @author Bibl (don't ban me pls)
- * @created 27 Aug 2015 23:39:57
- */
- public class InCompilerImpl implements ICompiler<ClassNode> {
- public static final char TAB_CHAR = '\t';
- public static final String TAB = Character.toString(TAB_CHAR);
- @Override
- public void compile(InputStream is, ClassNode cn) {
- AtomicReference<String> prefix = new AtomicReference<String>("");
- PrefixedStringBuilder sb = new PrefixedStringBuilder();
- enterSection(sb, "class");
- }
- public void enterSection(PrefixedStringBuilder sb, String name) {
- sb.append('.').append(name);
- incrementTabIndex(sb.getPrefix());
- sb.ln();
- }
- public void exitSection(PrefixedStringBuilder sb) {
- decrementTabIndex(sb.getPrefix());
- sb.ln();
- sb.appendLn("}");
- }
- public static String incrementTabIndex(String oldPrefix) {
- return oldPrefix + TAB;
- }
- public static String decrementTabIndex(String oldPrefix) {
- if(oldPrefix != null && !oldPrefix.isEmpty()) {
- // assumption: prefix string only contains tabs
- if(oldPrefix.replace(TAB, "").length() != 0) {
- throw new IllegalArgumentException("Prefix contains chars other than tabs: " + oldPrefix);
- } else {
- return oldPrefix.substring(0, oldPrefix.length() - 1); // remove last tab
- }
- } else {
- return "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement