001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * FieldElem.java
044: *
045: * Created on June 26, 2000, 9:29 AM
046: */
047:
048: package org.netbeans.test.java.generating.SuperClassInterfaces;
049:
050: import com.sun.source.tree.ClassTree;
051: import com.sun.source.tree.Tree;
052: import org.netbeans.test.java.Common;
053: import java.lang.reflect.Modifier;
054: import java.util.ArrayList;
055: import java.util.Collections;
056: import java.util.List;
057: import org.netbeans.api.java.source.CancellableTask;
058: import org.netbeans.api.java.source.JavaSource;
059: import org.netbeans.api.java.source.JavaSource.Phase;
060: import org.netbeans.api.java.source.WorkingCopy;
061: import org.openide.loaders.*;
062: import org.netbeans.junit.*;
063: import org.openide.filesystems.FileObject;
064:
065: /** <B>Java Module General API test: InnerInterface</B>
066: * <BR><BR><I>What it tests:</I><BR>
067: * Creating and handling with ClassElement.
068: * Test is focused on checking of correctness of generated code.
069: * <BR><BR><I>How it works</I><BR>
070: * New class is created using DataObject.createFromTemplate() and also some ClassElements are created.
071: * These are customized using setters, set to be the Interfaces and filled with fields, methods etc.
072: * Then these ClassElements are added using ClassElement.addClass() into ClassElement.
073: * These actions cause generating of .java code. This code is compared with supposed one.
074: * <BR><BR><I>Output</I><BR>
075: * Generated Java code.
076: * <BR><BR><I>Possible reasons of failure</I><BR>
077: * <U>Interfaces are not inserted properly:</U><BR>
078: * If there are some Interfaces in .diff file.
079: * <BR><BR><U>Classes have/return bad properies</U><BR>
080: * See .diff file to get which ones
081: * <BR><BR><U>Bad indentation</U><BR>
082: * This is probably not a bug of Java Module. (->Editor Bug)
083: * In .diff file could be some whitespaces.
084: * <BR><BR><U>Exception occured</U><BR><BR>
085: * See .log file for StackTrace
086: *
087: * @author Jan Becicka <Jan.Becicka@sun.com>
088: */
089:
090: public class SuperClassInterfaces extends
091: org.netbeans.test.java.XRunner {
092:
093: public static void main(java.lang.String[] args) {
094: junit.textui.TestRunner.run(suite());
095: }
096:
097: public SuperClassInterfaces() {
098: super ("");
099: }
100:
101: public SuperClassInterfaces(java.lang.String testName) {
102: super (testName);
103: }
104:
105: public static NbTest suite() {
106: return new NbTestSuite(SuperClassInterfaces.class);
107: }
108:
109: /** "body" of this TestCase
110: * @param o SourceElement - target for generating
111: * @param log log is used for logging StackTraces
112: * @throws Exception
113: * @return true if test passed
114: * false if failed
115: */
116:
117: public boolean go(Object o, java.io.PrintWriter log)
118: throws Exception {
119: FileObject fo = (FileObject) o;
120: JavaSource js = JavaSource.forFileObject(fo);
121: List<String> list = new ArrayList<String>();
122: list.add("java.util.List");
123: list.add("java.io.Closeable");
124: Common.addExtendImplementClause(js, "java.io.File", list);
125: return true;
126: }
127:
128: /**
129: */
130: protected void setUp() {
131: super .setUp();
132: name = "JavaTestSourceSuperClassInterfaces";
133: packageName = "org.netbeans.test.java.testsources";
134: }
135:
136: }
|