KickJava   Java API By Example, From Geeks To Geeks.

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


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
15 import org.eclipse.jdt.internal.compiler.ASTVisitor;
16 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
17 import org.eclipse.jdt.internal.compiler.ast.MessageSend;
18 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
19
20 class CascadingMethodInvocationFragmentBuilder
21     extends ASTVisitor {
22         
23     ArrayList JavaDoc fragmentsList;
24
25     CascadingMethodInvocationFragmentBuilder() {
26         this.fragmentsList = new ArrayList JavaDoc();
27     }
28
29     public MessageSend[] fragments() {
30         MessageSend[] fragments = new MessageSend[this.fragmentsList.size()];
31         this.fragmentsList.toArray(fragments);
32         return fragments;
33     }
34
35     public int size() {
36         return this.fragmentsList.size();
37     }
38     /* (non-Javadoc)
39      * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.MessageSend, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
40      */

41     public boolean visit(MessageSend messageSend, BlockScope scope) {
42         if ((messageSend.receiver.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT == 0) {
43             if (messageSend.receiver instanceof MessageSend) {
44                 this.fragmentsList.add(0, messageSend);
45                 messageSend.receiver.traverse(this, scope);
46                 return false;
47             }
48             this.fragmentsList.add(0, messageSend);
49             this.fragmentsList.add(1, messageSend);
50         } else {
51             this.fragmentsList.add(0, messageSend);
52             this.fragmentsList.add(1, messageSend);
53         }
54         return false;
55     }
56 }
57
Popular Tags