本文整理汇总了Java中javax.lang.model.SourceVersion类的典型用法代码示例。如果您正苦于以下问题:Java SourceVersion类的具体用法?Java SourceVersion怎么用?Java SourceVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceVersion类属于javax.lang.model包,在下文中一共展示了SourceVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillIn
import javax.lang.model.SourceVersion; //导入依赖的package包/类
private void fillIn(PackageSymbol p,
Location location,
Iterable<JavaFileObject> files) {
currentLoc = location;
for (JavaFileObject fo : files) {
switch (fo.getKind()) {
case CLASS:
case SOURCE: {
// TODO pass binaryName to includeClassFile
String binaryName = fileManager.inferBinaryName(currentLoc, fo);
String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1);
if (SourceVersion.isIdentifier(simpleName) ||
simpleName.equals("package-info"))
includeClassFile(p, fo);
break;
}
default:
extraFileActions(p, fo);
}
}
}
示例2: resolveIdent
import javax.lang.model.SourceVersion; //导入依赖的package包/类
/**
* Resolve an identifier.
*
* @param name The identifier to resolve
*/
public Symbol resolveIdent(String name) {
if (name.equals(""))
return syms.errSymbol;
JavaFileObject prev = log.useSource(null);
try {
JCExpression tree = null;
for (String s : name.split("\\.", -1)) {
if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
return syms.errSymbol;
tree = (tree == null) ? make.Ident(names.fromString(s))
: make.Select(tree, names.fromString(s));
}
JCCompilationUnit toplevel =
make.TopLevel(List.<JCAnnotation>nil(), null, List.<JCTree>nil());
toplevel.packge = syms.unnamedPackage;
return attr.attribIdent(tree, toplevel);
} finally {
log.useSource(prev);
}
}
示例3: correctMethodParameterName
import javax.lang.model.SourceVersion; //导入依赖的package包/类
public static String correctMethodParameterName(String paramName) {
if (SourceVersion.isName(paramName)) {
return paramName;
}
StringBuffer newParam = new StringBuffer();
char tempChar;
for (int index = 0; index < paramName.length(); index++) {
tempChar = paramName.charAt(index);
if (Character.isJavaIdentifierPart(tempChar)) {
newParam.append(paramName.charAt(index));
} else if (tempChar == '.' || tempChar == '-') {
newParam.append('_');
}
}
return newParam.toString();
}
示例4: addOptionButtonActionPerformed
import javax.lang.model.SourceVersion; //导入依赖的package包/类
private void addOptionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOptionButtonActionPerformed
final AddProcessorOption panel = new AddProcessorOption();
final DialogDescriptor desc = new DialogDescriptor(panel, NbBundle.getMessage (CustomizerCompile.class, "LBL_AddProcessorOption_Title")); //NOI18N
desc.setValid(false);
panel.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
String key = panel.getOptionKey();
for(String s : key.split("\\.", -1)) { //NOI18N
if (!SourceVersion.isIdentifier(s)) {
desc.setValid(false);
return;
}
}
desc.setValid(true);
}
});
Dialog dlg = DialogDisplayer.getDefault().createDialog(desc);
dlg.setVisible (true);
if (desc.getValue() == DialogDescriptor.OK_OPTION) {
((DefaultTableModel)processorOptionsTable.getModel()).addRow(new String[] {panel.getOptionKey(), panel.getOptionValue()});
}
dlg.dispose();
}
示例5: adjustName
import javax.lang.model.SourceVersion; //导入依赖的package包/类
private static String adjustName(String name) {
if (name == null) {
return null;
}
String shortName = null;
if (name.startsWith("get") && name.length() > 3) { //NOI18N
shortName = name.substring(3);
}
if (name.startsWith("is") && name.length() > 2) { //NOI18N
shortName = name.substring(2);
}
if (shortName != null) {
return firstToLower(shortName);
}
if (SourceVersion.isKeyword(name)) {
return "a" + Character.toUpperCase(name.charAt(0)) + name.substring(1); //NOI18N
} else {
return name;
}
}
示例6: firstToLower
import javax.lang.model.SourceVersion; //导入依赖的package包/类
private static String firstToLower(String name) {
if (name.length() == 0) {
return null;
}
StringBuilder result = new StringBuilder();
boolean toLower = true;
char last = Character.toLowerCase(name.charAt(0));
for (int i = 1; i < name.length(); i++) {
if (toLower && Character.isUpperCase(name.charAt(i))) {
result.append(Character.toLowerCase(last));
} else {
result.append(last);
toLower = false;
}
last = name.charAt(i);
}
result.append(last);
if (SourceVersion.isKeyword(result)) {
return "a" + name; //NOI18N
} else {
return result.toString();
}
}
示例7: generateComment
import javax.lang.model.SourceVersion; //导入依赖的package包/类
public String generateComment(VariableElement field, CompilationInfo javac) {
StringBuilder builder = new StringBuilder(
// "/**\n" + // NOI18N
"\n" // NOI18N
);
if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0 &&
JavadocUtilities.isDeprecated(javac, field)) {
builder.append("@deprecated\n"); // NOI18N
}
// builder.append("*/\n"); // NOI18N
return builder.toString();
}
示例8: isValidOptionName
import javax.lang.model.SourceVersion; //导入依赖的package包/类
public static boolean isValidOptionName(String optionName) {
for(String s : optionName.split("\\.", -1)) {
if (!SourceVersion.isIdentifier(s))
return false;
}
return true;
}
示例9: getSupportedSourceVersion
import javax.lang.model.SourceVersion; //导入依赖的package包/类
@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();
}
示例10: isValidName
import javax.lang.model.SourceVersion; //导入依赖的package包/类
private static boolean isValidName(String name) {
// Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ),
// but the set of keywords depends on the source level, and we don't want
// impls of JavaFileManager to have to be dependent on the source level.
// Therefore we simply check that the argument is a sequence of identifiers
// separated by ".".
for (String s : name.split("\\.", -1)) {
if (!SourceVersion.isIdentifier(s))
return false;
}
return true;
}
示例11: isValidImportString
import javax.lang.model.SourceVersion; //导入依赖的package包/类
/**
* Return true if the argument string is a valid import-style
* string specifying claimed annotations; return false otherwise.
*/
public static boolean isValidImportString(String s) {
if (s.equals("*"))
return true;
boolean valid = true;
String t = s;
int index = t.indexOf('*');
if (index != -1) {
// '*' must be last character...
if (index == t.length() -1) {
// ... any and preceding character must be '.'
if ( index-1 >= 0 ) {
valid = t.charAt(index-1) == '.';
// Strip off ".*$" for identifier checks
t = t.substring(0, t.length()-2);
}
} else
return false;
}
// Verify string is off the form (javaId \.)+ or javaId
if (valid) {
String[] javaIds = t.split("\\.", t.length()+2);
for(String javaId: javaIds)
valid &= SourceVersion.isIdentifier(javaId);
}
return valid;
}
示例12: toConstantName
import javax.lang.model.SourceVersion; //导入依赖的package包/类
public String toConstantName( String token ) {
String name = super.toConstantName(token);
if(!SourceVersion.isKeyword(name))
return name;
else
return '_'+name;
}
示例13: getSupportedSourceVersion
import javax.lang.model.SourceVersion; //导入依赖的package包/类
/**
* If the processor class is annotated with {@link
* SupportedSourceVersion}, return the source version in the
* annotation. If the class is not so annotated, {@link
* SourceVersion#RELEASE_6} is returned.
*
* @return the latest source version supported by this processor
*/
public SourceVersion getSupportedSourceVersion() {
SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
SourceVersion sv = null;
if (ssv == null) {
sv = SourceVersion.RELEASE_6;
if (isInitialized())
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
"No SupportedSourceVersion annotation " +
"found on " + this.getClass().getName() +
", returning " + sv + ".");
} else
sv = ssv.value();
return sv;
}
示例14: 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);
}
}
示例15: sourceVersion
import javax.lang.model.SourceVersion; //导入依赖的package包/类
public @NonNull SourceVersion sourceVersion() {
String sourceLevel = SourceLevelQuery.getSourceLevel(ctx.getInfo().getFileObject());
if (sourceLevel == null) {
return SourceVersion.latest(); //TODO
}
String[] splited = sourceLevel.split("\\.");
String spec = splited[1];
return SourceVersion.valueOf("RELEASE_"+ spec);//!!!
}