KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > formatter > MethodInvocationFragmentBuilder


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.formatter;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jdt.core.dom.ASTNode;
17 import org.eclipse.jdt.core.dom.ASTVisitor;
18 import org.eclipse.jdt.core.dom.Expression;
19 import org.eclipse.jdt.core.dom.MethodInvocation;
20 import org.eclipse.jdt.core.dom.SuperMethodInvocation;
21
22 class MethodInvocationFragmentBuilder
23     extends ASTVisitor {
24         
25     ArrayList JavaDoc fragmentsList;
26
27     MethodInvocationFragmentBuilder() {
28         this.fragmentsList = new ArrayList JavaDoc();
29     }
30
31     public List JavaDoc fragments() {
32         return this.fragmentsList;
33     }
34
35     /* (non-Javadoc)
36      * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.MessageSend, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
37      */

38     public boolean visit(MethodInvocation methodInvocation) {
39         final Expression expression = methodInvocation.getExpression();
40         if (expression != null) {
41             switch(expression.getNodeType()) {
42                 case ASTNode.METHOD_INVOCATION :
43                 case ASTNode.SUPER_METHOD_INVOCATION :
44                     expression.accept(this);
45                     break;
46                 default:
47                     this.fragmentsList.add(expression);
48             }
49         }
50         this.fragmentsList.add(methodInvocation);
51         return false;
52     }
53     /* (non-Javadoc)
54      * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.MessageSend, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
55      */

56     public boolean visit(SuperMethodInvocation methodInvocation) {
57         this.fragmentsList.add(methodInvocation);
58         return false;
59     }
60 }
61
Popular Tags