< prev index next >
src/sample/share/javac/processing/src/CheckNamesProcessor.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
--- 1,7 ----
/*
! * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*** 73,85 ****
* process</i> without explicitly naming the processor to run:<br>
* {@code javac -processorpath procdir -proc:only CheckNamesProcessor.java}
*
* </ol>
*
- * For some notes on how to run an annotation processor inside
- * NetBeans, see http://wiki.java.net/bin/view/Netbeans/FaqApt.
- *
* <h3>Possible Enhancements</h3>
* <ul>
*
* <li> Support an annotation processor option to control checking
* exported API elements ({@code public} and {@code protected} ones)
--- 73,82 ----
*** 136,148 ****
@Override
public SourceVersion getSupportedSourceVersion() {
/*
* Return latest source version instead of a fixed version
! * like RELEASE_9. To return a fixed version, this class
! * could be annotated with a SupportedSourceVersion
! * annotation.
*
* Warnings will be issued if any unknown language constructs
* are encountered.
*/
return SourceVersion.latest();
--- 133,144 ----
@Override
public SourceVersion getSupportedSourceVersion() {
/*
* Return latest source version instead of a fixed version
! * like RELEASE_9. To return a fixed version, this class could
! * be annotated with a SupportedSourceVersion annotation.
*
* Warnings will be issued if any unknown language constructs
* are encountered.
*/
return SourceVersion.latest();
*** 309,322 ****
// more than once if a package's elements were visited
// too.
return null;
}
@Override
public Void visitUnknown(Element e, Void p) {
// This method will be called if a kind of element
! // added after JDK 7 is visited. Since as of this
// writing the conventions for such constructs aren't
// known, issue a warning.
messager.printMessage(WARNING,
"Unknown kind of element, " + e.getKind() +
", no name checking performed.", e);
--- 305,338 ----
// more than once if a package's elements were visited
// too.
return null;
}
+ /**
+ * Check the name of a module.
+ */
+ @Override
+ public Void visitModule(ModuleElement e, Void p) {
+ /*
+ * Implementing the checks of package names is left as
+ * an exercise for the reader.
+ */
+
+ // Similar to the options of how visiting a package
+ // could be handled, whether or not this method should
+ // call super and scan, etc. is a design choice on
+ // whether it is desired for a ModuleElement to
+ // represent a module-info file or for the
+ // ModuleElement to represent the entire contents of a
+ // module, including its packages.
+ return null;
+ }
+
@Override
public Void visitUnknown(Element e, Void p) {
// This method will be called if a kind of element
! // added after JDK 9 is visited. Since as of this
// writing the conventions for such constructs aren't
// known, issue a warning.
messager.printMessage(WARNING,
"Unknown kind of element, " + e.getKind() +
", no name checking performed.", e);
*** 401,417 ****
if (Character.isUpperCase(firstCodePoint)) {
previousUpper = true;
if (!initialCaps) {
messager.printMessage(WARNING,
! "Name, ``" + name + "'', should start in lowercase.", e);
return;
}
} else if (Character.isLowerCase(firstCodePoint)) {
if (initialCaps) {
messager.printMessage(WARNING,
! "Name, ``" + name + "'', should start in uppercase.", e);
return;
}
} else // underscore, etc.
conventional = false;
--- 417,433 ----
if (Character.isUpperCase(firstCodePoint)) {
previousUpper = true;
if (!initialCaps) {
messager.printMessage(WARNING,
! "Name ``" + name + "'' should start in lowercase.", e);
return;
}
} else if (Character.isLowerCase(firstCodePoint)) {
if (initialCaps) {
messager.printMessage(WARNING,
! "Name ``" + name + "'' should start in uppercase.", e);
return;
}
} else // underscore, etc.
conventional = false;
*** 432,453 ****
}
}
if (!conventional)
messager.printMessage(WARNING,
! "Name, ``" + name + "'', should be in camel case.", e);
}
/**
* Print a warning if the element's name is not a sequence
* of uppercase letters separated by underscores ("_").
*
* @param e the element whose name will be checked
*/
private void checkAllCaps(Element e) {
String name = e.getSimpleName().toString();
! if (e.getKind() == TYPE_PARAMETER) { // Should be one character
if (name.codePointCount(0, name.length()) > 1 ||
// Assume names are non-empty
!Character.isUpperCase(name.codePointAt(0)))
messager.printMessage(WARNING,
"A type variable's name,``" + name +
--- 448,474 ----
}
}
if (!conventional)
messager.printMessage(WARNING,
! "Name ``" + name + "'', should be in camel case.", e);
}
/**
* Print a warning if the element's name is not a sequence
* of uppercase letters separated by underscores ("_").
*
* @param e the element whose name will be checked
*/
private void checkAllCaps(Element e) {
String name = e.getSimpleName().toString();
! /*
! * Traditionally type variables are recommended to
! * have one-character names. As an exercise for the
! * reader, a more nuanced policy can be implemented.
! */
! if (e.getKind() == TYPE_PARAMETER) {
if (name.codePointCount(0, name.length()) > 1 ||
// Assume names are non-empty
!Character.isUpperCase(name.codePointAt(0)))
messager.printMessage(WARNING,
"A type variable's name,``" + name +
*** 495,504 ****
--- 516,527 ----
}
}
/**
* Lots of bad names. Don't write code like this!
+ *
+ * The unmodified name checks will print 11 warnings for this class.
*/
class BADLY_NAMED_CODE {
enum colors {
red,
blue,
< prev index next >