本文整理汇总了Java中com.sun.source.tree.MemberSelectTree.getExpression方法的典型用法代码示例。如果您正苦于以下问题:Java MemberSelectTree.getExpression方法的具体用法?Java MemberSelectTree.getExpression怎么用?Java MemberSelectTree.getExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.MemberSelectTree
的用法示例。
在下文中一共展示了MemberSelectTree.getExpression方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matchMemberSelect
import com.sun.source.tree.MemberSelectTree; //导入方法依赖的package包/类
@Override
public Description matchMemberSelect(MemberSelectTree tree, VisitorState state) {
if (!matchWithinClass) {
return Description.NO_MATCH;
}
Symbol symbol = ASTHelpers.getSymbol(tree);
// some checks for cases where we know it is not
// a null dereference
if (symbol == null || symbol.getSimpleName().toString().equals("class") || symbol.isEnum()) {
return Description.NO_MATCH;
}
Description badDeref = matchDereference(tree.getExpression(), tree, state);
if (!badDeref.equals(Description.NO_MATCH)) {
return badDeref;
}
// if we're accessing a field of this, make sure we're not reading the field before init
if (tree.getExpression() instanceof IdentifierTree
&& ((IdentifierTree) tree.getExpression()).getName().toString().equals("this")) {
return checkForReadBeforeInit(tree, state);
}
return Description.NO_MATCH;
}
示例2: visitMemberSelect
import com.sun.source.tree.MemberSelectTree; //导入方法依赖的package包/类
@Override
public Void visitMemberSelect(MemberSelectTree node, Void p) {
Void d = super.visitMemberSelect(node, p);
Element el = info.getTrees().getElement(getCurrentPath());
messageMethod = null;
if (el == null || el.getKind() != ElementKind.METHOD) {
return d;
}
ExecutableElement ee = (ExecutableElement)el;
String sn = ee.getSimpleName().toString();
for (MessagePattern desc : descriptions) {
if (!desc.getMethodNamePattern().matcher(sn).matches()) {
continue;
}
// check the defining type
el = ee.getEnclosingElement();
if (el == null || !(el.getKind().isClass() || el.getKind().isInterface())) {
continue;
}
TypeElement tel = (TypeElement)el;
if (!desc.getOwnerTypePattern().matcher(tel.getQualifiedName().toString()).matches()) {
continue;
}
messageMethod = desc;
methodName = sn;
methodOwnerPath = new TreePath(getCurrentPath(), node.getExpression());
break;
}
return d;
}
示例3: getStaticallyImportedElement
import com.sun.source.tree.MemberSelectTree; //导入方法依赖的package包/类
/**
* special handling of static imports
* see #196685
*
*/
private Element getStaticallyImportedElement(TreePath treePath, CompilationInfo info) {
if (treePath.getLeaf().getKind() != Tree.Kind.MEMBER_SELECT)
return null;
MemberSelectTree memberSelectTree = (MemberSelectTree) treePath.getLeaf();
TreePath tp = treePath;
while (tp!=null) {
Kind treeKind = tp.getLeaf().getKind();
if (treeKind == Tree.Kind.IMPORT) {
if (!((ImportTree) tp.getLeaf()).isStatic()) {
return null;
}
break;
} else if (treeKind == Tree.Kind.MEMBER_SELECT || treeKind == Tree.Kind.IDENTIFIER) {
tp = tp.getParentPath();
continue;
}
return null;
}
Name simpleName = memberSelectTree.getIdentifier();
if (simpleName == null) {
return null;
}
TreePath declPath = new TreePath(new TreePath(treePath, memberSelectTree), memberSelectTree.getExpression());
TypeElement decl = (TypeElement) info.getTrees().getElement(declPath);
if (decl==null) {
return null;
}
for (Element e : info.getElements().getAllMembers((TypeElement) decl)) {
if (!e.getModifiers().contains(Modifier.STATIC)) {
continue;
}
if (!e.getSimpleName().equals(simpleName)) {
continue;
}
return e;
}
return null;
}
示例4: visitMemberSelect
import com.sun.source.tree.MemberSelectTree; //导入方法依赖的package包/类
@Override
public Void visitMemberSelect(MemberSelectTree tree, EnumSet<UseTypes> d) {
long memberSelectBypassLoc = memberSelectBypass;
memberSelectBypass = -1;
Element el = info.getTrees().getElement(getCurrentPath());
if (el != null && el.getKind() == ElementKind.MODULE) {
handlePossibleIdentifier(getCurrentPath(), EnumSet.of(UseTypes.MODULE_USE));
tl.moduleNameHere(tree, tree2Tokens);
return null;
}
Tree expr = tree.getExpression();
if (expr instanceof IdentifierTree) {
TreePath tp = new TreePath(getCurrentPath(), expr);
handlePossibleIdentifier(tp, EnumSet.of(UseTypes.READ));
}
if (el != null && el.getKind().isField()) {
handlePossibleIdentifier(getCurrentPath(), d == null ? EnumSet.of(UseTypes.READ) : d);
}
if (el != null && (el.getKind().isClass() || el.getKind().isInterface()) &&
getCurrentPath().getParentPath().getLeaf().getKind() != Kind.NEW_CLASS) {
handlePossibleIdentifier(getCurrentPath(), EnumSet.of(UseTypes.CLASS_USE));
}
// System.err.println("XXXX=" + tree.toString());
// System.err.println("YYYY=" + info.getElement(tree));
super.visitMemberSelect(tree, d);
tl.moveToEnd(tree.getExpression());
if (memberSelectBypassLoc != (-1)) {
tl.moveToOffset(memberSelectBypassLoc);
}
firstIdentifier(tree.getIdentifier().toString());
return null;
}
示例5: visitImport
import com.sun.source.tree.MemberSelectTree; //导入方法依赖的package包/类
@Override
public Void visitImport(ImportTree tree, Void d) {
if (parseErrorInImport(tree)) {
return super.visitImport(tree, null);
}
if (tree.getQualifiedIdentifier() == null ||
tree.getQualifiedIdentifier().getKind() != Tree.Kind.MEMBER_SELECT) {
return super.visitImport(tree, null);
}
MemberSelectTree qualIdent = (MemberSelectTree) tree.getQualifiedIdentifier();
boolean assign = false;
// static imports and star imports only use the qualifier part
boolean star = isStar(tree);
TreePath tp = tree.isStatic() || star ?
new TreePath(new TreePath(getCurrentPath(), qualIdent), qualIdent.getExpression()) :
new TreePath(getCurrentPath(), tree.getQualifiedIdentifier());
Element decl = info.getTrees().getElement(tp);
import2Highlight.put(tree, getCurrentPath());
if (decl != null && !isErroneous(decl)) {
if (!tree.isStatic()) {
if (star) {
List<TypeElement> types = ElementFilter.typesIn(decl.getEnclosedElements());
for (TypeElement te : types) {
assign = true;
if (!element2Import.containsKey(te)) {
element2Import.put(te, tree);
}
}
} else {
element2Import.put(decl, tree);
importedBySingleImport.add(decl);
}
} else if (decl.getKind().isClass() || decl.getKind().isInterface()) {
Name simpleName = star ? null : qualIdent.getIdentifier();
for (Element e : info.getElements().getAllMembers((TypeElement) decl)) {
if (!e.getModifiers().contains(Modifier.STATIC)) continue;
if (simpleName != null && !e.getSimpleName().equals(simpleName)) {
continue;
}
if (!star || !element2Import.containsKey(e)) {
element2Import.put(e, tree);
}
assign = true;
}
}
}
if (!assign) {
if (!tree.isStatic() && star) {
unresolvablePackageImports.add(tree);
} else {
addUnresolvableImport(qualIdent.getIdentifier(), tree);
}
}
super.visitImport(tree, null);
return null;
}
示例6: computeFixes
import com.sun.source.tree.MemberSelectTree; //导入方法依赖的package包/类
protected static Fix computeFixes(CompilationInfo info, TreePath treePath, int[] bounds, int[] kind, String[] simpleName) {
if (treePath.getLeaf().getKind() != Kind.MEMBER_SELECT) {
return null;
}
MemberSelectTree mst = (MemberSelectTree)treePath.getLeaf();
Tree expression = mst.getExpression();
TreePath expr = new TreePath(treePath, expression);
TypeMirror tm = info.getTrees().getTypeMirror(expr);
if (!Utilities.isValidType(tm)) {
return null;
}
Element el = info.getTypes().asElement(tm);
if (el == null || (!el.getKind().isClass() && !el.getKind().isInterface())) {
return null;
}
TypeElement type = (TypeElement)el;
if (isError(type)) {
return null;
}
Name idName = null;
if (expression.getKind() == Kind.MEMBER_SELECT) {
MemberSelectTree exprSelect = (MemberSelectTree)expression;
idName = exprSelect.getIdentifier();
}
if (expression.getKind() == Kind.IDENTIFIER) {
IdentifierTree idt = (IdentifierTree)expression;
idName = idt.getName();
}
if (idName != null) {
if (idName.equals(type.getSimpleName())) {
return null;
}
if (idName.equals(type.getQualifiedName())) {
return null;
}
}
Element used = info.getTrees().getElement(treePath);
if (used == null || !used.getModifiers().contains(Modifier.STATIC)) {
return null;
}
if (isError(used)) {
return null;
}
if (used.getKind().isField()) {
kind[0] = 0;
} else {
if (used.getKind() == ElementKind.METHOD) {
kind[0] = 1;
} else {
kind[0] = 2;
}
}
simpleName[0] = used.getSimpleName().toString();
return new FixImpl(info, expr, type).toEditorFix();
}