本文整理汇总了Java中javax.lang.model.SourceVersion.isName方法的典型用法代码示例。如果您正苦于以下问题:Java SourceVersion.isName方法的具体用法?Java SourceVersion.isName怎么用?Java SourceVersion.isName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.SourceVersion
的用法示例。
在下文中一共展示了SourceVersion.isName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateLimitModules
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private void validateLimitModules(SourceVersion sv) {
String limitModules = options.get(Option.LIMIT_MODULES);
if (limitModules != null) {
// Each entry must be of the form target-list where target-list is a
// comma separated list of module names, or ALL-DEFAULT, ALL-SYSTEM,
// or ALL-MODULE_PATH.
// Empty items in the target list are ignored.
// There must be at least one item in the list; this is handled in Option.LIMIT_EXPORTS.
for (String moduleName : limitModules.split(",")) {
switch (moduleName) {
case "":
break;
default:
if (!SourceVersion.isName(moduleName, sv)) {
// syntactically invalid module name: e.g. --limit-modules m1,m!
log.error(Errors.BadNameForOption(Option.LIMIT_MODULES, moduleName));
}
break;
}
}
}
}
示例2: validateAddModules
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private void validateAddModules(SourceVersion sv) {
String addModules = options.get(Option.ADD_MODULES);
if (addModules != null) {
// Each entry must be of the form target-list where target-list is a
// comma separated list of module names, or ALL-DEFAULT, ALL-SYSTEM,
// or ALL-MODULE_PATH.
// Empty items in the target list are ignored.
// There must be at least one item in the list; this is handled in Option.ADD_MODULES.
for (String moduleName : addModules.split(",")) {
switch (moduleName) {
case "":
case "ALL-SYSTEM":
case "ALL-MODULE-PATH":
break;
default:
if (!SourceVersion.isName(moduleName, sv)) {
// syntactically invalid module name: e.g. --add-modules m1,m!
log.error(Errors.BadNameForOption(Option.ADD_MODULES, moduleName));
}
break;
}
}
}
}
示例3: checkClassName
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private static String checkClassName(@NotNull final String className) {
requireNonNull(className);
if (!SourceVersion.isName(className)) {
throw new IllegalArgumentException("Class name " + className + " is invalid.");
}
return className;
}
示例4: fastCheckParameters
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
@Override
public Problem fastCheckParameters() {
String builderName = refactoring.getBuilderName();
String buildMethodName = refactoring.getBuildMethodName();
if (builderName == null || builderName.length() == 0) {
return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NoFactory"));
}
if (!SourceVersion.isName(builderName)) {
return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NotIdentifier", builderName));
}
if (buildMethodName == null || buildMethodName.isEmpty()) {
return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NoBuildMethod"));
}
if (!SourceVersion.isIdentifier(buildMethodName)) {
return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NotIdentifier", buildMethodName));
}
final TreePathHandle constr = treePathHandle;
ClassPath classPath = ClassPath.getClassPath(constr.getFileObject(), ClassPath.SOURCE);
String name = refactoring.getBuilderName().replace(".", "/") + ".java";
FileObject resource = classPath.findResource(name);
if (resource !=null) {
return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_FileExists", name));
}
Problem problem = null;
for (Setter set : refactoring.getSetters()) {
if(set.isOptional() && set.getDefaultValue() == null) {
problem = JavaPluginUtils.chainProblems(problem, new Problem(false, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "WRN_NODEFAULT", set.getVarName())));
}
}
return problem;
}
示例5: getClassName
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public String getClassName() {
String n = className.getText().trim();
if (n.isEmpty() || !SourceVersion.isName(n)) {
return null;
}
return n;
}
示例6: isPackageInfo
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private boolean isPackageInfo(String name, boolean allowUnnamedPackageInfo) {
// Is the name of the form "package-info" or
// "foo.bar.package-info"?
final String PKG_INFO = "package-info";
int periodIndex = name.lastIndexOf(".");
if (periodIndex == -1) {
return allowUnnamedPackageInfo ? name.equals(PKG_INFO) : false;
} else {
// "foo.bar.package-info." illegal
String prefix = name.substring(0, periodIndex);
String simple = name.substring(periodIndex+1);
return SourceVersion.isName(prefix) && simple.equals(PKG_INFO);
}
}
示例7: getPackageElement
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public PackageSymbol getPackageElement(CharSequence name) {
String strName = name.toString();
if (strName.equals(""))
return syms.unnamedPackage;
return SourceVersion.isName(strName)
? nameToSymbol(strName, PackageSymbol.class)
: null;
}
示例8: isModuleName
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**
* Returns {@code true} if the given name is a legal module name.
*/
private boolean isModuleName(String name) {
int next;
int off = 0;
while ((next = name.indexOf('.', off)) != -1) {
String id = name.substring(off, next);
if (!SourceVersion.isName(id))
return false;
off = next+1;
}
String last = name.substring(off);
return SourceVersion.isName(last);
}
示例9: doGetElement
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private <S extends Symbol> S doGetElement(ModuleElement module, String methodName,
CharSequence name, Class<S> clazz) {
String strName = name.toString();
if (!SourceVersion.isName(strName) && (!strName.isEmpty() || clazz == ClassSymbol.class)) {
return null;
}
if (module == null) {
return unboundNameToSymbol(methodName, strName, clazz);
} else {
return nameToSymbol((ModuleSymbol) module, strName, clazz);
}
}
示例10: parse
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public static JavacOptions parse(OptionChecker primary, OptionChecker secondary, String... arguments) {
List<String> recognizedOptions = new ArrayList<String>();
List<String> unrecognizedOptions = new ArrayList<String>();
List<String> classNames = new ArrayList<String>();
List<File> files = new ArrayList<File>();
for (int i = 0; i < arguments.length; i++) {
String argument = arguments[i];
int optionCount = primary.isSupportedOption(argument);
if (optionCount < 0) {
optionCount = secondary.isSupportedOption(argument);
}
if (optionCount < 0) {
File file = new File(argument);
if (file.exists())
files.add(file);
else if (SourceVersion.isName(argument))
classNames.add(argument);
else
unrecognizedOptions.add(argument);
} else {
for (int j = 0; j < optionCount + 1; j++) {
int index = i + j;
if (index == arguments.length) throw new IllegalArgumentException(argument);
recognizedOptions.add(arguments[index]);
}
i += optionCount;
}
}
return new JavacOptions(recognizedOptions, classNames, files, unrecognizedOptions);
}
示例11: checkName
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
if (lint)
log.warning(Warnings.ProcIllegalFileName(name));
throw new FilerException("Illegal name " + name);
}
}
示例12: isValidName
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private boolean isValidName(CharSequence name) {
return SourceVersion.isName(name, Source.toSourceVersion(source));
}
示例13: getValidBundleName
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private String getValidBundleName(String name) {
if (name == null) {
return null;
}
if (name.contains("..") || name.contains("//")) { // NOI18N
return null;
}
name = name.trim();
if ("".equals(name)) { // NOI18N
return null;
}
if (name.toLowerCase().endsWith(".java")) { // NOI18N
return null;
}
if (name.startsWith("/")) { // NOI18N
name = name.substring(1);
}
// We prefer if the name (without extension) can be used as a class name, but
// that can be too strict, so we allow to use any file that already exists.
int i = name.lastIndexOf('.');
String withPropertiesExt = i < 0 ? name + ".properties" : null; // NOI18N
FileObject sourceFile = getSourceFile();
ClassPath cp = ClassPath.getClassPath(sourceFile, ClassPath.SOURCE);
for (FileObject r : cp.getRoots()) {
if (FileUtil.isParentOf(r, sourceFile)) {
if (r.getFileObject(name) != null
|| (withPropertiesExt != null && r.getFileObject(withPropertiesExt) != null)) {
return name; // it exists
}
break;
}
}
String withoutExt;
String ext;
if (i >= 0) {
withoutExt = name.substring(0, i);
ext = name.substring(i+1); // one dot considered as extension
} else {
withoutExt = name;
ext = null;
}
if (withoutExt.contains(".") || withoutExt.length() == 0) { // NOI18N
return null; // likely entered dot-separated class name, but that's not allowed here
}
if (!SourceVersion.isName(withoutExt.replace('/', '.'))
|| (ext != null && !SourceVersion.isIdentifier(ext))) {
return null;
}
return name;
}
示例14: checkErrors
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
@NbBundle.Messages({
"ERR_ClassnameNotSpecified=Error: class name has not been specified",
"# {0} - class name",
"ERR_ClassnameInvalid=Error: {0} is not a valid Java class name",
"ERR_PackagDoesNotExist=Error: existing package must be selected",
"ERR_NoSourceGroups=Error: no place to generate class, set up a Source folder",
"INFO_ClassAlreadyExists=Note: The class already exists. It will be overwritten.",
"ERR_ProjectNotSelected=Project is not selected"
})
private void checkErrors() {
enableDisable();
if (project == null) {
reportError(Bundle.ERR_ProjectNotSelected());
return;
}
if (packageSelect.getItemCount() == 0) {
reportError(Bundle.ERR_NoSourceGroups());
return;
}
if (packageSelect.getSelectedItem() == null) {
reportError(Bundle.ERR_PackagDoesNotExist());
return;
}
String n = className.getText().trim();
if (n.isEmpty()) {
reportError(Bundle.ERR_ClassnameNotSpecified());
return;
}
if (!SourceVersion.isName(n)) {
reportError(Bundle.ERR_ClassnameInvalid(n));
return;
}
notifier.clearMessages();
FileObject folder = getTarget();
if (folder != null) {
n = getClassName();
FileObject existing = folder.getFileObject(n, "java"); // NOI18N
if (existing != null) {
notifier.setInformationMessage(Bundle.INFO_ClassAlreadyExists());
}
}
if (listener != null) {
listener.stateChanged(new ChangeEvent(this));
}
}
示例15: createUserMarker
import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**
* Extracts the {@link UserMarkerAnnotation} from the given element, which is expected to be an annotation
* annotated with {@link Service}. (This is checked).
* @param annotationElement The marked annotation.
* @param procEnv The current processing environment.
* @return The extracted UserMarkerAnnotation
*/
static UserMarkerAnnotation createUserMarker(Element annotationElement, ProcessingEnvironment procEnv) {
Elements elements = procEnv.getElementUtils();
// Annotations are considered interfaces, as per the documentation.
if (!annotationElement.getKind().isInterface()) {
throw new IllegalStateException(
"Annotated something that wasn't an annotation? "+annotationElement.toString());
}
TypeElement annotationMarkingSP = (TypeElement) annotationElement;
Service serviceAnnotation = annotationElement.getAnnotation(Service.class);
AnnotationMirror serviceMirror =
Util.getMatchingMirror(
elements.getTypeElement(Service.class.getName()).asType(),
elements.getAllAnnotationMirrors(annotationElement),
procEnv.getTypeUtils());
// We can't get the interface the normal way (via the annotation's methods)
// Since Class<?>'s are a runtime construct and require classloading ... etc
String interfaceQName = Util.getValueStringByName(serviceMirror, "serviceInterface");
TypeElement serviceClass = elements.getTypeElement(interfaceQName);
if (serviceClass == null) {
throw new EasyPluginException(
"Couldn't find interface class named: " + interfaceQName);
}
String serviceName = serviceAnnotation.value();
if (!SourceVersion.isName(serviceName)) {
throw new EasyPluginException(String.format("Service name isn't a valid java name: '%s'", serviceName));
}
String serviceNameFromAnnotaion = serviceAnnotation.serviceNameKey();
String outputPackage = serviceAnnotation.outputPackage();
return new UserMarkerAnnotation(
annotationMarkingSP,
serviceClass,
serviceName,
serviceNameFromAnnotaion,
outputPackage);
}