本文整理汇总了Java中com.sun.source.tree.LiteralTree.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java LiteralTree.getKind方法的具体用法?Java LiteralTree.getKind怎么用?Java LiteralTree.getKind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.LiteralTree
的用法示例。
在下文中一共展示了LiteralTree.getKind方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
if (!type.isAnnotatedInHierarchy(FORMAT)) {
String format = null;
if (tree.getKind() == Tree.Kind.STRING_LITERAL) {
format = (String) tree.getValue();
} else if (tree.getKind() == Tree.Kind.CHAR_LITERAL) {
format = Character.toString((Character) tree.getValue());
}
if (format != null) {
AnnotationMirror anno;
try {
ConversionCategory[] cs = FormatUtil.formatParameterCategories(format);
anno = FormatterAnnotatedTypeFactory.this.treeUtil.categoriesToFormatAnnotation(cs);
} catch (IllegalFormatException e) {
anno = FormatterAnnotatedTypeFactory.this.treeUtil.exceptionToInvalidFormatAnnotation(e);
}
type.addAnnotation(anno);
}
}
return super.visitLiteral(tree, type);
}
示例2: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
/**
* Case 1: valid regular expression String or char literal.
* Adds PartialRegex annotation to String literals that are not valid
* regular expressions.
*/
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
if (!type.isAnnotatedInHierarchy(REGEX)) {
String regex = null;
if (tree.getKind() == Tree.Kind.STRING_LITERAL) {
regex = (String) tree.getValue();
} else if (tree.getKind() == Tree.Kind.CHAR_LITERAL) {
regex = Character.toString((Character) tree.getValue());
}
if (regex != null) {
if (isRegex(regex)) {
int groupCount = getGroupCount(regex);
type.addAnnotation(createRegexAnnotation(groupCount));
} else {
type.addAnnotation(createPartialRegexAnnotation(regex));
}
}
}
return super.visitLiteral(tree, type);
}
示例3: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
/**
* Go through the string patterns and add the greatest lower bound of all matching patterns.
*/
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
if (!stringPatterns.isEmpty() && tree.getKind() == Tree.Kind.STRING_LITERAL) {
Set<? extends AnnotationMirror> res = null;
String string = (String) tree.getValue();
for (Pattern pattern : stringPatterns.keySet()) {
if (pattern.matcher(string).matches()) {
if (res == null) {
res = stringPatterns.get(pattern);
} else {
Set<? extends AnnotationMirror> newres = stringPatterns.get(pattern);
res = qualHierarchy.greatestLowerBounds(res, newres);
}
}
}
if (res != null) {
type.addAnnotations(res);
}
}
return super.visitLiteral(tree, type);
}
示例4: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Object visitLiteral(LiteralTree node, Void p) {
if (node.getKind() == NULL_LITERAL) {
return enhanceProcessing ? NULL : null;
}
return node.getValue();
}
示例5: generateDataflowAnnoFromLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
public static AnnotationMirror generateDataflowAnnoFromLiteral(LiteralTree node, ProcessingEnvironment processingEnv) {
String datatypeInArray[] = { "" };
// String datatypeInArray[] = null;
switch (node.getKind()) {
case STRING_LITERAL:
datatypeInArray = convert(String.class.toString().split(" ")[1]);
break;
case INT_LITERAL:
datatypeInArray = convert(int.class.toString());
break;
case LONG_LITERAL:
datatypeInArray = convert(long.class.toString());
break;
case FLOAT_LITERAL:
datatypeInArray = convert(float.class.toString());
break;
case DOUBLE_LITERAL:
datatypeInArray = convert(double.class.toString());
break;
case BOOLEAN_LITERAL:
datatypeInArray = convert(boolean.class.toString());
break;
case CHAR_LITERAL:
datatypeInArray = convert(char.class.toString());
break;
case NULL_LITERAL:
// JLTODO: this results in "" for null, which is not very useful.
// We had discussed two modes: not including null, or making it
// explicit.
break;
default:
// JLTODO: Raise an error?!
break;
}
AnnotationMirror dataFlowType = createDataflowAnnotation(
datatypeInArray, processingEnv);
return dataFlowType;
}
示例6: matches
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public boolean matches(LiteralTree literalTree, VisitorState state) {
if (literalTree.getKind() == Kind.LONG_LITERAL) {
// The javac AST doesn't seem to record whether the suffix is present, or whether it's
// an 'l' or 'L'. We have to look at the original source
String longLiteral = getLongLiteral(literalTree, state);
return longLiteral != null && longLiteral.endsWith("l");
} else {
return false;
}
}
示例7: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
/**
* Inserts {@code @Mutable} annotations on null literal trees.
*/
@Override
public Void visitLiteral(LiteralTree node, AnnotatedTypeMirror p) {
if (node.getKind() == Tree.Kind.NULL_LITERAL)
p.addAnnotation(MUTABLE);
return super.visitLiteral(node, p);
}
示例8: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
if (tree.getKind() != Tree.Kind.NULL_LITERAL) {
type.addAnnotation(COMMITTED);
}
return super.visitLiteral(tree, type);
}
示例9: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
if (!type.isAnnotatedInHierarchy(theAnnot)
&& tree.getKind() == Tree.Kind.STRING_LITERAL
&& strContains(lookupKeys, tree.getValue().toString())) {
type.addAnnotation(theAnnot);
}
// A possible extension is to record all the keys that have been used and
// in the end output a list of keys that were not used in the program,
// possibly pointing to the opposite problem, keys that were supposed to
// be used somewhere, but have not been, maybe because of copy-and-paste errors.
return super.visitLiteral(tree, type);
}
示例10: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
if (!type.isAnnotatedInHierarchy(LOCALIZED)) {
if (tree.getKind() == Tree.Kind.STRING_LITERAL && tree.getValue().equals("")) {
type.addAnnotation(LOCALIZED);
}
}
return super.visitLiteral(tree, type);
}
示例11: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public ExpressionModel visitLiteral(LiteralTree node, VisitContext context) {
switch (node.getKind()) {
case NULL_LITERAL:
return new NullLiteralModel(context.builder);
case STRING_LITERAL:
return new StringLiteralModel(context.builder, node.getValue().toString());
case BOOLEAN_LITERAL:
return context.builder.render(writer -> {
writer.renderBooleanLiteral(node.getValue().toString());
});
case INT_LITERAL:
return context.builder.render(writer -> {
writer.renderIntegerLiteral(node.getValue().toString());
});
case LONG_LITERAL:
return context.builder.render(writer -> {
writer.renderLongLiteral(node.getValue().toString());
});
case CHAR_LITERAL:
return context.builder.render(writer -> {
writer.renderCharLiteral(node.getValue().toString().charAt(0));
});
case FLOAT_LITERAL:
return context.builder.render(writer -> {
writer.renderFloatLiteral(node.getValue().toString());
});
case DOUBLE_LITERAL:
return context.builder.render(writer -> {
writer.renderDoubleLiteral(node.getValue().toString());
});
default:
throw new UnsupportedOperationException("Literal " + node.getKind().name() + " not yet implemented");
}
}
示例12: visitLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Boolean visitLiteral(LiteralTree node, Void unused) {
switch (node.getKind()) {
case STRING_LITERAL:
case INT_LITERAL:
case LONG_LITERAL:
case FLOAT_LITERAL:
case DOUBLE_LITERAL:
case BOOLEAN_LITERAL:
case CHAR_LITERAL:
return true;
default:
return false;
}
}
示例13: matchLiteral
import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Description matchLiteral(LiteralTree tree, VisitorState state) {
if (tree.getKind() != STRING_LITERAL) {
return Description.NO_MATCH;
}
// Hard-coded paths may come handy when writing tests. Therefore, we suppress the check
// for code located under 'javatests'.
if (ASTHelpers.isJUnitTestCode(state)) {
return Description.NO_MATCH;
}
String literal = (String) tree.getValue();
if (literal == null) {
return Description.NO_MATCH;
}
for (Map.Entry<String, String> entry : PATH_TABLE.entrySet()) {
String hardCodedPath = entry.getKey();
if (!literal.startsWith(hardCodedPath)) {
continue;
}
String correctPath = entry.getValue();
String remainderPath = literal.substring(hardCodedPath.length());
// Replace the hard-coded fragment of the path with a portable expression.
SuggestedFix.Builder suggestedFix = SuggestedFix.builder();
if (remainderPath.isEmpty()) {
suggestedFix.replace(tree, correctPath);
} else {
suggestedFix.replace(tree, correctPath + " + \"" + remainderPath + "\"");
}
// Add the corresponding import statements.
if (correctPath.equals(SDCARD)) {
suggestedFix.addImport("android.os.Environment");
} else {
suggestedFix.addImport("android.content.Context");
}
return describeMatch(tree, suggestedFix.build());
}
return Description.NO_MATCH;
}