001 /*BEGIN_COPYRIGHT_BLOCK
002 *
003 * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
004 * All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or without
007 * modification, are permitted provided that the following conditions are met:
008 * * Redistributions of source code must retain the above copyright
009 * notice, this list of conditions and the following disclaimer.
010 * * Redistributions in binary form must reproduce the above copyright
011 * notice, this list of conditions and the following disclaimer in the
012 * documentation and/or other materials provided with the distribution.
013 * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014 * names of its contributors may be used to endorse or promote products
015 * derived from this software without specific prior written permission.
016 *
017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028 *
029 * This software is Open Source Initiative approved Open Source Software.
030 * Open Source Initative Approved is a trademark of the Open Source Initiative.
031 *
032 * This file is part of DrJava. Download the current version of this project
033 * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034 *
035 * END_COPYRIGHT_BLOCK*/
036
037 package edu.rice.cs.javalanglevels;
038
039 import edu.rice.cs.javalanglevels.tree.*;
040 import java.util.*;
041
042 import junit.framework.TestCase;
043
044 /** Abstract class corresponding to a method or block. BodyData ::= MethodData | BlockData */
045 public abstract class BodyData extends Data {
046
047 public BodyData(Data outerData) { super(outerData); }
048
049 /** Return the enclosing SymbolData, corresponding to the enclosing class.
050 * Note-this may be several layers up the tree.
051 */
052 public SymbolData getSymbolData() { return _outerData.getSymbolData(); }
053
054 /** Will return this, if it is a method data, or the enclosing method data if this is a block data. */
055 public abstract MethodData getMethodData();
056
057 /** True if this is a method data. */
058 public abstract boolean isMethodData();
059
060 /** Test class for BodyData. Verifies that methods work as expected. */
061 public static class BodyDataTest extends TestCase {
062
063 private BodyData _bd1;
064 private BodyData _bd2;
065
066 private SymbolData _sd1;
067 private SymbolData _sd2;
068
069 public BodyDataTest() { this(""); }
070 public BodyDataTest(String name) { super(name); }
071
072 public void testGetThis() {
073 //getThis should be able to go up the tree correctly.
074 _sd1 = new SymbolData("i.like.monkey");
075 _sd2 = new SymbolData("i.like.giraffe");
076 _bd1 = new BlockData(_sd2);
077 _bd2 = new BlockData(_bd1);
078 _sd2.setSuperClass(_sd1);
079 assertEquals("Should return _sd2", _sd2, _bd2.getSymbolData());
080 }
081 }
082 }