本文整理匯總了Java中com.sun.source.tree.VariableTree.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java VariableTree.getName方法的具體用法?Java VariableTree.getName怎麽用?Java VariableTree.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.source.tree.VariableTree
的用法示例。
在下文中一共展示了VariableTree.getName方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleVariable
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
private List<ErrorDescription> handleVariable(CompilationInfo info, TreePath treePath) {
VariableTree vt = (VariableTree) treePath.getLeaf();
if (vt.getName() == null)
return null;
String declarationName = vt.getName().toString();
String actualName = getName(vt.getInitializer());
if (isConflicting(info, declarationName, actualName)) {
int[] span = info.getTreeUtilities().findNameSpan(vt);
if (span != null) {
String description = NbBundle.getMessage(SuspiciousNamesCombination.class, "HINT_SuspiciousNamesCombination");
return Collections.singletonList(ErrorDescriptionFactory.createErrorDescription(getSeverity().toEditorSeverity(), description, info.getFileObject(), span[0], span[1]));
}
}
return null;
}
示例2: createHashCodeLineForField
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
private String createHashCodeLineForField(VariableTree field) {
Name fieldName = field.getName();
Tree fieldType = field.getType();
if (fieldType.getKind() == Tree.Kind.PRIMITIVE_TYPE) {
if (((PrimitiveTypeTree) fieldType).getPrimitiveTypeKind() == TypeKind.BOOLEAN) {
return "hash += (" + fieldName + " ? 1 : 0"; // NOI18N
}
return "hash += (int)" + fieldName + ";"; // NOI18N
}
return "hash += (" + fieldName + " != null ? " + fieldName + ".hashCode() : 0);"; // NOI18N
}
示例3: createEqualsLineForField
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
private String createEqualsLineForField(VariableTree field) {
Name fieldName = field.getName();
Tree fieldType = field.getType();
if (fieldType.getKind() == Tree.Kind.PRIMITIVE_TYPE) {
return "if (this." + fieldName + " != other." + fieldName + ") return false;"; // NOI18N
}
return "if ((this." + fieldName + " == null && other." + fieldName + " != null) || " + "(this." + fieldName +
" != null && !this." + fieldName + ".equals(other." + fieldName + "))) return false;"; // NOI18N
}
示例4: createFinallyCloseBlockStatement
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
private StatementTree createFinallyCloseBlockStatement(VariableTree origDeclaration) {
Trees trees = info.getTrees();
TypeMirror tm = trees.getTypeMirror(statement);
ElementUtilities elUtils = info.getElementUtilities();
Iterable iterable = elUtils.getMembers(tm, new ElementAcceptor() {
public boolean accept(Element e, TypeMirror type) {
return e.getKind() == ElementKind.METHOD && "close".equals(e.getSimpleName().toString()); // NOI18N
}
});
boolean throwsIO = false;
for (Iterator iter = iterable.iterator(); iter.hasNext(); ) {
ExecutableElement elem = (ExecutableElement) iter.next();
if (!elem.getParameters().isEmpty()) {
continue;
} else {
for (TypeMirror typeMirror : elem.getThrownTypes()) {
if ("java.io.IOException".equals(typeMirror.toString())) { // NOI18N
throwsIO = true;
break;
}
}
}
}
CharSequence name = origDeclaration.getName();
StatementTree close = make.ExpressionStatement(make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(make.Identifier(name), "close"), Collections.<ExpressionTree>emptyList()));
StatementTree result = close;
if (throwsIO) {
result = make.Try(make.Block(Collections.singletonList(close), false), Collections.singletonList(createCatch(info, make, statement, inferName(info, statement), info.getElements().getTypeElement("java.io.IOException").asType())), null);
}
return result;
}
示例5: checkParamOverriding
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
private Description checkParamOverriding(
Tree tree,
List<? extends VariableTree> methodParams,
Symbol.MethodSymbol closestOverriddenMethod,
boolean isLambda) {
com.sun.tools.javac.util.List<VarSymbol> superParamSymbols =
closestOverriddenMethod.getParameters();
for (int i = 0; i < superParamSymbols.size(); i++) {
VarSymbol superParam = superParamSymbols.get(i);
if (Nullness.hasNullableAnnotation(superParam)) {
VariableTree param = methodParams.get(i);
VarSymbol paramSymbol = ASTHelpers.getSymbol(param);
// in the case where we have a parameter of a lambda expression, we do
// *not* force the parameter to be annotated with @Nullable; instead we "inherit"
// nullability from the corresponding functional interface method
if (!Nullness.hasNullableAnnotation(paramSymbol)
&& !(isLambda && !NullabilityUtil.lambdaParamIsExplicitlyTyped(param))) {
String message =
"parameter "
+ param.getName()
+ " is @NonNull, but parameter in "
+ (isLambda ? "functional interface " : "superclass ")
+ "method "
+ ASTHelpers.enclosingClass(closestOverriddenMethod)
+ "."
+ closestOverriddenMethod.toString()
+ " is @Nullable";
return createErrorDescription(MessageTypes.WRONG_OVERRIDE_PARAM, param, message, param);
}
}
}
return Description.NO_MATCH;
}
示例6: computeFixes
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
@Override
protected List<Fix> computeFixes(CompilationInfo compilationInfo, TreePath treePath, int[] bounds) {
if (treePath.getLeaf().getKind() != Kind.VARIABLE) {
return null;
}
VariableTree vt = (VariableTree)treePath.getLeaf();
Element el = compilationInfo.getTrees().getElement(treePath);
if (el == null) {
return null;
}
if (el.getKind() == ElementKind.FIELD) {
return null;
}
boolean isStatic = false;
while (el != null && !(el instanceof TypeElement)) {
isStatic = el.getModifiers().contains(Modifier.STATIC);
el = el.getEnclosingElement();
}
if (el == null) {
return null;
}
if (treePath.getParentPath().getLeaf().getKind() == Kind.METHOD) {
// skip method values
return null;
}
Element hidden = null;
for (Element e : getAllMembers(compilationInfo, (TypeElement)el)) {
if (stop) {
return null;
}
if (e.getKind() != ElementKind.FIELD) {
continue;
}
if (isStatic && !e.getModifiers().contains(Modifier.STATIC)) {
continue;
}
if (e.getSimpleName() == vt.getName()) {
hidden = e;
break;
}
}
if (hidden == null) {
return null;
}
int[] span = compilationInfo.getTreeUtilities().findNameSpan(vt);
if (span == null) {
return null;
}
List<Fix> fixes = Collections.<Fix>singletonList(new FixImpl(
(span[1] + span[0]) / 2,
compilationInfo.getFileObject(),
true
));
bounds[0] = span[0];
bounds[1] = span[1];
return fixes;
}
示例7: compare
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
@Hint(
displayName = "#DN_ComparatorParameterNotUsed",
description = "#DESC_ComparatorParameterNotUsed",
category = "bugs",
suppressWarnings = { "ComparatorMethodParameterNotUsed" },
enabled = true
)
@TriggerPattern("public int compare($v1, $v2) { $stmts$; } ")
public static List<ErrorDescription> run(HintContext ctx) {
CompilationInfo ci = ctx.getInfo();
Element me = ci.getTrees().getElement(ctx.getPath());
if (me == null) {
return null;
}
Element clazz = me.getEnclosingElement();
if (clazz == null || !(
clazz.getKind().isClass() ||
/* JDK8 */ (clazz.getKind().isInterface() && me.getModifiers().contains(Modifier.DEFAULT)))
) {
// method bod not valid at this point
return null;
}
TypeMirror tm = clazz.asType();
TypeElement comparableIface = ci.getElements().getTypeElement("java.lang.Comparable"); // NOI18N
// the eclosing type must implement or extend comparable
if (comparableIface == null ||
!ci.getTypes().isSubtype(tm, comparableIface.asType())) {
return null;
}
Set<VariableElement> vars = new HashSet<VariableElement>(2);
ExecutableElement ee = (ExecutableElement)me;
vars.addAll(ee.getParameters());
ComparatorParameterNotUsed v = new ComparatorParameterNotUsed(ci, vars);
MethodTree mt = (MethodTree)ctx.getPath().getLeaf();
if (mt.getBody() == null) {
return null;
}
try {
v.scan(new TreePath(ctx.getPath(), mt.getBody()), v);
} catch (StopProcessing ex) {
// nothing, just fast interrupt
}
if (v.unusedVars.isEmpty()) {
return null;
}
// the method has exactly 2 parameters:
VariableTree par1 = mt.getParameters().get(0);
VariableTree par2 = mt.getParameters().get(1);
List<? extends VariableElement> ll = new ArrayList<VariableElement>(v.unusedVars);
List<ErrorDescription> res = new ArrayList<>(ll.size());
Collections.sort(ll, Collator.getInstance());
for (VariableElement ve : ll) {
Tree vt = ve.getSimpleName() == par1.getName() ? par1 : par2;
res.add(
ErrorDescriptionFactory.forName(ctx, vt,
TEXT_ComparatorParameterNotUsed(ve.getSimpleName().toString())
));
}
return res;
}
示例8: createFieldSignature
import com.sun.source.tree.VariableTree; //導入方法依賴的package包/類
public static String createFieldSignature(VariableTree v) {
return getShortTypeName(v.getType().toString()) + " " + v.getName();
}