Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package org.nullbool.editor.impl.model.code;
  2.  
  3. import java.io.InputStream;
  4. import java.util.concurrent.atomic.AtomicReference;
  5.  
  6. import org.nullbool.editor.model.code.ICompiler;
  7. import org.nullbool.editor.util.PrefixedStringBuilder;
  8. import org.objectweb.asm.tree.ClassNode;
  9.  
  10. /**
  11. * @author Bibl (don't ban me pls)
  12. * @created 27 Aug 2015 23:39:57
  13. */
  14. public class InCompilerImpl implements ICompiler<ClassNode> {
  15.  
  16. public static final char TAB_CHAR = '\t';
  17. public static final String TAB = Character.toString(TAB_CHAR);
  18.  
  19. @Override
  20. public void compile(InputStream is, ClassNode cn) {
  21. AtomicReference<String> prefix = new AtomicReference<String>("");
  22. PrefixedStringBuilder sb = new PrefixedStringBuilder();
  23. enterSection(sb, "class");
  24.  
  25.  
  26. }
  27.  
  28. public void enterSection(PrefixedStringBuilder sb, String name) {
  29. sb.append('.').append(name);
  30. incrementTabIndex(sb.getPrefix());
  31. sb.ln();
  32. }
  33.  
  34. public void exitSection(PrefixedStringBuilder sb) {
  35. decrementTabIndex(sb.getPrefix());
  36. sb.ln();
  37. sb.appendLn("}");
  38. }
  39.  
  40. public static String incrementTabIndex(String oldPrefix) {
  41. return oldPrefix + TAB;
  42. }
  43.  
  44. public static String decrementTabIndex(String oldPrefix) {
  45. if(oldPrefix != null && !oldPrefix.isEmpty()) {
  46. // assumption: prefix string only contains tabs
  47. if(oldPrefix.replace(TAB, "").length() != 0) {
  48. throw new IllegalArgumentException("Prefix contains chars other than tabs: " + oldPrefix);
  49. } else {
  50. return oldPrefix.substring(0, oldPrefix.length() - 1); // remove last tab
  51. }
  52. } else {
  53. return "";
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement