/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6449781 6930508
* @summary Test that reported names of anonymous classes are non-null.
* @author Joseph D. Darcy
* @library ../../../lib
* @build JavacTestingAbstractProcessor TestAnonSourceNames
* @compile -processor TestAnonSourceNames TestAnonClassNames.java
* @run main TestAnonClassNames
*/
/*
* This test operates in phases to test retrieving the qualified name
* of anonymous classes from type elements modeling the anonymous
* class. The type elements are generated using both source files and
* class files as the basis of constructing the elements.
*
* Source files will be tested by the @compile line which runs
* TestAnonSourceNames as an annotation processor over this file.
*
* Class files are tested by the @run command on this type. This
* class gets the names of classes with different nesting kinds,
* including anonymous classes, and then invokes the compiler with an
* annotation processor having the class files names as inputs. The
* compiler is invoked via the javax.tools mechanism.
*/
public class TestAnonClassNames {
static class MemberClass1{}
class MemberClass2{}
class LocalClass{};
return "I have no name!";
}
};
MemberClass1.class,
MemberClass2.class,
LocalClass.class,
o.getClass(),
TestAnonClassNames.class,
};
}
// test all names together
if (errors > 0)
}
/**
* Perform annotation processing on the class file name and verify
* the existence of different flavors of class names when the
* input classes are modeled as elements.
*/
}
/**
* Perform annotation processing on a list of class file names and verify
* the existence of different flavors of class names when the
* input classes are modeled as elements.
*/
null, // File manager
null, // Diagnostics
null); // Sources
if (!goodResult) {
error("Errors found during compile.");
}
}
errors++;
}
}
@interface Nesting {
}
/**
* Probe at the various kinds of names of a type element.
*/
public ClassNameProber(){super();}
private boolean classesFound=false;
if (!roundEnv.processingOver()) {
classesFound = true;
// Verify different names are non-null; an NPE will
// result in failed compile status being reported.
nestingKind.toString());
throw new RuntimeException("Mismatch of expected and reported nesting kind.");
}
}
}
if (!classesFound) {
throw new RuntimeException("Error: no classes processed.");
}
return true;
}
}