|
10 | 10 | *******************************************************************************/ |
11 | 11 | package net.sf.j2s.core.astvisitors; |
12 | 12 |
|
13 | | -import org.eclipse.jdt.core.dom.*; |
| 13 | +import java.util.HashMap; |
| 14 | +import java.util.Map; |
| 15 | +import org.eclipse.jdt.core.dom.ASTNode; |
| 16 | +import org.eclipse.jdt.core.dom.ASTVisitor; |
| 17 | +import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; |
| 18 | +import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; |
| 19 | +import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; |
| 20 | +import org.eclipse.jdt.core.dom.ArrayAccess; |
| 21 | +import org.eclipse.jdt.core.dom.ArrayCreation; |
| 22 | +import org.eclipse.jdt.core.dom.ArrayInitializer; |
| 23 | +import org.eclipse.jdt.core.dom.ArrayType; |
| 24 | +import org.eclipse.jdt.core.dom.AssertStatement; |
| 25 | +import org.eclipse.jdt.core.dom.Assignment; |
| 26 | +import org.eclipse.jdt.core.dom.BlockComment; |
| 27 | +import org.eclipse.jdt.core.dom.BooleanLiteral; |
| 28 | +import org.eclipse.jdt.core.dom.BreakStatement; |
| 29 | +import org.eclipse.jdt.core.dom.CastExpression; |
| 30 | +import org.eclipse.jdt.core.dom.CatchClause; |
| 31 | +import org.eclipse.jdt.core.dom.CharacterLiteral; |
| 32 | +import org.eclipse.jdt.core.dom.ClassInstanceCreation; |
| 33 | +import org.eclipse.jdt.core.dom.CompilationUnit; |
| 34 | +import org.eclipse.jdt.core.dom.ConditionalExpression; |
| 35 | +import org.eclipse.jdt.core.dom.ConstructorInvocation; |
| 36 | +import org.eclipse.jdt.core.dom.ContinueStatement; |
| 37 | +import org.eclipse.jdt.core.dom.DoStatement; |
| 38 | +import org.eclipse.jdt.core.dom.EmptyStatement; |
| 39 | +import org.eclipse.jdt.core.dom.EnhancedForStatement; |
| 40 | +import org.eclipse.jdt.core.dom.EnumConstantDeclaration; |
| 41 | +import org.eclipse.jdt.core.dom.ExpressionStatement; |
| 42 | +import org.eclipse.jdt.core.dom.FieldAccess; |
| 43 | +import org.eclipse.jdt.core.dom.FieldDeclaration; |
| 44 | +import org.eclipse.jdt.core.dom.ForStatement; |
| 45 | +import org.eclipse.jdt.core.dom.IfStatement; |
| 46 | +import org.eclipse.jdt.core.dom.ImportDeclaration; |
| 47 | +import org.eclipse.jdt.core.dom.InfixExpression; |
| 48 | +import org.eclipse.jdt.core.dom.Initializer; |
| 49 | +import org.eclipse.jdt.core.dom.InstanceofExpression; |
| 50 | +import org.eclipse.jdt.core.dom.Javadoc; |
| 51 | +import org.eclipse.jdt.core.dom.LabeledStatement; |
| 52 | +import org.eclipse.jdt.core.dom.LineComment; |
| 53 | +import org.eclipse.jdt.core.dom.MarkerAnnotation; |
| 54 | +import org.eclipse.jdt.core.dom.MemberRef; |
| 55 | +import org.eclipse.jdt.core.dom.MemberValuePair; |
| 56 | +import org.eclipse.jdt.core.dom.MethodInvocation; |
| 57 | +import org.eclipse.jdt.core.dom.MethodRef; |
| 58 | +import org.eclipse.jdt.core.dom.MethodRefParameter; |
| 59 | +import org.eclipse.jdt.core.dom.Modifier; |
| 60 | +import org.eclipse.jdt.core.dom.NormalAnnotation; |
| 61 | +import org.eclipse.jdt.core.dom.NullLiteral; |
| 62 | +import org.eclipse.jdt.core.dom.NumberLiteral; |
| 63 | +import org.eclipse.jdt.core.dom.PackageDeclaration; |
| 64 | +import org.eclipse.jdt.core.dom.ParameterizedType; |
| 65 | +import org.eclipse.jdt.core.dom.ParenthesizedExpression; |
| 66 | +import org.eclipse.jdt.core.dom.PrefixExpression; |
| 67 | +import org.eclipse.jdt.core.dom.PrimitiveType; |
| 68 | +import org.eclipse.jdt.core.dom.QualifiedName; |
| 69 | +import org.eclipse.jdt.core.dom.ReturnStatement; |
| 70 | +import org.eclipse.jdt.core.dom.SimpleName; |
| 71 | +import org.eclipse.jdt.core.dom.SimpleType; |
| 72 | +import org.eclipse.jdt.core.dom.SingleMemberAnnotation; |
| 73 | +import org.eclipse.jdt.core.dom.SingleVariableDeclaration; |
| 74 | +import org.eclipse.jdt.core.dom.StringLiteral; |
| 75 | +import org.eclipse.jdt.core.dom.SuperConstructorInvocation; |
| 76 | +import org.eclipse.jdt.core.dom.SuperFieldAccess; |
| 77 | +import org.eclipse.jdt.core.dom.SuperMethodInvocation; |
| 78 | +import org.eclipse.jdt.core.dom.SwitchCase; |
| 79 | +import org.eclipse.jdt.core.dom.SwitchStatement; |
| 80 | +import org.eclipse.jdt.core.dom.SynchronizedStatement; |
| 81 | +import org.eclipse.jdt.core.dom.TagElement; |
| 82 | +import org.eclipse.jdt.core.dom.TextElement; |
| 83 | +import org.eclipse.jdt.core.dom.ThisExpression; |
| 84 | +import org.eclipse.jdt.core.dom.ThrowStatement; |
| 85 | +import org.eclipse.jdt.core.dom.TryStatement; |
| 86 | +import org.eclipse.jdt.core.dom.TypeDeclaration; |
| 87 | +import org.eclipse.jdt.core.dom.TypeLiteral; |
| 88 | +import org.eclipse.jdt.core.dom.TypeParameter; |
| 89 | +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; |
| 90 | +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; |
| 91 | +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; |
| 92 | +import org.eclipse.jdt.core.dom.WhileStatement; |
| 93 | +import org.eclipse.jdt.core.dom.WildcardType; |
14 | 94 |
|
15 | 95 | /** |
16 | 96 | * This empty visitor just gives a way for debugging. That is to say, in |
@@ -44,7 +124,36 @@ public void setBuffer(StringBuffer buffer) { |
44 | 124 | this.buffer = buffer; |
45 | 125 | } |
46 | 126 |
|
47 | | - |
| 127 | + protected Map visitorMap = new HashMap(); |
| 128 | + |
| 129 | + public Object getAdaptable(Class clazz) { |
| 130 | + if (clazz == ASTEmptyVisitor.class) { |
| 131 | + return this; |
| 132 | + } |
| 133 | + Object visitor = visitorMap.get(clazz); |
| 134 | + if (visitor != null) { |
| 135 | + return visitor; |
| 136 | + } |
| 137 | + try { |
| 138 | + Object newInstance = clazz.newInstance(); |
| 139 | + if (newInstance instanceof IPluginVisitor) { |
| 140 | + registerPluginVisitor((IPluginVisitor) newInstance); |
| 141 | + return newInstance; |
| 142 | + } |
| 143 | + } catch (InstantiationException e) { |
| 144 | + e.printStackTrace(); |
| 145 | + } catch (IllegalAccessException e) { |
| 146 | + e.printStackTrace(); |
| 147 | + } |
| 148 | + return null; |
| 149 | + } |
| 150 | + |
| 151 | + public void registerPluginVisitor(IPluginVisitor visitor) { |
| 152 | + visitor.setBuffer(buffer); |
| 153 | + visitor.setVisitor(this); |
| 154 | + visitorMap.put(visitor.getClass(), visitor); |
| 155 | + } |
| 156 | + |
48 | 157 | /* |
49 | 158 | * The following are empty super.* methods which will be use to help |
50 | 159 | * developing Java2Script compiler. |
|
0 commit comments