001 package plugins.JavaRolePluginModule; 002 003 import java.util.Vector; 004 /** 005 @version 0.1+ 006 007 Transformationer: 008 1. Bygg om Entity till att enbart hantera start- och slutposition eftersom 009 det måste vara möjligt att ersätta enbart kommentarer i ett block 010 2. Lägg till typen Semicolon för att kunna lägga in ett ensamt semikolon! 011 3. Omforma Class, ClassWithBody och EndOfClass till ClassHead, ClassBody och EndOfClassBody 012 4. Lägg till typen DocComment 013 5. Lägg till typen EndOfFile 014 6. Spjälka Method i MethodHead och MethodBody 015 7. Antalet olika typer blir 12 016 017 Förslag: 018 1. Bygga om classhead och classbody till class som innehåller huvudet 019 själva klasskroppen är barnen. 020 2. Flytta utvalda metoder till JavaParseTree. 021 3. Gör en "tätare" och ner avskalad Entity! 022 023 Problem: 024 025 */ 026 public class Entity { 027 public static final int UNKNOWN=0; 028 public static final int FILE=1; 029 public static final int ENDOFFILE=2; 030 public static final int CLASSHEAD=3; 031 public static final int CLASSBODY=4; 032 public static final int ENDOFCLASSBODY=5; //set when } is found 033 public static final int METHODHEAD=6; 034 public static final int METHODBODY=7; 035 public static final int VARIABLE=8; 036 public static final int DOCCOMMENT=9; 037 public static final int SEMICOLON=10; 038 public static final int EXTRA=11; 039 public static final int SYNTAXERROR=12; 040 041 private Entity parent; 042 private Vector children=new Vector(); 043 private int currentChild; 044 045 public String file; 046 047 public int type=UNKNOWN; 048 public int startPos=-1; 049 public int endPos=-1; 050 public int contentStartPos=-1; 051 052 public Entity(String file) { 053 this.file=file; 054 } 055 056 public Entity getParent() { 057 return parent; 058 } 059 060 public void setParent(Entity parent) { 061 this.parent=parent; 062 } 063 064 public void addChild(Entity subEntity) { 065 subEntity.setParent(this); 066 children.add(subEntity); 067 } 068 069 public void insertChildBefore(Entity subEntity) { 070 subEntity.setParent(this); 071 children.add(currentChild,subEntity); 072 currentChild++; 073 } 074 075 /* 076 public void insertChildAfter(Entity e) { 077 e.setParent(this); 078 children.add(currentChild+1,e); 079 } 080 */ 081 082 public Entity removeCurrentChildAndGetPrevious() { 083 children.remove(currentChild); 084 currentChild--; 085 if(currentChild>=0) { 086 return (Entity) children.elementAt(currentChild); 087 } else { 088 return null; 089 } 090 } 091 092 093 public Entity removeCurrentChildAndGetNext() { 094 children.remove(currentChild); 095 if(currentChild < children.size()) { 096 return (Entity) children.elementAt(currentChild); 097 } else { 098 return null; 099 } 100 } 101 102 public Entity getFirstChild() { 103 currentChild=0; 104 if(currentChild<children.size()) { 105 return (Entity) children.elementAt(currentChild); 106 } else { 107 return null; 108 } 109 } 110 111 public Entity getLastChild() { 112 currentChild=children.size()-1; 113 if(currentChild>=0) { 114 return (Entity) children.elementAt(currentChild); 115 } else { 116 return null; 117 } 118 } 119 120 121 public Entity getNextChild() { 122 currentChild++; 123 if(currentChild<children.size()) { 124 return (Entity) children.elementAt(currentChild); 125 } else { 126 return null; 127 } 128 } 129 130 public Entity getPreviousChild() { 131 currentChild--; 132 if(currentChild>=0) { 133 return (Entity) children.elementAt(currentChild); 134 } else { 135 return null; 136 } 137 } 138 139 public boolean isAtFirstChild() { 140 return currentChild==0; 141 } 142 143 public String getContent() { 144 if(type==SEMICOLON) { 145 return ";"; 146 } else { 147 return file.substring(contentStartPos,endPos); 148 } 149 } 150 151 public String getContentAndWhitespace() { 152 if(type==SEMICOLON) { 153 return file.substring(startPos,contentStartPos)+";"; 154 } else { 155 return file.substring(startPos,endPos); 156 } 157 } 158 } 159 160 161 162 163 164