ada.editor/src/org/netbeans/modules/ada/editor/ast/nodes/visitors/DefaultTreePathVisitor.java
author Andrea Lucarelli <raster@netbeans.org>
Sun, 22 Aug 2010 23:37:11 +0200
branchrelease68
changeset 16367 d2820c029d3a
parent 15779 367c7fdb5d23
permissions -rw-r--r--
Add JVM compiler support.
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
     5  *
     6  * The contents of this file are subject to the terms of either the GNU
     7  * General Public License Version 2 only ("GPL") or the Common
     8  * Development and Distribution License("CDDL") (collectively, the
     9  * "License"). You may not use this file except in compliance with the
    10  * License. You can obtain a copy of the License at
    11  * http://www.netbeans.org/cddl-gplv2.html
    12  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    13  * specific language governing permissions and limitations under the
    14  * License.  When distributing the software, include this License Header
    15  * Notice in each file and include the License file at
    16  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    17  * particular file as subject to the "Classpath" exception as provided
    18  * by Sun in the GPL Version 2 section of the License file that
    19  * accompanied this code. If applicable, add the following below the
    20  * License Header, with the fields enclosed by brackets [] replaced by
    21  * your own identifying information:
    22  * "Portions Copyrighted [year] [name of copyright owner]"
    23  *
    24  * If you wish your version of this file to be governed by only the CDDL
    25  * or only the GPL Version 2, indicate your decision by adding
    26  * "[Contributor] elects to include this software in this distribution
    27  * under the [CDDL or GPL Version 2] license." If you do not indicate a
    28  * single choice of license, a recipient has the option to distribute
    29  * your version of this file under either the CDDL, the GPL Version 2 or
    30  * to extend the choice of license to its licensees as provided above.
    31  * However, if you add GPL Version 2 code and therefore, elected the GPL
    32  * Version 2 license, then the option applies only if the new code is
    33  * made subject to such option by the copyright holder.
    34  *
    35  * Contributor(s):
    36  *
    37  * Portions Copyrighted 2008 Sun Microsystems, Inc.
    38  */
    39 package org.netbeans.modules.ada.editor.ast.nodes.visitors;
    40 
    41 import java.util.Collections;
    42 import java.util.LinkedList;
    43 import java.util.List;
    44 import org.netbeans.modules.ada.editor.ast.ASTError;
    45 import org.netbeans.modules.ada.editor.ast.ASTNode;
    46 import org.netbeans.modules.ada.editor.ast.nodes.AbortStatement;
    47 import org.netbeans.modules.ada.editor.ast.nodes.ArrayAccess;
    48 import org.netbeans.modules.ada.editor.ast.nodes.Assignment;
    49 import org.netbeans.modules.ada.editor.ast.nodes.Block;
    50 import org.netbeans.modules.ada.editor.ast.nodes.BlockStatement;
    51 import org.netbeans.modules.ada.editor.ast.nodes.CaseStatement;
    52 import org.netbeans.modules.ada.editor.ast.nodes.CaseWhen;
    53 import org.netbeans.modules.ada.editor.ast.nodes.CodeStatement;
    54 import org.netbeans.modules.ada.editor.ast.nodes.Comment;
    55 import org.netbeans.modules.ada.editor.ast.nodes.DelayStatement;
    56 import org.netbeans.modules.ada.editor.ast.nodes.ExitStatement;
    57 import org.netbeans.modules.ada.editor.ast.nodes.FieldsDeclaration;
    58 import org.netbeans.modules.ada.editor.ast.nodes.FormalParameter;
    59 import org.netbeans.modules.ada.editor.ast.nodes.GotoStatement;
    60 import org.netbeans.modules.ada.editor.ast.nodes.Identifier;
    61 import org.netbeans.modules.ada.editor.ast.nodes.IfStatement;
    62 import org.netbeans.modules.ada.editor.ast.nodes.InfixExpression;
    63 import org.netbeans.modules.ada.editor.ast.nodes.LoopStatement;
    64 import org.netbeans.modules.ada.editor.ast.nodes.MethodDeclaration;
    65 import org.netbeans.modules.ada.editor.ast.nodes.NullStatement;
    66 import org.netbeans.modules.ada.editor.ast.nodes.PackageBody;
    67 import org.netbeans.modules.ada.editor.ast.nodes.PackageInstanceCreation;
    68 import org.netbeans.modules.ada.editor.ast.nodes.PackageSpecification;
    69 import org.netbeans.modules.ada.editor.ast.nodes.PackageName;
    70 import org.netbeans.modules.ada.editor.ast.nodes.PackageRenames;
    71 import org.netbeans.modules.ada.editor.ast.nodes.Program;
    72 import org.netbeans.modules.ada.editor.ast.nodes.QualifiedExpression;
    73 import org.netbeans.modules.ada.editor.ast.nodes.RaiseStatement;
    74 import org.netbeans.modules.ada.editor.ast.nodes.Range;
    75 import org.netbeans.modules.ada.editor.ast.nodes.Reference;
    76 import org.netbeans.modules.ada.editor.ast.nodes.ReturnStatement;
    77 import org.netbeans.modules.ada.editor.ast.nodes.Scalar;
    78 import org.netbeans.modules.ada.editor.ast.nodes.SingleFieldDeclaration;
    79 import org.netbeans.modules.ada.editor.ast.nodes.SubprogramBody;
    80 import org.netbeans.modules.ada.editor.ast.nodes.SubprogramSpecification;
    81 import org.netbeans.modules.ada.editor.ast.nodes.SubtypeDeclaration;
    82 import org.netbeans.modules.ada.editor.ast.nodes.TaskName;
    83 import org.netbeans.modules.ada.editor.ast.nodes.TypeDeclaration;
    84 import org.netbeans.modules.ada.editor.ast.nodes.TypeName;
    85 import org.netbeans.modules.ada.editor.ast.nodes.UnaryOperation;
    86 import org.netbeans.modules.ada.editor.ast.nodes.Use;
    87 import org.netbeans.modules.ada.editor.ast.nodes.Variable;
    88 import org.netbeans.modules.ada.editor.ast.nodes.With;
    89 
    90 /**
    91  * Based on org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultTreePathVisitor
    92  * 
    93  * @author Andrea Lucarelli
    94  */
    95 public class DefaultTreePathVisitor extends DefaultVisitor {
    96 
    97     private LinkedList<ASTNode> path = new LinkedList<ASTNode>();
    98     private List<ASTNode> unmodifiablePath;
    99 
   100     public DefaultTreePathVisitor() {
   101         unmodifiablePath = Collections.unmodifiableList(path);
   102     }
   103 
   104     /**
   105      * ... reversed order ....
   106      * 
   107      * 
   108      * @return
   109      */
   110     public List<ASTNode> getPath() {
   111         return unmodifiablePath;
   112     }
   113 
   114     @Override
   115     public void visit(ASTError astError) {
   116         super.visit(astError);
   117     }
   118 
   119     @Override
   120     public void visit(ASTNode node) {
   121         path.addFirst(node);
   122         super.visit(node);
   123         path.removeFirst();
   124     }
   125 
   126     @Override
   127     public void visit(AbortStatement node) {
   128         path.addFirst(node);
   129         super.visit(node);
   130         path.removeFirst();
   131     }
   132 
   133     @Override
   134     public void visit(ArrayAccess node) {
   135         path.addFirst(node);
   136         super.visit(node);
   137         path.removeFirst();
   138     }
   139 
   140     @Override
   141     public void visit(Assignment node) {
   142         path.addFirst(node);
   143         super.visit(node);
   144         path.removeFirst();
   145     }
   146 
   147     @Override
   148     public void visit(Block node) {
   149         path.addFirst(node);
   150         super.visit(node);
   151         path.removeFirst();
   152     }
   153 
   154     @Override
   155     public void visit(BlockStatement node) {
   156         path.addFirst(node);
   157         super.visit(node);
   158         path.removeFirst();
   159     }
   160 
   161     @Override
   162     public void visit(CaseStatement node) {
   163         path.addFirst(node);
   164         super.visit(node);
   165         path.removeFirst();
   166     }
   167 
   168     @Override
   169     public void visit(CaseWhen node) {
   170         path.addFirst(node);
   171         super.visit(node);
   172         path.removeFirst();
   173     }
   174 
   175     @Override
   176     public void visit(CodeStatement node) {
   177         path.addFirst(node);
   178         super.visit(node);
   179         path.removeFirst();
   180     }
   181 
   182     @Override
   183     public void visit(Comment node) {
   184         path.addFirst(node);
   185         super.visit(node);
   186         path.removeFirst();
   187     }
   188 
   189     @Override
   190     public void visit(DelayStatement node) {
   191         path.addFirst(node);
   192         super.visit(node);
   193         path.removeFirst();
   194     }
   195 
   196     @Override
   197     public void visit(ExitStatement node) {
   198         path.addFirst(node);
   199         super.visit(node);
   200         path.removeFirst();
   201     }
   202 
   203     @Override
   204     public void visit(FieldsDeclaration node) {
   205         path.addFirst(node);
   206         super.visit(node);
   207         path.removeFirst();
   208     }
   209 
   210     @Override
   211     public void visit(FormalParameter node) {
   212         path.addFirst(node);
   213         super.visit(node);
   214         path.removeFirst();
   215     }
   216 
   217     @Override
   218     public void visit(GotoStatement node) {
   219         path.addFirst(node);
   220         super.visit(node);
   221         path.removeFirst();
   222     }
   223 
   224     @Override
   225     public void visit(Identifier node) {
   226         path.addFirst(node);
   227         super.visit(node);
   228         path.removeFirst();
   229     }
   230 
   231     @Override
   232     public void visit(IfStatement node) {
   233         path.addFirst(node);
   234         super.visit(node);
   235         path.removeFirst();
   236     }
   237 
   238     @Override
   239     public void visit(InfixExpression node) {
   240         path.addFirst(node);
   241         super.visit(node);
   242         path.removeFirst();
   243     }
   244 
   245     @Override
   246     public void visit(LoopStatement node) {
   247         path.addFirst(node);
   248         super.visit(node);
   249         path.removeFirst();
   250     }
   251 
   252     @Override
   253     public void visit(MethodDeclaration node) {
   254         path.addFirst(node);
   255         super.visit(node);
   256         path.removeFirst();
   257     }
   258 
   259     @Override
   260     public void visit(NullStatement node) {
   261         path.addFirst(node);
   262         super.visit(node);
   263         path.removeFirst();
   264     }
   265 
   266     @Override
   267     public void visit(PackageBody node) {
   268         path.addFirst(node);
   269         super.visit(node);
   270         path.removeFirst();
   271     }
   272 
   273     @Override
   274     public void visit(PackageInstanceCreation node) {
   275         path.addFirst(node);
   276         super.visit(node);
   277         path.removeFirst();
   278     }
   279 
   280     @Override
   281     public void visit(PackageName node) {
   282         path.addFirst(node);
   283         super.visit(node);
   284         path.removeFirst();
   285     }
   286 
   287     @Override
   288     public void visit(PackageRenames node) {
   289         path.addFirst(node);
   290         super.visit(node);
   291         path.removeFirst();
   292     }
   293 
   294     @Override
   295     public void visit(PackageSpecification node) {
   296         path.addFirst(node);
   297         super.visit(node);
   298         path.removeFirst();
   299     }
   300 
   301     @Override
   302     public void visit(Program node) {
   303         path.addFirst(node);
   304         super.visit(node);
   305         path.removeFirst();
   306     }
   307 
   308     @Override
   309     public void visit(QualifiedExpression node) {
   310         path.addFirst(node);
   311         super.visit(node);
   312         path.removeFirst();
   313     }
   314 
   315     @Override
   316     public void visit(Range node) {
   317         path.addFirst(node);
   318         super.visit(node);
   319         path.removeFirst();
   320     }
   321 
   322     @Override
   323     public void visit(RaiseStatement node) {
   324         path.addFirst(node);
   325         super.visit(node);
   326         path.removeFirst();
   327     }
   328 
   329     @Override
   330     public void visit(ReturnStatement node) {
   331         path.addFirst(node);
   332         super.visit(node);
   333         path.removeFirst();
   334     }
   335 
   336     @Override
   337     public void visit(Reference node) {
   338         path.addFirst(node);
   339         super.visit(node);
   340         path.removeFirst();
   341     }
   342 
   343     @Override
   344     public void visit(Scalar node) {
   345         path.addFirst(node);
   346         super.visit(node);
   347         path.removeFirst();
   348     }
   349 
   350     @Override
   351     public void visit(SingleFieldDeclaration node) {
   352         path.addFirst(node);
   353         super.visit(node);
   354         path.removeFirst();
   355     }
   356 
   357     @Override
   358     public void visit(SubprogramBody node) {
   359         path.addFirst(node);
   360         super.visit(node);
   361         path.removeFirst();
   362     }
   363 
   364     @Override
   365     public void visit(SubprogramSpecification node) {
   366         path.addFirst(node);
   367         super.visit(node);
   368         path.removeFirst();
   369     }
   370 
   371     @Override
   372     public void visit(SubtypeDeclaration node) {
   373         path.addFirst(node);
   374         super.visit(node);
   375         path.removeFirst();
   376     }
   377 
   378     @Override
   379     public void visit(TaskName node) {
   380         path.addFirst(node);
   381         super.visit(node);
   382         path.removeFirst();
   383     }
   384 
   385     @Override
   386     public void visit(TypeName node) {
   387         path.addFirst(node);
   388         super.visit(node);
   389         path.removeFirst();
   390     }
   391 
   392     @Override
   393     public void visit(TypeDeclaration node) {
   394         path.addFirst(node);
   395         super.visit(node);
   396         path.removeFirst();
   397     }
   398 
   399     @Override
   400     public void visit(Use node) {
   401         path.addFirst(node);
   402         super.visit(node);
   403         path.removeFirst();
   404     }
   405 
   406     @Override
   407     public void visit(Variable node) {
   408         path.addFirst(node);
   409         super.visit(node);
   410         path.removeFirst();
   411     }
   412 
   413     @Override
   414     public void visit(With node) {
   415         path.addFirst(node);
   416         super.visit(node);
   417         path.removeFirst();
   418     }
   419 
   420     @Override
   421     public void visit(UnaryOperation node) {
   422         path.addFirst(node);
   423         super.visit(node);
   424         path.removeFirst();
   425     }
   426 }