Source Code Cross Referenced for Behaviour.java in  » Development » jdec » net » sf » jdec » reflection » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » jdec » net.sf.jdec.reflection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Behaviour.java Copyright (c) 2006,07 Swaroop Belur
003:         *
004:         * This program is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License
006:         * as published by the Free Software Foundation; either version 2
007:         * of the License, or (at your option) any later version.
008:         
009:         * This program is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU General Public License for more details.
013:         
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software
016:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
017:         *
018:         */
019:
020:        package net.sf.jdec.reflection;
021:
022:        import java.util.ArrayList;
023:        import java.util.HashMap;
024:        import java.util.HashSet;
025:        import java.util.Iterator;
026:        import java.util.Map;
027:        import java.util.Set;
028:
029:        import net.sf.jdec.blocks.IFBlock;
030:        import net.sf.jdec.core.DecompilerHelper;
031:        import net.sf.jdec.core.GeneratedIfTracker;
032:        import net.sf.jdec.core.GlobalVariableStore;
033:        import net.sf.jdec.core.LocalVariableStructure;
034:        import net.sf.jdec.core.OperandStack;
035:        import net.sf.jdec.core.ShortcutAnalyser;
036:        import net.sf.jdec.core.GeneratedIfTracker.IfStore;
037:        import net.sf.jdec.util.Util;
038:
039:        /**
040:         * This Is a Class to indicate any code processing an Object of this type that
041:         * it is handling an object of a Class representing the behaviour of the Class.
042:         * According the Java terminology behaviour represents a method of a class <p/>
043:         * <p/> <p/> <br>
044:         * <br>
045:         * Example representation: Any Method or constructor<br>
046:         * Example Usage: In Disassembling Code Section
047:         */
048:
049:        public abstract class Behaviour {
050:
051:            private StringBuffer codeAsBuffer = new StringBuffer();
052:
053:            protected JavaClass classRef;
054:
055:            private Set methodIfs = new HashSet();
056:
057:            protected Map datatypesForParams = new HashMap();
058:
059:            private ArrayList variablesatfront = new ArrayList();
060:
061:            private java.lang.String vmInstructions = "";
062:
063:            private java.lang.String codeStatements = "";
064:
065:            private OperandStack opStack = new OperandStack();
066:
067:            private boolean hasBeenDissassembled = false;
068:
069:            private Behaviour parentBehaviour = null;
070:
071:            private LocalVariableStructure methodLocalVariables = null;
072:
073:            public abstract java.lang.String getBehaviourName();
074:
075:            public abstract void setShortCutAnalyser(ShortcutAnalyser sa);
076:
077:            public abstract ShortcutAnalyser getShortCutAnalyser();
078:
079:            private Map labels = new HashMap();
080:
081:            public abstract byte[] getCode();
082:
083:            /**
084:             * Called From Disassembled Section of the project
085:             * 
086:             * @param code
087:             *            represents the actual blocks for this method interpreted from
088:             *            the bytes of the code for this behaviour
089:             */
090:
091:            public void setVMInstructions(java.lang.String code) {
092:                vmInstructions = code;
093:            }
094:
095:            public java.lang.String getVMInstructions() {
096:                return vmInstructions;
097:            }
098:
099:            public java.lang.String getUserFriendlyMethodAccessors() {
100:                return null;
101:            }
102:
103:            public java.lang.String getReturnType() {
104:                return null;
105:            }
106:
107:            public java.lang.String getUserFriendlyMethodParams() {
108:                return null;
109:            }
110:
111:            public abstract int getNumberofparamters();
112:
113:            public abstract java.lang.String getStringifiedParameters();
114:
115:            public abstract String[] getMethodParams();
116:
117:            public OperandStack getOpStack() {
118:                return opStack;
119:            }
120:
121:            public void setOpStack(OperandStack opStack) {
122:                this .opStack = opStack;
123:            }
124:
125:            public boolean isHasBeenDissassembled() {
126:                return hasBeenDissassembled;
127:            }
128:
129:            public void setHasBeenDissassembled(boolean hasBeenDissassembled) {
130:                this .hasBeenDissassembled = hasBeenDissassembled;
131:            }
132:
133:            public Behaviour getParentBehaviour() {
134:                return parentBehaviour;
135:            }
136:
137:            public void setParentBehaviour(Behaviour parentBehaviour) {
138:                this .parentBehaviour = parentBehaviour;
139:            }
140:
141:            public java.lang.String getCodeStatements() {
142:                return codeStatements;
143:            }
144:
145:            public void setVariablesAtFront(ArrayList list) {
146:                variablesatfront = list;
147:            }
148:
149:            private void setCodeStatements(java.lang.String codeAsString) {
150:
151:                this .codeStatements = codeAsString;
152:                this .codeStatements = removeDummyLabels();
153:                this .codeStatements = removeLeftOverMarkers0();
154:                this .codeStatements = removeLeftOverMarkers1();
155:                // this.codeStatements=correctAnyInvalidSuperPosition(this.codeStatements);
156:                this .codeStatements = removeExtraSpaces0(this .codeStatements);
157:                this .codeStatements = removeExtraSpaces1(this .codeStatements);
158:                this .codeStatements = removeExtraJdecLabels(this .codeStatements); // Hack
159:                this .codeStatements = this .codeStatements.replaceAll("this\\$",
160:                        "This\\$");
161:                // this.codeStatements=removeOrphanJDECLabels(this.codeStatements);
162:                // TODO: Need to write better code for stripping extra spaces in code
163:                this .codeStatements = this .codeStatements.replaceAll("\\)   ",
164:                        "\\)");
165:                this .codeStatements = this .codeStatements.replaceAll("\\)   ",
166:                        "\\)");
167:                this .codeStatements = this .codeStatements.replaceAll("\\)   ",
168:                        "\\)");
169:                this .codeStatements = addVariablesAtFront(this .codeStatements);
170:                //this.codeStatements = this.codeStatements.replaceAll("\r\n\r\n", "\r\n");
171:                replaceDoWhileMarkersWithIfs();
172:                //this.codeStatements=Util.formatDecompiledStatement(this.codeStatements);
173:            }
174:
175:            private void replaceDoWhileMarkersWithIfs() {
176:                if (GlobalVariableStore.getDowhileloopmarkers().size() > 0) {
177:                    int size = GlobalVariableStore.getDowhileloopmarkers()
178:                            .size();
179:                    String ls = "//INSERT IFCODE FOR DOWHILE HERE";
180:                    String ifs = "<IF_AT_LOOP_END_BEGIN_";
181:                    String ife = "<IF_AT_LOOP_END_END_";
182:                    for (int i = 0; i < size; i++) {
183:                        int temp = ((Integer) GlobalVariableStore
184:                                .getDowhileloopmarkers().get(i)).intValue();
185:                        ls = ls + temp;
186:                        ifs = ifs + temp + "_>";
187:                        ife = ife + temp + "_>";
188:                        int lindex = codeStatements.indexOf(ls);
189:                        if (lindex != -1) {
190:                            int start = codeStatements.indexOf(ifs, lindex + 1);
191:                            if (start != -1) {
192:                                int end = codeStatements
193:                                        .indexOf(ife, start + 1);
194:                                if (end != -1) {
195:                                    int tempStart = start;
196:                                    start = start + ifs.length();
197:                                    String reqdif = codeStatements.substring(
198:                                            start, end);
199:                                    String sub1 = codeStatements.substring(0,
200:                                            tempStart);
201:                                    String sub2 = codeStatements.substring(end
202:                                            + ife.length());
203:                                    codeStatements = sub1 + sub2;
204:                                    codeStatements = codeStatements
205:                                            .replaceFirst(ls, reqdif);
206:
207:                                }
208:                            } else {
209:                                codeStatements = codeStatements.replaceFirst(
210:                                        ls, "");
211:                            }
212:                        }
213:
214:                        ifs = "<IF_AT_LOOP_END_BEGIN_";
215:                        ife = "<IF_AT_LOOP_END_END_";
216:                        ls = "//INSERT IFCODE FOR DOWHILE HERE";
217:
218:                    }
219:                }
220:            }
221:
222:            private void removeInvalidElseBreaksAtIfEnd() {
223:                Iterator iterator = getMethodIfs().iterator();
224:                while (iterator.hasNext()) {
225:                    IFBlock ifb = (IFBlock) iterator.next();
226:                    if (ifb.isElsebreakinvalid()) {
227:                        int start = ifb.getIfStart();
228:                        String marker = "<elsebreak" + start + ">";
229:                        String endmarker = "</elsebreak" + start + ">";
230:                        int markerIndex = codeAsBuffer.indexOf(marker);
231:                        if (markerIndex != -1) {
232:                            int endmarkerIndex = codeAsBuffer.indexOf(
233:                                    endmarker, markerIndex + 1);
234:                            if (endmarkerIndex != -1) {
235:                                endmarkerIndex += endmarker.length();
236:                                /*if ((endmarkerIndex + 1) < codeAsBuffer.length()) {
237:                                	endmarkerIndex = endmarkerIndex + 1;
238:                                }*/
239:                                if (endmarkerIndex < codeAsBuffer.length()) {
240:                                    codeAsBuffer.replace(markerIndex,
241:                                            endmarkerIndex, "");
242:                                }
243:
244:                            }
245:
246:                        }
247:                    } else {
248:                        int start = ifb.getIfStart();
249:                        String marker = "<elsebreak" + start + ">";
250:                        int markerIndex = codeAsBuffer.indexOf(marker);
251:                        if (markerIndex != -1) {
252:                            int endmarkerIndex = markerIndex + marker.length();
253:                            //endmarkerIndex = endmarkerIndex + 1;
254:                            codeAsBuffer.replace(markerIndex, endmarkerIndex,
255:                                    "");
256:
257:                        }
258:
259:                        marker = "</elsebreak" + start + ">";
260:                        markerIndex = codeAsBuffer.indexOf(marker);
261:                        if (markerIndex != -1) {
262:                            int endmarkerIndex = markerIndex + marker.length();
263:                            //endmarkerIndex = endmarkerIndex + 1;
264:                            codeAsBuffer.replace(markerIndex, endmarkerIndex,
265:                                    "");
266:
267:                        }
268:
269:                    }
270:                }
271:            }
272:
273:            public void filterCode(GeneratedIfTracker generatedIfTracker) {
274:                removeInvalidElseBreaksAtIfEnd();
275:                setCodeStatements(codeAsBuffer.toString());
276:                removeInvalidGeneratedIfs(generatedIfTracker);
277:            }
278:
279:            private void removeInvalidGeneratedIfs(
280:                    GeneratedIfTracker generatedIfTracker) {
281:                Map ifs = generatedIfTracker.getIfs();
282:                Iterator iterator = ifs.entrySet().iterator();
283:                while (iterator.hasNext()) {
284:                    Map.Entry entry = (Map.Entry) iterator.next();
285:                    IfStore aif = (IfStore) entry.getKey();
286:                    if (aif.isInvalid()) {
287:                        String name = aif.getName();
288:                        String toRemove = name + "=false;";
289:                        this .codeStatements = codeStatements.replaceAll(
290:                                toRemove, "");
291:                        toRemove = "boolean " + name + "= true;";
292:                        this .codeStatements = codeStatements.replaceAll(
293:                                toRemove, "");
294:                    }
295:                }
296:
297:            }
298:
299:            public LocalVariableStructure getLocalVariables() {
300:                return methodLocalVariables;
301:            }
302:
303:            public void setMethodLocalVariables(
304:                    LocalVariableStructure methodLocalVariables) {
305:                this .methodLocalVariables = methodLocalVariables;
306:            }
307:
308:            public abstract java.lang.String[] getMethodAccessors();
309:
310:            public abstract void setExceptionTableList(ArrayList tables);
311:
312:            public abstract ArrayList getExceptionTableList();
313:
314:            public abstract ArrayList getAllTriesForMethod();
315:
316:            public abstract void setAllTriesForMethod(ArrayList alltries);
317:
318:            public abstract void setCreatedTableList(ArrayList list);
319:
320:            public abstract ArrayList getCreatedTableList();
321:
322:            protected ArrayList exceptionTables;
323:
324:            public abstract String[] getExceptionTypes();
325:
326:            public abstract java.lang.String getDeclaringClass();
327:
328:            public abstract ArrayList getAllSwitchBlks();
329:
330:            public abstract void setSynchronizedTableEntries(ArrayList list);
331:
332:            public abstract ArrayList getSynchronizedEntries();
333:
334:            public abstract ArrayList getBehaviourLoops();
335:
336:            public abstract void setBehaviourLoops(ArrayList list);
337:
338:            public abstract ArrayList getInstructionStartPositions();
339:
340:            public Map getLabels() {
341:                return labels;
342:            }
343:
344:            public void setLabels(Map labels) {
345:                this .labels = labels;
346:            }
347:
348:            protected abstract java.lang.String removeDummyLabels();
349:
350:            protected boolean isConstructor = false;
351:
352:            // public abstract boolean isMethodConstructor();
353:            // public abstract void setMethodAsConstructor(boolean c);
354:
355:            private java.lang.String correctAnyInvalidSuperPosition(
356:                    java.lang.String codeS) {
357:                java.lang.String temp4 = codeS.trim();
358:                int index = temp4.indexOf("super(");
359:                if (index == 0)
360:                    return codeS;
361:
362:                index = codeS.indexOf("super(");
363:                if (index != -1) {
364:                    java.lang.String temp = codeS.substring(0, index);
365:                    int semi = codeS.indexOf(";", index);
366:                    if (semi != -1) {
367:                        java.lang.String temp2 = codeS.substring(semi + 1);
368:                        java.lang.String temp3 = temp + temp2;
369:                        java.lang.String s = codeS.substring(index, semi + 1);
370:                        return "\t" + "\t" + "\t" + "\t" + s + "\n" + temp3;
371:
372:                    } else
373:                        return codeS; // Invalid return actually
374:                } else
375:                    return codeS;
376:
377:            }
378:
379:            public java.lang.String getShortDescription() {
380:
381:                java.lang.String desc = "";
382:                desc += "\n[Name ]:" + this .getBehaviourName() + "\n";
383:                desc += "[Parameters ]:" + this .getUserFriendlyMethodParams()
384:                        + "\n";
385:                desc += "[Accessors ]:" + this .getUserFriendlyMethodAccessors()
386:                        + "\n";
387:                desc += "[Return TYpe ]:" + this .getReturnType() + "\n";
388:                desc += "[Belonging Class ]:" + this .getDeclaringClass() + "\n";
389:                return desc;
390:
391:            }
392:
393:            public java.lang.String removeLeftOverMarkers0() {
394:                ArrayList codeList = new ArrayList();
395:                java.lang.String temp = getCodeStatements();
396:                // if(getLabels()==null || getLabels().size()==0)return temp;
397:                int i = -1;
398:                int start = 0;
399:                String copy = getCodeStatements();
400:                i = copy.indexOf("#REPLACE_INT_", start);
401:                if (i == -1) {
402:                    String sr = copy;
403:                    sr = sr.replaceAll("\n\n", "\n");
404:                    return sr;
405:
406:                }
407:                while (i != -1) {
408:                    int j = i + 13;
409:                    int hash = copy.indexOf("#", (i + 1));
410:                    java.lang.String num = copy.substring(j, hash);
411:                    java.lang.String dummy = copy.substring(i, (hash + 1));
412:                    boolean excep = false;
413:                    try {
414:                        int inum = Integer.parseInt(num);
415:                    } catch (NumberFormatException ne) {
416:                        excep = true;
417:
418:                    }
419:                    if (!excep) {
420:                        String tempCode = copy.substring(0, i);
421:                        copy = copy.substring(i);
422:                        copy = copy.replaceFirst(dummy, "");
423:                        codeList.add(tempCode);
424:                        i = copy.indexOf("#REPLACE_INT_", start);
425:                        if (i == -1) {
426:                            codeList.add(copy);
427:                        }
428:                    } else {
429:                        String tempCode = copy.substring(0, j);
430:                        copy = copy.substring(j);
431:                        codeList.add(tempCode);
432:                        i = copy.indexOf("#REPLACE_INT_", start);
433:                        if (i == -1) {
434:                            codeList.add(copy);
435:                        }
436:                    }
437:
438:                }
439:                StringBuffer buf = new StringBuffer("");
440:                for (int k = 0; k < codeList.size(); k++) {
441:                    buf.append(codeList.get(k).toString());
442:                }
443:
444:                temp = buf.toString();
445:                temp = temp.replaceAll("\n\n", "\n");
446:
447:                return temp;
448:
449:            }
450:
451:            public java.lang.String removeLeftOverMarkers1() {
452:                ArrayList codeList = new ArrayList();
453:                java.lang.String temp = getCodeStatements();
454:                // if(getLabels()==null || getLabels().size()==0)return temp;
455:                int i = -1;
456:                int start = 0;
457:                String copy = getCodeStatements();
458:                i = copy.indexOf("#VALUE", start);
459:                if (i == -1) {
460:                    String sr = copy;
461:                    sr = sr.replaceAll("\n\n", "\n");
462:                    return sr;
463:                }
464:
465:                while (i != -1) {
466:                    int j = i + 6;
467:                    int hash = copy.indexOf("#", (i + 1));
468:                    java.lang.String num = copy.substring(j, hash);
469:                    java.lang.String dummy = copy.substring(i, (hash + 1));
470:                    boolean excep = false;
471:                    try {
472:                        int inum = Integer.parseInt(num);
473:                    } catch (NumberFormatException ne) {
474:                        excep = true;
475:
476:                    }
477:                    if (!excep) {
478:                        String tempCode = copy.substring(0, i);
479:                        copy = copy.substring(i);
480:                        copy = copy.replaceFirst(dummy, "");
481:                        codeList.add(tempCode);
482:                        i = copy.indexOf("#VALUE", start);
483:                        if (i == -1) {
484:                            codeList.add(copy);
485:                        }
486:                    } else {
487:                        String tempCode = copy.substring(0, j);
488:                        copy = copy.substring(j);
489:                        codeList.add(tempCode);
490:                        i = copy.indexOf("#VALUE", start);
491:                        if (i == -1) {
492:                            codeList.add(copy);
493:                        }
494:                    }
495:
496:                }
497:                StringBuffer buf = new StringBuffer("");
498:                for (int k = 0; k < codeList.size(); k++) {
499:                    buf.append(codeList.get(k).toString());
500:                }
501:
502:                temp = buf.toString();
503:                temp = temp.replaceAll("\n\n", "\n");
504:
505:                return temp;
506:
507:            }
508:
509:            public abstract boolean isMethodConstructor();
510:
511:            private java.lang.String removeExtraSpaces0(java.lang.String codes) {
512:
513:                java.lang.String temp = codes;
514:                int j = temp.indexOf("||");
515:                if (j == -1)
516:                    return temp;
517:                else {
518:                    while (j != -1) {
519:                        java.lang.String temp1 = temp.substring(0, j + 2);
520:                        int k = j + 2;
521:                        if (k < temp.length()) {
522:                            char c = temp.charAt(k);
523:                            while (c == ' ') {
524:                                k++;
525:                                if (k >= temp.length())
526:                                    return codes;// Should Not happen
527:                                c = temp.charAt(k);
528:                            }
529:                            temp1 = temp1 + " ";
530:                            java.lang.String temp2 = temp.substring(k);
531:                            temp1 = temp1 + temp2;
532:                            temp = temp1;
533:                            j = temp.indexOf("||", j + 2);
534:
535:                        } else {
536:                            return codes; // should not happen
537:                        }
538:                    }
539:
540:                }
541:                // temp=temp.replaceAll(" "," ");
542:                return temp;
543:
544:            }
545:
546:            private java.lang.String removeExtraSpaces1(java.lang.String codes) {
547:
548:                java.lang.String temp = codes;
549:                int j = temp.indexOf("||");
550:                if (j == -1)
551:                    return codes;
552:                else {
553:                    while (j != -1) {
554:                        int next = j + 2;
555:                        if (next >= temp.length())
556:                            return codes;
557:                        char c = temp.charAt(next);
558:                        while (c == ' ') {
559:                            next++;
560:                            if (next >= temp.length())
561:                                return codes;
562:                            c = temp.charAt(next);
563:                        }
564:                        if (c == ';') {
565:
566:                            do {
567:                                next++;
568:                                if (next >= temp.length())
569:                                    return codes;
570:                                c = temp.charAt(next);
571:                            } while (c == ' ' || c == '\n' || c == '\r'
572:                                    || c == '\t');
573:
574:                        }
575:                        while (c != ' ') {
576:                            if (c == ';') {
577:                                do {
578:                                    next++;
579:                                    if (next >= temp.length())
580:                                        return codes;
581:                                    c = temp.charAt(next);
582:                                } while (c == ' ' || c == '\n' || c == '\r'
583:                                        || c == '\t');
584:                            }
585:
586:                            next++;
587:                            if (next >= temp.length())
588:                                return codes;
589:                            c = temp.charAt(next);
590:                        }
591:                        // next++;
592:                        if ((next + 1) >= temp.length())
593:                            return codes;
594:
595:                        java.lang.String temp1 = temp.substring(0, next);
596:                        while (c == ' ') {
597:                            next++;
598:                            if (next >= temp.length())
599:                                return codes;
600:                            c = temp.charAt(next);
601:                        }
602:                        temp1 = temp1 + " ";
603:                        temp1 = temp1 + temp.substring(next);
604:                        temp = temp1;
605:                        j = temp.indexOf("||", j + 2);
606:                    }
607:
608:                }
609:                return temp;
610:            }
611:
612:            private java.lang.String removeOrphanJDECLabels(
613:                    java.lang.String codes) {
614:
615:                java.lang.String temp = codes;
616:
617:                int fromwhere = temp.indexOf("jdecLABEL");
618:                if (fromwhere == -1)
619:                    return codes;
620:                boolean processed = false;
621:                do {
622:                    int index = fromwhere;
623:                    int colon = temp.indexOf(":", index);
624:                    int start = index + 9;
625:                    java.lang.String lbl = "jdecLABEL"
626:                            + temp.substring(start, colon);
627:                    int nextIndex = temp.indexOf(lbl, index + 1);
628:                    if (nextIndex == -1) {
629:                        temp = temp.replaceAll(lbl + ":", "");
630:                        processed = true;
631:                    }
632:                } while ((fromwhere = temp.indexOf("jdecLABEL", fromwhere + 9)) != -1);
633:
634:                return (processed == true) ? temp : codes;
635:
636:            }
637:
638:            public abstract void createExceptionTableInStringifiedForm();
639:
640:            public abstract String getShortExceptionTableDetails();
641:
642:            public abstract String getDetailedExceptionTableDetails();
643:
644:            public abstract String getSynchTableDetails();
645:
646:            private ArrayList varatfrontTemp = new ArrayList();
647:
648:            private java.lang.String removeExtraJdecLabels(
649:                    java.lang.String input) {
650:
651:                java.lang.String output = input;
652:                if (output.indexOf("jdecLABEL") == -1)
653:                    return output;
654:                int i = output.indexOf("jdecLABEL");
655:                while (i != -1) {
656:                    int colon = output.indexOf(":", i);
657:                    if (colon != -1) {
658:                        java.lang.String lbl = output.substring(i, colon);
659:                        try {
660:                            String number = output.substring(i + 9, colon);
661:                            int num = Integer.parseInt(number);
662:                            int j = output.indexOf(lbl, colon + 1);
663:                            if (j == -1) {
664:                                output = output.replaceFirst(lbl + ":", "");
665:                            }
666:                            i = output.indexOf("jdecLABEL", colon);
667:                        } catch (NumberFormatException ne) {
668:                            i = output.indexOf("jdecLABEL", colon);
669:                        }
670:
671:                    } else {
672:                        i = output.indexOf("jdecLABEL", i + 8);
673:                    }
674:
675:                }
676:                return output;
677:            }
678:
679:            // Bug Here
680:            private String addVariablesAtFront(String code) {
681:                if (variablesatfront == null || variablesatfront.size() == 0)
682:                    return code;
683:                String front = "";
684:                for (int z = 0; z < variablesatfront.size(); z++) {
685:                    DecompilerHelper.VariableAtFront v = (DecompilerHelper.VariableAtFront) variablesatfront
686:                            .get(z);
687:                    String temp = v.getType() + " " + v.getName() + "= "
688:                            + v.getInitial() + ";\n";
689:                    temp = Util.formatFieldsOrMethodHeader(temp, "field");
690:                    varatfrontTemp.add("   " + temp);
691:                }
692:                varatfrontTemp = removeDuplicates(varatfrontTemp);
693:                for (int k = 0; k < varatfrontTemp.size(); k++) {
694:                    String t = (String) varatfrontTemp.get(k);
695:                    front += t;
696:                    if (!t.endsWith("\n")) {
697:                        front += "\n";
698:                    }
699:                }
700:                boolean added = false;
701:                if (this  instanceof  ConstructorMember) {
702:
703:                    int m = code.indexOf("super(");
704:                    if (m == -1) {
705:                        m = code.indexOf("this(");
706:                    }
707:                    if (m != -1) {
708:
709:                        int semi = code.indexOf(";", m);
710:                        if (semi != -1) {
711:                            String t1 = code.substring(0, semi + 1);
712:                            String t2 = code.substring(semi + 1);
713:                            code = t1 + "\n" + front + t2;
714:                            added = true;
715:                        }
716:                    }
717:                }
718:                if (added == false)
719:                    code = front + code;
720:                return code;
721:
722:            }
723:
724:            public static ArrayList removeDuplicates(ArrayList input) {
725:                ArrayList updatedList = new ArrayList();
726:                if (input != null && input.size() > 0) {
727:                    String[] fullList = (java.lang.String[]) input
728:                            .toArray(new java.lang.String[] {});
729:                    java.util.Arrays.sort(fullList);
730:                    updatedList.add(fullList[0]);
731:                    for (int s = 1; s < fullList.length; s++) {
732:                        if (s < fullList.length) {
733:                            String currentItem = fullList[s];
734:                            // currentItem=currentItem.trim();
735:                            int prev = s - 1;
736:                            String temp = "";
737:                            if (prev >= 0 && prev < fullList.length) {
738:                                temp = fullList[prev];
739:                                // /temp=temp.trim();
740:                                if (temp.equals(currentItem) == false) {
741:                                    // if(currentItem.indexOf("[")==-1) ??
742:                                    updatedList.add(currentItem);
743:                                }
744:                            }
745:
746:                        }
747:
748:                    }
749:
750:                }
751:                return updatedList;
752:
753:            }
754:
755:            public JavaClass getClassRef() {
756:                return classRef;
757:            }
758:
759:            public abstract void setClassRef(JavaClass classRef);
760:
761:            public Map getDatatypesForParams() {
762:                return datatypesForParams;
763:            }
764:
765:            public abstract void setDatatypesForParams(Map datatypesForParams);
766:
767:            public Set getMethodIfs() {
768:                return methodIfs;
769:            }
770:
771:            public String appendToBuffer(String string) {
772:                //if(string.indexOf("}") != -1)string=string+ExecutionState.getCurrentInstructionPosition();
773:                codeAsBuffer.append(string);
774:                return null;
775:            }
776:
777:            public void replaceBuffer(String string) {
778:                codeAsBuffer = new StringBuffer(string);
779:            }
780:
781:            public void replaceBuffer(StringBuffer stringbuffer) {
782:                codeAsBuffer = stringbuffer;
783:            }
784:
785:            public StringBuffer getCodeAsBuffer() {
786:                return codeAsBuffer;
787:            }
788:
789:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.