Source Code Cross Referenced for PackagesDependenciesAnalysis.java in  » IDE » tIDE » tide » utils » 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 » IDE » tIDE » tide.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tide.utils;
002:
003:        import tide.editor.*;
004:        import tide.sources.*;
005:        import snow.concurrent.*;
006:        import snow.utils.gui.*;
007:        import java.util.*;
008:
009:        /** Analyses packages interdependencies.
010:         */
011:        public final class PackagesDependenciesAnalysis {
012:            // name sorted
013:            final private Set<PackageNode> packageNodes = new TreeSet<PackageNode>();
014:            // usages and dependencies (line i elt uses col j)
015:            final private int[][] usages;
016:
017:            final String[] names;
018:
019:            public int[][] getUsagesMatrix() {
020:                return usages;
021:            }
022:
023:            public String[] getPackageNames() {
024:                return names;
025:            }
026:
027:            public PackagesDependenciesAnalysis(final List<SourceFile> sfs) {
028:                HashSet<SourceFile> packages = new HashSet<SourceFile>();
029:
030:                // 1) collect all packages
031:                for (SourceFile sfi : sfs) {
032:                    if (sfi.isJavaFile()) // so we not include empty packages !
033:                    {
034:                        packages.add((SourceFile) sfi.getParent());
035:                    }
036:                }
037:                System.out.println("" + packages.size() + " packages");
038:
039:                // create the package nodes
040:                for (SourceFile packi : packages) {
041:                    PackageNode pn = new PackageNode(packi.getPackageName());
042:                    packageNodes.add(pn);
043:
044:                    for (int i = 0; i < packi.getChildCount(); i++) {
045:                        SourceFile ci = packi.getChildFileAt(i);
046:                        if (ci.isJavaFile()) {
047:                            pn.directChilds.add(ci);
048:                        }
049:                    }
050:                }
051:
052:                // give them numbers to associate with the matrix
053:                int n = 0;
054:                names = new String[packageNodes.size()];
055:                for (PackageNode pn : packageNodes) {
056:                    pn.index = n;
057:                    names[n] = pn.packageName;
058:                    if (names[n].length() == 0) {
059:                        names[n] = "<unnamed scope>";
060:                    }
061:                    n++;
062:                }
063:
064:                // fill the dependency matrix (only look at "used by")
065:                usages = new int[packageNodes.size()][packageNodes.size()]; // filled with zeroes
066:
067:                for (PackageNode pn : packageNodes) {
068:                    //place the dependencies in the matrix
069:                    for (SourceFile sfi : pn.directChilds) {
070:                        for (SourceFile sui : sfi.sourceFileDependencies
071:                                .getClassesUsedBy_REF_()) // or classesUsingThis
072:                        {
073:                            String suipn = sui.getPackageName();
074:                            PackageNode up = getPackageNode(suipn);
075:                            if (up != null) {
076:                                usages[pn.index][up.index]++;
077:                            }
078:                        }
079:                    }
080:                }
081:
082:                // put 1 on the diagonal, caus a pacj$kage depends on itself (until empty, but
083:                //  this is not the case). This is important for matrix operations such as
084:                //  nested dependencies
085:                for (int i = 0; i < usages.length; i++) {
086:                    usages[i][i] = 1;
087:                }
088:
089:            }
090:
091:            @Override
092:            public String toString() {
093:                StringBuilder sb = new StringBuilder("\t\t");
094:                for (int i = 0; i < packageNodes.size(); i++) {
095:                    sb.append("\t" + (i + 1));
096:                }
097:                sb.append("\n\t\t");
098:                for (PackageNode pn : packageNodes) {
099:                    sb.append("\t" + pn.packageName);
100:                }
101:
102:                sb.append("\n");
103:
104:                int line = 0;
105:                for (PackageNode pn : packageNodes) {
106:                    sb.append("" + (line + 1) + "\t" + pn.packageName + "\t");
107:
108:                    for (int col = 0; col < usages[line].length; col++) {
109:                        sb.append("\t");
110:                        if (line == col) {
111:                            //sb.append("\\");
112:                        } else if (usages[line][col] == 0) {
113:
114:                        } else {
115:                            sb.append("" + usages[line][col]);
116:                        }
117:
118:                    }
119:
120:                    sb.append("\n");
121:                    line++;
122:                }
123:                return sb.toString();
124:            }
125:
126:            // Can be boosted with hashtables...
127:            private PackageNode getPackageNode(String name) {
128:                for (PackageNode pn : packageNodes) {
129:                    if (pn.packageName.equals(name))
130:                        return pn;
131:                }
132:                return null;
133:            }
134:
135:            class PackageNode implements  Comparable<PackageNode> {
136:                final String packageName;
137:                int index = -1;
138:                Set<SourceFile> directChilds = new HashSet<SourceFile>();
139:
140:                PackageNode(String name) {
141:                    this .packageName = name;
142:                }
143:
144:                public int compareTo(PackageNode pn) {
145:                    return packageName.compareTo(pn.packageName);
146:                }
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.