Source Code Cross Referenced for CompilationUnitVisitor.java in  » Net » Terracotta » org » terracotta » dso » 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 » Net » Terracotta » org.terracotta.dso 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package org.terracotta.dso;
006:
007:        import org.eclipse.core.resources.IMarker;
008:        import org.eclipse.core.resources.IProject;
009:        import org.eclipse.core.resources.IResource;
010:        import org.eclipse.core.resources.IResourceRuleFactory;
011:        import org.eclipse.core.resources.IWorkspace;
012:        import org.eclipse.core.resources.IWorkspaceRunnable;
013:        import org.eclipse.core.resources.ResourcesPlugin;
014:        import org.eclipse.core.runtime.CoreException;
015:        import org.eclipse.core.runtime.IProgressMonitor;
016:        import org.eclipse.core.runtime.jobs.ISchedulingRule;
017:        import org.eclipse.jdt.core.ICompilationUnit;
018:        import org.eclipse.jdt.core.IField;
019:        import org.eclipse.jdt.core.IMethod;
020:        import org.eclipse.jdt.core.IType;
021:        import org.eclipse.jdt.core.JavaModelException;
022:        import org.eclipse.jdt.core.dom.AST;
023:        import org.eclipse.jdt.core.dom.ASTNode;
024:        import org.eclipse.jdt.core.dom.ASTParser;
025:        import org.eclipse.jdt.core.dom.ASTVisitor;
026:        import org.eclipse.jdt.core.dom.Annotation;
027:        import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
028:        import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
029:        import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
030:        import org.eclipse.jdt.core.dom.ArrayAccess;
031:        import org.eclipse.jdt.core.dom.ArrayCreation;
032:        import org.eclipse.jdt.core.dom.ArrayInitializer;
033:        import org.eclipse.jdt.core.dom.ArrayType;
034:        import org.eclipse.jdt.core.dom.AssertStatement;
035:        import org.eclipse.jdt.core.dom.Assignment;
036:        import org.eclipse.jdt.core.dom.Block;
037:        import org.eclipse.jdt.core.dom.BlockComment;
038:        import org.eclipse.jdt.core.dom.BooleanLiteral;
039:        import org.eclipse.jdt.core.dom.BreakStatement;
040:        import org.eclipse.jdt.core.dom.CastExpression;
041:        import org.eclipse.jdt.core.dom.CatchClause;
042:        import org.eclipse.jdt.core.dom.CharacterLiteral;
043:        import org.eclipse.jdt.core.dom.ClassInstanceCreation;
044:        import org.eclipse.jdt.core.dom.CompilationUnit;
045:        import org.eclipse.jdt.core.dom.ConditionalExpression;
046:        import org.eclipse.jdt.core.dom.ConstructorInvocation;
047:        import org.eclipse.jdt.core.dom.ContinueStatement;
048:        import org.eclipse.jdt.core.dom.DoStatement;
049:        import org.eclipse.jdt.core.dom.EmptyStatement;
050:        import org.eclipse.jdt.core.dom.EnhancedForStatement;
051:        import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
052:        import org.eclipse.jdt.core.dom.EnumDeclaration;
053:        import org.eclipse.jdt.core.dom.ExpressionStatement;
054:        import org.eclipse.jdt.core.dom.FieldAccess;
055:        import org.eclipse.jdt.core.dom.FieldDeclaration;
056:        import org.eclipse.jdt.core.dom.ForStatement;
057:        import org.eclipse.jdt.core.dom.IMethodBinding;
058:        import org.eclipse.jdt.core.dom.ITypeBinding;
059:        import org.eclipse.jdt.core.dom.IVariableBinding;
060:        import org.eclipse.jdt.core.dom.IfStatement;
061:        import org.eclipse.jdt.core.dom.ImportDeclaration;
062:        import org.eclipse.jdt.core.dom.InfixExpression;
063:        import org.eclipse.jdt.core.dom.Initializer;
064:        import org.eclipse.jdt.core.dom.InstanceofExpression;
065:        import org.eclipse.jdt.core.dom.Javadoc;
066:        import org.eclipse.jdt.core.dom.LabeledStatement;
067:        import org.eclipse.jdt.core.dom.LineComment;
068:        import org.eclipse.jdt.core.dom.MarkerAnnotation;
069:        import org.eclipse.jdt.core.dom.MemberRef;
070:        import org.eclipse.jdt.core.dom.MemberValuePair;
071:        import org.eclipse.jdt.core.dom.MethodDeclaration;
072:        import org.eclipse.jdt.core.dom.MethodInvocation;
073:        import org.eclipse.jdt.core.dom.MethodRef;
074:        import org.eclipse.jdt.core.dom.MethodRefParameter;
075:        import org.eclipse.jdt.core.dom.Modifier;
076:        import org.eclipse.jdt.core.dom.NormalAnnotation;
077:        import org.eclipse.jdt.core.dom.NullLiteral;
078:        import org.eclipse.jdt.core.dom.NumberLiteral;
079:        import org.eclipse.jdt.core.dom.PackageDeclaration;
080:        import org.eclipse.jdt.core.dom.ParameterizedType;
081:        import org.eclipse.jdt.core.dom.ParenthesizedExpression;
082:        import org.eclipse.jdt.core.dom.PostfixExpression;
083:        import org.eclipse.jdt.core.dom.PrefixExpression;
084:        import org.eclipse.jdt.core.dom.PrimitiveType;
085:        import org.eclipse.jdt.core.dom.QualifiedName;
086:        import org.eclipse.jdt.core.dom.QualifiedType;
087:        import org.eclipse.jdt.core.dom.ReturnStatement;
088:        import org.eclipse.jdt.core.dom.SimpleName;
089:        import org.eclipse.jdt.core.dom.SimpleType;
090:        import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
091:        import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
092:        import org.eclipse.jdt.core.dom.Statement;
093:        import org.eclipse.jdt.core.dom.StringLiteral;
094:        import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
095:        import org.eclipse.jdt.core.dom.SuperFieldAccess;
096:        import org.eclipse.jdt.core.dom.SuperMethodInvocation;
097:        import org.eclipse.jdt.core.dom.SwitchCase;
098:        import org.eclipse.jdt.core.dom.SwitchStatement;
099:        import org.eclipse.jdt.core.dom.SynchronizedStatement;
100:        import org.eclipse.jdt.core.dom.TagElement;
101:        import org.eclipse.jdt.core.dom.TextElement;
102:        import org.eclipse.jdt.core.dom.ThisExpression;
103:        import org.eclipse.jdt.core.dom.ThrowStatement;
104:        import org.eclipse.jdt.core.dom.TryStatement;
105:        import org.eclipse.jdt.core.dom.Type;
106:        import org.eclipse.jdt.core.dom.TypeDeclaration;
107:        import org.eclipse.jdt.core.dom.TypeLiteral;
108:        import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
109:        import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
110:        import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
111:        import org.eclipse.jdt.core.dom.WhileStatement;
112:        import org.eclipse.jdt.core.dom.WildcardType;
113:        import org.eclipse.ui.texteditor.MarkerUtilities;
114:
115:        import com.tc.aspectwerkz.reflect.ClassInfo;
116:        import com.tc.aspectwerkz.reflect.FieldInfo;
117:        import com.tc.aspectwerkz.reflect.MethodInfo;
118:
119:        import java.util.HashMap;
120:        import java.util.Iterator;
121:        import java.util.List;
122:        import java.util.Map;
123:
124:        /**
125:         * An Abstract Syntax Tree (AST) visitor that is used for inspecting modules
126:         * for the purpose of defining Terracotta-specific annotations as for creating
127:         * type summaries for use in various chooser dialogs.
128:         * 
129:         * @see org.eclipse.jdt.core.dom.ASTVisitor
130:         * @see org.eclipse.jdt.core.ICompilationUnit
131:         * @see org.terracotta.dso.ConfigurationHelper
132:         */
133:
134:        public class CompilationUnitVisitor extends ASTVisitor {
135:            private IProject m_project;
136:            private IResource m_res;
137:            private CompilationUnit m_ast;
138:            private ConfigurationHelper m_configHelper;
139:            private InspectionAction m_inspector;
140:
141:            private static final TcPlugin m_plugin = TcPlugin.getDefault();
142:
143:            public CompilationUnitVisitor() {
144:                super ();
145:                m_inspector = new InspectionAction();
146:            }
147:
148:            protected void setup(ICompilationUnit cu)
149:                    throws JavaModelException, CoreException {
150:                m_res = cu.getBuffer().getUnderlyingResource();
151:                m_project = cu.getJavaProject().getProject();
152:                m_configHelper = m_plugin.getConfigurationHelper(m_project);
153:                m_inspector = new InspectionAction();
154:            }
155:
156:            public void inspect(final ICompilationUnit cu) {
157:                try {
158:                    IWorkspace workspace = ResourcesPlugin.getWorkspace();
159:
160:                    if (!workspace.isTreeLocked()) {
161:                        IResourceRuleFactory ruleFactory = workspace
162:                                .getRuleFactory();
163:                        ISchedulingRule rule = ruleFactory.markerRule(cu
164:                                .getResource());
165:
166:                        m_inspector.setTarget(cu);
167:                        ResourcesPlugin.getWorkspace().run(m_inspector, rule,
168:                                IWorkspace.AVOID_UPDATE, null);
169:                    }
170:                } catch (CoreException ce) {
171:                    m_plugin.openError("Problem inspecting '"
172:                            + cu.getElementName() + "'", ce);
173:                }
174:            }
175:
176:            class InspectionAction implements  IWorkspaceRunnable {
177:                private ICompilationUnit m_target;
178:
179:                void setTarget(ICompilationUnit target) {
180:                    m_target = target;
181:                }
182:
183:                public void run(IProgressMonitor monitor) throws CoreException {
184:                    setup(m_target);
185:
186:                    clearTerracottaMarkers();
187:
188:                    ASTParser parser = ASTParser.newParser(AST.JLS3);
189:                    parser.setSource(m_target);
190:                    parser.setResolveBindings(true);
191:
192:                    m_ast = (CompilationUnit) parser.createAST(monitor);
193:                    m_ast.accept(CompilationUnitVisitor.this );
194:
195:                    m_plugin.updateDecorators();
196:                    m_configHelper.validateAll();
197:                }
198:            }
199:
200:            public boolean visit(CompilationUnit node) {
201:                return true;
202:            }
203:
204:            private static IType typeFromTypeBinding(ITypeBinding typeBinding) {
205:                if (typeBinding != null) {
206:                    Object o = typeBinding.getJavaElement();
207:                    if (o instanceof  IType) {
208:                        return (IType) o;
209:                    }
210:                }
211:                return null;
212:            }
213:
214:            public boolean visit(TypeDeclaration node) {
215:                ITypeBinding binding = node.resolveBinding();
216:                if (binding != null) {
217:                    IType type = typeFromTypeBinding(binding);
218:                    ClassInfo classInfo = PatternHelper.getHelper()
219:                            .getClassInfo(type);
220:                    if (classInfo instanceof  JavaModelClassInfo) {
221:                        JavaModelClassInfo jmci = (JavaModelClassInfo) classInfo;
222:                        jmci.clearAnnotations();
223:                        for (Object o : node.modifiers()) {
224:                            if (o instanceof  Annotation) {
225:                                jmci.addAnnotation((Annotation) o);
226:                            }
227:                        }
228:                    }
229:
230:                    if (type != null) {
231:                        String fullName = PatternHelper
232:                                .getFullyQualifiedName(type);
233:
234:                        if (m_configHelper.isAdaptable(fullName)) {
235:                            addMarker("adaptedTypeMarker", "DSO Adapted Type",
236:                                    node.getName());
237:                        } else if (m_configHelper.isExcluded(fullName)) {
238:                            addMarker("excludedTypeMarker",
239:                                    "DSO Excluded Type", node.getName());
240:                        }
241:                    }
242:
243:                    List super Interfaces = node.super InterfaceTypes();
244:                    if (super Interfaces != null) {
245:                        for (Iterator iter = super Interfaces.iterator(); iter
246:                                .hasNext();) {
247:                            Type t = (Type) iter.next();
248:                            binding = t.resolveBinding();
249:
250:                            if (binding != null && !binding.isPrimitive()
251:                                    && !binding.isTypeVariable()) {
252:                                type = typeFromTypeBinding(binding);
253:
254:                                String fullName = PatternHelper
255:                                        .getFullyQualifiedName(type);
256:                                if (m_plugin.isBootClass(fullName)) {
257:                                    addMarker("bootJarTypeMarker",
258:                                            "BootJar Type", t);
259:                                } else if (m_configHelper.isAdaptable(fullName)) {
260:                                    addMarker("adaptedTypeReferenceMarker",
261:                                            "DSO Instrumented Type Reference",
262:                                            t);
263:                                } else if (m_configHelper.isExcluded(fullName)) {
264:                                    addMarker("excludedTypeMarker",
265:                                            "DSO Excluded Type", t);
266:                                }
267:                            }
268:                        }
269:                    }
270:
271:                    Type super Type = node.getSuperclassType();
272:                    if (super Type != null) {
273:                        binding = super Type.resolveBinding();
274:
275:                        if (binding != null && !binding.isPrimitive()
276:                                && !binding.isTypeVariable()) {
277:                            type = typeFromTypeBinding(binding);
278:
279:                            if (type != null) {
280:                                String fullName = PatternHelper
281:                                        .getFullyQualifiedName(type);
282:
283:                                if (m_plugin.isBootClass(fullName)) {
284:                                    addMarker("bootJarTypeMarker",
285:                                            "BootJar Type", super Type);
286:                                } else if (m_configHelper.isAdaptable(fullName)) {
287:                                    addMarker("adaptedTypeReferenceMarker",
288:                                            "DSO Instrumented Type Reference",
289:                                            super Type);
290:                                } else if (m_configHelper.isExcluded(fullName)) {
291:                                    addMarker("excludedTypeMarker",
292:                                            "DSO Excluded Type", super Type);
293:                                }
294:                            }
295:                        }
296:                    }
297:                }
298:
299:                return true;
300:            }
301:
302:            public boolean visit(FieldDeclaration node) {
303:                Type typeNode = node.getType();
304:                ITypeBinding binding = typeNode.resolveBinding();
305:
306:                if (binding != null && !binding.isPrimitive()
307:                        && (binding.isClass() || binding.isInterface())) {
308:                    IType type = typeFromTypeBinding(binding);
309:
310:                    List fragments = node.fragments();
311:                    Iterator<VariableDeclarationFragment> fragIter = fragments
312:                            .iterator();
313:                    while (fragIter.hasNext()) {
314:                        VariableDeclarationFragment vdf = fragIter.next();
315:                        IField field = (IField) vdf.resolveBinding()
316:                                .getJavaElement();
317:                        FieldInfo fieldInfo = PatternHelper.getHelper()
318:                                .getFieldInfo(field);
319:                        if (fieldInfo instanceof  JavaModelFieldInfo) {
320:                            JavaModelFieldInfo jmfi = (JavaModelFieldInfo) fieldInfo;
321:                            jmfi.clearAnnotations();
322:                            for (Object o : node.modifiers()) {
323:                                if (o instanceof  Annotation) {
324:                                    jmfi.addAnnotation((Annotation) o);
325:                                }
326:                            }
327:                        }
328:                    }
329:
330:                    if (type != null) {
331:                        String fullName = PatternHelper
332:                                .getFullyQualifiedName(type);
333:
334:                        if (m_plugin.isBootClass(fullName)) {
335:                            addMarker("bootJarTypeMarker", "BootJar Type",
336:                                    typeNode);
337:                        } else if (m_configHelper.isAdaptable(fullName)) {
338:                            addMarker("adaptedTypeReferenceMarker",
339:                                    "DSO Instrumented Type Reference", typeNode);
340:                        } else if (m_configHelper.isExcluded(fullName)) {
341:                            addMarker("excludedTypeMarker",
342:                                    "DSO Excluded Type", typeNode);
343:                        }
344:                    }
345:                }
346:
347:                return true;
348:            }
349:
350:            public boolean visit(MethodDeclaration node) {
351:                IMethodBinding methodBinding = node.resolveBinding();
352:                if (methodBinding != null) {
353:                    IMethod method = (IMethod) methodBinding.getJavaElement();
354:                    MethodInfo methodInfo = PatternHelper.getHelper()
355:                            .getMethodInfo(method);
356:                    if (methodInfo instanceof  JavaModelMethodInfo) {
357:                        JavaModelMethodInfo jmmi = (JavaModelMethodInfo) methodInfo;
358:                        jmmi.clearAnnotations();
359:                        for (Object o : node.modifiers()) {
360:                            if (o instanceof  Annotation) {
361:                                jmmi.addAnnotation((Annotation) o);
362:                            }
363:                        }
364:                    }
365:                }
366:
367:                if (isDeclaringTypeAdaptable(node)) {
368:                    if (m_configHelper.isAutolocked(node)
369:                            && hasSynchronization(node)) {
370:                        addMarker("autolockedMarker", "DSO Auto-locked Method",
371:                                node.getName());
372:                    } else if (m_configHelper.isNameLocked(node)) {
373:                        addMarker("nameLockedMarker", "DSO Name-locked Method",
374:                                node.getName());
375:                    }
376:                }
377:
378:                if (m_configHelper.isDistributedMethod(node)) {
379:                    addMarker("distributedMethodMarker",
380:                            "DSO Distributed Method", node.getName());
381:
382:                    if (!isDeclaringTypeAdaptable(node)) {
383:                        addProblemMarker("DeclaringTypeNotInstrumentedMarker",
384:                                "Declaring type not instrumented", node
385:                                        .getName());
386:                    }
387:                }
388:
389:                return true;
390:            }
391:
392:            public boolean visit(MethodInvocation node) {
393:                IMethodBinding binding = node.resolveMethodBinding();
394:
395:                if (binding != null && binding.isConstructor()) {
396:                    ITypeBinding declaringType = binding.getDeclaringClass();
397:                    String fullName = declaringType.getQualifiedName();
398:
399:                    if (m_plugin.isBootClass(fullName)) {
400:                        addMarker("bootJarTypeMarker", "BootJar Type", node
401:                                .getName());
402:                    } else if (m_configHelper.isAdaptable(fullName)) {
403:                        addMarker("adaptedTypeReferenceMarker",
404:                                "DSO Instrumented Type Reference", node
405:                                        .getName());
406:                    }
407:                }
408:
409:                return true;
410:            }
411:
412:            public boolean visit(ClassInstanceCreation node) {
413:                Type type = node.getType();
414:                ITypeBinding binding = type.resolveBinding();
415:
416:                if (binding != null) {
417:                    String fullName = binding.getQualifiedName();
418:
419:                    if (m_plugin.isBootClass(fullName)) {
420:                        addMarker("bootJarTypeMarker", "BootJar Type", type);
421:                    } else if (m_configHelper.isAdaptable(fullName)) {
422:                        addMarker("adaptedTypeReferenceMarker",
423:                                "DSO Instrumented Type Reference", type);
424:                    }
425:                }
426:
427:                return true;
428:            }
429:
430:            public boolean visit(Block node) {
431:                return true;
432:            }
433:
434:            public boolean visit(SynchronizedStatement node) {
435:                return true;
436:            }
437:
438:            public boolean visit(WhileStatement node) {
439:                return true;
440:            }
441:
442:            public boolean visit(TryStatement node) {
443:                return true;
444:            }
445:
446:            public boolean visit(ForStatement node) {
447:                return true;
448:            }
449:
450:            public boolean visit(IfStatement node) {
451:                return true;
452:            }
453:
454:            public boolean visit(SwitchStatement node) {
455:                return true;
456:            }
457:
458:            public boolean visit(LabeledStatement node) {
459:                return true;
460:            }
461:
462:            public boolean visit(InstanceofExpression node) {
463:                return true;
464:            }
465:
466:            public boolean visit(Initializer node) {
467:                return true;
468:            }
469:
470:            public boolean visit(SingleVariableDeclaration node) {
471:                IVariableBinding binding = node.resolveBinding();
472:
473:                if (binding != null) {
474:                    //      if(binding.isField()) {
475:                    //        String parentClass = getQualifiedName(binding.getDeclaringClass());
476:                    //        String fieldName   = parentClass+"."+binding.getName();
477:                    //  
478:                    //        if(m_configHelper.isRoot(fieldName)) {
479:                    //          addMarker("rootMarker", "DSO Root Field", node.getName());
480:                    //        } else if(m_configHelper.isTransient(fieldName)) {
481:                    //          addMarker("transientFieldMarker", "DSO Transient Field", node.getName());
482:                    //          
483:                    //          if(!m_configHelper.isAdaptable(parentClass) && !m_configHelper.declaresRoot(parentClass)) {
484:                    //            addProblemMarker("DeclaringTypeNotInstrumentedMarker", "Declaring type not instrumented", node.getName());
485:                    //          }
486:                    //        }
487:                    //      }
488:
489:                    if (m_plugin.isBootClass(binding.getType()
490:                            .getQualifiedName())) {
491:                        addMarker("bootJarTypeMarker", "BootJar Type", node
492:                                .getType());
493:                    }
494:                }
495:
496:                return true;
497:            }
498:
499:            private static String getQualifiedName(ITypeBinding binding) {
500:                String qname = binding.getQualifiedName();
501:
502:                if (binding.isMember()) {
503:                    int lastDot = qname.lastIndexOf('.');
504:                    qname = qname.substring(0, lastDot) + '$'
505:                            + qname.substring(lastDot + 1);
506:                }
507:
508:                return qname;
509:            }
510:
511:            public boolean visit(VariableDeclarationFragment node) {
512:                IVariableBinding binding = node.resolveBinding();
513:
514:                if (binding != null) {
515:                    if (binding.isField()) {
516:                        String parentClass = getQualifiedName(binding
517:                                .getDeclaringClass());
518:                        String fieldName = parentClass + "."
519:                                + binding.getName();
520:                        IField field = (IField) binding.getJavaElement();
521:
522:                        if (m_configHelper.isRoot(field)) {
523:                            addMarker("rootMarker", "DSO Root Field", node
524:                                    .getName());
525:                        } else if (m_configHelper.isTransient(fieldName)) {
526:                            addMarker("transientFieldMarker",
527:                                    "DSO Transient Field", node.getName());
528:
529:                            if (!m_configHelper.isAdaptable(parentClass)
530:                                    && !m_configHelper
531:                                            .declaresRoot(parentClass)) {
532:                                addProblemMarker(
533:                                        "DeclaringTypeNotInstrumentedMarker",
534:                                        "Declaring type not instrumented", node);
535:                            }
536:                        }
537:                    }
538:
539:                    String typeName = binding.getType().getQualifiedName();
540:
541:                    if (m_plugin.isBootClass(typeName)) {
542:                        addMarker("bootJarTypeMarker", "BootJar Type",
543:                                getType(node));
544:                    } else if (m_configHelper.isAdaptable(typeName)) {
545:                        addMarker("adaptedTypeReferenceMarker",
546:                                "DSO Instrumented Type Reference",
547:                                getType(node));
548:                    }
549:                }
550:
551:                return true;
552:            }
553:
554:            private Type getType(VariableDeclarationFragment node) {
555:                ASTNode parentNode = node.getParent();
556:
557:                if (parentNode instanceof  FieldDeclaration) {
558:                    return ((FieldDeclaration) node.getParent()).getType();
559:                } else if (parentNode instanceof  VariableDeclarationStatement) {
560:                    return ((VariableDeclarationStatement) node.getParent())
561:                            .getType();
562:                } else if (parentNode instanceof  VariableDeclarationExpression) {
563:                    return ((VariableDeclarationExpression) node.getParent())
564:                            .getType();
565:                }
566:
567:                return null;
568:            }
569:
570:            private static boolean hasSynchronization(MethodDeclaration node) {
571:                if (Modifier.isSynchronized(node.getModifiers())) {
572:                    return true;
573:                }
574:
575:                Block body = node.getBody();
576:                if (body != null) {
577:                    return hasSynchronization(body);
578:                }
579:
580:                return false;
581:            }
582:
583:            private static boolean hasSynchronization(Block block) {
584:                List statements = block.statements();
585:
586:                if (statements != null) {
587:                    Iterator iter = statements.iterator();
588:
589:                    while (iter.hasNext()) {
590:                        if (hasSynchronization((Statement) iter.next())) {
591:                            return true;
592:                        }
593:                    }
594:                }
595:
596:                return false;
597:            }
598:
599:            private static boolean hasSynchronization(Statement statement) {
600:                if (statement instanceof  SynchronizedStatement) {
601:                    return true;
602:                } else if (statement instanceof  Block) {
603:                    return hasSynchronization((Block) statement);
604:                } else if (statement instanceof  ForStatement) {
605:                    return hasSynchronization(((ForStatement) statement)
606:                            .getBody());
607:                } else if (statement instanceof  EnhancedForStatement) {
608:                    return hasSynchronization(((EnhancedForStatement) statement)
609:                            .getBody());
610:                } else if (statement instanceof  IfStatement) {
611:                    return hasSynchronization((IfStatement) statement);
612:                } else if (statement instanceof  WhileStatement) {
613:                    return hasSynchronization((WhileStatement) statement);
614:                } else if (statement instanceof  DoStatement) {
615:                    return hasSynchronization((DoStatement) statement);
616:                } else if (statement instanceof  TryStatement) {
617:                    return hasSynchronization((TryStatement) statement);
618:                } else if (statement instanceof  SwitchStatement) {
619:                    return hasSynchronization((SwitchStatement) statement);
620:                }
621:
622:                return false;
623:            }
624:
625:            private static boolean hasSynchronization(IfStatement statement) {
626:                Statement thenStatement = statement.getThenStatement();
627:                Statement elseStatement = statement.getElseStatement();
628:
629:                return hasSynchronization(thenStatement)
630:                        || ((elseStatement != null) && hasSynchronization(elseStatement));
631:            }
632:
633:            private static boolean hasSynchronization(WhileStatement statement) {
634:                return hasSynchronization(statement.getBody());
635:            }
636:
637:            private static boolean hasSynchronization(DoStatement statement) {
638:                return hasSynchronization(statement.getBody());
639:            }
640:
641:            // TODO: handle catchClauses and finallyBlock
642:            private static boolean hasSynchronization(TryStatement statement) {
643:                return hasSynchronization(statement.getBody());
644:            }
645:
646:            private static boolean hasSynchronization(SwitchStatement statement) {
647:                List statements = statement.statements();
648:
649:                if (statements != null) {
650:                    Iterator iter = statements.iterator();
651:
652:                    while (iter.hasNext()) {
653:                        if (hasSynchronization((Statement) iter.next())) {
654:                            return true;
655:                        }
656:                    }
657:                }
658:
659:                return false;
660:            }
661:
662:            public boolean isDeclaringTypeAdaptable(MethodDeclaration node) {
663:                IMethodBinding binding = node.resolveBinding();
664:
665:                if (binding != null) {
666:                    IMethod method = (IMethod) binding.getJavaElement();
667:
668:                    if (method != null) {
669:                        IType type = method.getDeclaringType();
670:                        return m_configHelper.isAdaptable(type)
671:                                || m_configHelper.declaresRoot(type);
672:                    }
673:                }
674:
675:                return false;
676:            }
677:
678:            private void addMarker(String markerID, String msg, ASTNode node) {
679:                if (node == null)
680:                    return;
681:
682:                HashMap map = new HashMap();
683:                int startPos = node.getStartPosition();
684:                int endPos = startPos + node.getLength();
685:                int line = m_ast.lineNumber(startPos);
686:
687:                MarkerUtilities.setMessage(map, msg);
688:                MarkerUtilities.setCharStart(map, startPos);
689:                MarkerUtilities.setCharEnd(map, endPos);
690:                MarkerUtilities.setLineNumber(map, line);
691:
692:                createMarker(m_res, map, markerID);
693:            }
694:
695:            private void addProblemMarker(String markerID, String msg,
696:                    ASTNode node) {
697:                HashMap<String, Integer> map = new HashMap<String, Integer>();
698:                int startPos = node.getStartPosition();
699:                int endPos = startPos + node.getLength();
700:                int line = m_ast.lineNumber(startPos);
701:
702:                MarkerUtilities.setMessage(map, msg);
703:                MarkerUtilities.setCharStart(map, startPos);
704:                MarkerUtilities.setCharEnd(map, endPos);
705:                MarkerUtilities.setLineNumber(map, line);
706:                map.put(IMarker.SEVERITY, Integer
707:                        .valueOf(IMarker.SEVERITY_WARNING));
708:
709:                createMarker(m_res, map, markerID);
710:            }
711:
712:            private void createMarker(IResource resource, Map attributes,
713:                    String markerType) {
714:                try {
715:                    MarkerUtilities.createMarker(m_res, attributes,
716:                            "org.terracotta.dso." + markerType);
717:                } catch (CoreException ce) {
718:                    ce.printStackTrace();
719:                }
720:            }
721:
722:            protected void clearTerracottaMarkers() {
723:                try {
724:                    m_res.deleteMarkers("org.terracotta.dso.baseMarker", true,
725:                            IResource.DEPTH_ZERO);
726:                } catch (Exception e) {/**/
727:                }
728:
729:                try {
730:                    m_res.deleteMarkers(
731:                            "org.terracotta.dso.ConfigProblemMarker", true,
732:                            IResource.DEPTH_ZERO);
733:                } catch (Exception e) {/**/
734:                }
735:            }
736:
737:            public boolean visit(AnnotationTypeDeclaration node) {
738:                return false;
739:            }
740:
741:            public boolean visit(AnnotationTypeMemberDeclaration node) {
742:                return false;
743:            }
744:
745:            public boolean visit(AnonymousClassDeclaration node) {
746:                return false;
747:            }
748:
749:            public boolean visit(ArrayAccess node) {
750:                return false;
751:            }
752:
753:            public boolean visit(ArrayCreation node) {
754:                return false;
755:            }
756:
757:            public boolean visit(ArrayInitializer node) {
758:                return false;
759:            }
760:
761:            public boolean visit(ArrayType node) {
762:                return false;
763:            }
764:
765:            public boolean visit(AssertStatement node) {
766:                return false;
767:            }
768:
769:            public boolean visit(Assignment node) {
770:                return true;
771:            }
772:
773:            public boolean visit(BlockComment node) {
774:                return false;
775:            }
776:
777:            public boolean visit(BooleanLiteral node) {
778:                return false;
779:            }
780:
781:            public boolean visit(BreakStatement node) {
782:                return false;
783:            }
784:
785:            public boolean visit(CastExpression node) {
786:                return true;
787:            }
788:
789:            public boolean visit(CatchClause node) {
790:                return false;
791:            }
792:
793:            public boolean visit(CharacterLiteral node) {
794:                return false;
795:            }
796:
797:            public boolean visit(ConditionalExpression node) {
798:                return false;
799:            }
800:
801:            public boolean visit(ConstructorInvocation node) {
802:                return true;
803:            }
804:
805:            public boolean visit(ContinueStatement node) {
806:                return false;
807:            }
808:
809:            public boolean visit(DoStatement node) {
810:                return true;
811:            }
812:
813:            public boolean visit(EmptyStatement node) {
814:                return false;
815:            }
816:
817:            public boolean visit(EnhancedForStatement node) {
818:                return true;
819:            }
820:
821:            public boolean visit(EnumConstantDeclaration node) {
822:                return false;
823:            }
824:
825:            public boolean visit(EnumDeclaration node) {
826:                return false;
827:            }
828:
829:            public boolean visit(ExpressionStatement node) {
830:                return true;
831:            }
832:
833:            public boolean visit(FieldAccess node) {
834:                return false;
835:            }
836:
837:            public boolean visit(ImportDeclaration node) {
838:                return false;
839:            }
840:
841:            public boolean visit(InfixExpression node) {
842:                return false;
843:            }
844:
845:            public boolean visit(Javadoc node) {
846:                return false;
847:            }
848:
849:            public boolean visit(LineComment node) {
850:                return false;
851:            }
852:
853:            public boolean visit(MarkerAnnotation node) {
854:                return false;
855:            }
856:
857:            public boolean visit(MemberRef node) {
858:                return false;
859:            }
860:
861:            public boolean visit(MemberValuePair node) {
862:                return false;
863:            }
864:
865:            public boolean visit(MethodRef node) {
866:                return false;
867:            }
868:
869:            public boolean visit(MethodRefParameter node) {
870:                return false;
871:            }
872:
873:            public boolean visit(Modifier node) {
874:                return false;
875:            }
876:
877:            public boolean visit(NormalAnnotation node) {
878:                return false;
879:            }
880:
881:            public boolean visit(NullLiteral node) {
882:                return false;
883:            }
884:
885:            public boolean visit(NumberLiteral node) {
886:                return false;
887:            }
888:
889:            public boolean visit(PackageDeclaration node) {
890:                return false;
891:            }
892:
893:            public boolean visit(ParameterizedType node) {
894:                return false;
895:            }
896:
897:            public boolean visit(ParenthesizedExpression node) {
898:                return false;
899:            }
900:
901:            public boolean visit(PostfixExpression node) {
902:                return false;
903:            }
904:
905:            public boolean visit(PrefixExpression node) {
906:                return false;
907:            }
908:
909:            public boolean visit(PrimitiveType node) {
910:                return false;
911:            }
912:
913:            public boolean visit(QualifiedName node) {
914:                return false;
915:            }
916:
917:            public boolean visit(QualifiedType node) {
918:                return false;
919:            }
920:
921:            public boolean visit(ReturnStatement node) {
922:                return false;
923:            }
924:
925:            public boolean visit(SimpleName node) {
926:                return false;
927:            }
928:
929:            public boolean visit(SimpleType node) {
930:                return false;
931:            }
932:
933:            public boolean visit(SingleMemberAnnotation node) {
934:                return false;
935:            }
936:
937:            public boolean visit(StringLiteral node) {
938:                return false;
939:            }
940:
941:            public boolean visit(SuperConstructorInvocation node) {
942:                return false;
943:            }
944:
945:            public boolean visit(SuperFieldAccess node) {
946:                return false;
947:            }
948:
949:            public boolean visit(SuperMethodInvocation node) {
950:                return false;
951:            }
952:
953:            public boolean visit(SwitchCase node) {
954:                return false;
955:            }
956:
957:            public boolean visit(TagElement node) {
958:                return false;
959:            }
960:
961:            public boolean visit(TextElement node) {
962:                return false;
963:            }
964:
965:            public boolean visit(ThisExpression node) {
966:                return false;
967:            }
968:
969:            public boolean visit(ThrowStatement node) {
970:                return false;
971:            }
972:
973:            public boolean visit(TypeLiteral node) {
974:                return false;
975:            }
976:
977:            public boolean visit(WildcardType node) {
978:                return false;
979:            }
980:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.