本文整理汇总了Java中com.sun.source.tree.ArrayAccessTree类的典型用法代码示例。如果您正苦于以下问题:Java ArrayAccessTree类的具体用法?Java ArrayAccessTree怎么用?Java ArrayAccessTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArrayAccessTree类属于com.sun.source.tree包,在下文中一共展示了ArrayAccessTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
if (treePath.getLeaf().getKind() != Kind.ARRAY_ACCESS) {
return Collections.emptyList();
}
ArrayAccessTree aa = (ArrayAccessTree) treePath.getLeaf();
TypeMirror onType = info.getTrees().getTypeMirror(new TreePath(treePath, aa.getExpression()));
boolean list = isSubType(info, onType, "java.util.List");
boolean map = isSubType(info, onType, "java.util.Map");
if (list || map) {
Kind parentKind = treePath.getParentPath().getLeaf().getKind();
if (CANNOT_HANDLE_PARENTS.contains(parentKind)) return null;
return Collections.singletonList(new ConvertFromArrayAccess(info, treePath, map, parentKind == Kind.ASSIGNMENT).toEditorFix());
}
return Collections.emptyList();
}
示例2: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public Mirror visitArrayAccess(ArrayAccessTree arg0, EvaluationContext evaluationContext) {
Mirror array = arg0.getExpression().accept(this, evaluationContext);
if (array == null) {
Assert.error(arg0, "arrayIsNull", arg0.getExpression());
}
Mirror index = arg0.getIndex().accept(this, evaluationContext);
if (!(array instanceof ArrayReference)) {
Assert.error(arg0, "notArrayType", arg0.getExpression());
}
if (!(index instanceof PrimitiveValue)) {
Assert.error(arg0, "arraySizeBadType", index);
}
int i = ((PrimitiveValue) index).intValue();
if (i < 0 || i >= ((ArrayReference) array).length()) {
Assert.error(arg0, "arrayIndexOutOfBounds", array, i);
}
evaluationContext.putArrayAccess(arg0, (ArrayReference)array, i);
return ((ArrayReference) array).getValue(i);
}
示例3: matchTypeCast
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public Description matchTypeCast(TypeCastTree typeCastTree, VisitorState visitorState) {
CastingMatcher castingMatcher = new CastingMatcher();
if (!(typeCastTree.getExpression() instanceof IdentifierTree
|| typeCastTree.getExpression() instanceof ArrayAccessTree)) {
return Description.NO_MATCH;
}
if (castingMatcher.matches(typeCastTree, visitorState)) {
return buildDescription(typeCastTree)
.addFix(
SuggestedFix.replace(castingMatcher.nodeToReplace, typeCastTree.getType().toString()))
.build();
}
return Description.NO_MATCH;
}
示例4: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public AnnotatedTypeMirror visitArrayAccess(ArrayAccessTree node,
AnnotatedTypeFactory f) {
Pair<Tree, AnnotatedTypeMirror> preAssCtxt = f.visitorState.getAssignmentContext();
try {
// TODO: what other trees shouldn't maintain the context?
f.visitorState.setAssignmentContext(null);
AnnotatedTypeMirror type = f.getAnnotatedType(node.getExpression());
assert type instanceof AnnotatedArrayType;
return ((AnnotatedArrayType)type).getComponentType();
} finally {
f.visitorState.setAssignmentContext(preAssCtxt);
}
}
示例5: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public Tree visitArrayAccess(ArrayAccessTree tree, Void p) {
ArrayAccessTree n = make.ArrayAccess(tree.getExpression(), tree.getIndex());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例6: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
public Boolean visitArrayAccess(ArrayAccessTree node, TreePath p) {
if (p == null)
return super.visitArrayAccess(node, p);
ArrayAccessTree t = (ArrayAccessTree) p.getLeaf();
if (!scan(node.getExpression(), t.getExpression(), p))
return false;
return scan(node.getIndex(), t.getIndex(), p);
}
示例7: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public Void visitArrayAccess(ArrayAccessTree tree, EnumSet<UseTypes> d) {
scan(tree.getExpression(), EnumSet.of(UseTypes.READ));
scan(tree.getIndex(), EnumSet.of(UseTypes.READ));
return null;
}
示例8: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public Void visitArrayAccess(ArrayAccessTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitArrayAccess(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例9: forIndexedArray
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@TriggerPattern(value="for (int $index = 0; $index < $arr.length; $index++) $statement;", [email protected](variable="$arr", type="Object[]"))
public static ErrorDescription forIndexedArray(final HintContext ctx) {
AccessAndVarVisitor v = new AccessAndVarVisitor(ctx) {
@Override public Void visitArrayAccess(ArrayAccessTree node, Void p) {
TreePath path = getCurrentPath();
if (MatcherUtilities.matches(ctx, path, "$arr[$index]")) { // NOI18N
if (path.getParentPath() != null) {
if ( path.getParentPath().getLeaf().getKind() == Kind.ASSIGNMENT
&& ((AssignmentTree) path.getParentPath().getLeaf()).getVariable() == node) {
unsuitable();
}
if (CompoundAssignmentTree.class.isAssignableFrom(path.getParentPath().getLeaf().getKind().asInterface())
&& ((CompoundAssignmentTree) path.getParentPath().getLeaf()).getVariable() == node) {
unsuitable();
}
}
toReplace.add(path);
return null;
}
return super.visitArrayAccess(node, p);
}
};
v.scan(ctx.getVariables().get("$statement"), null); // NOI18N
if (v.unsuitable) return null;
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_IteratorToForArray(),
new ReplaceIndexedForEachLoop(ctx.getInfo(), ctx.getPath(), ctx.getVariables().get("$arr"),
v.toReplace, v.definedVariables).toEditorFix());
}
示例10: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
public Boolean visitArrayAccess(ArrayAccessTree node, ConstructorData p) {
boolean lv = lValueDereference;
// even the array reference is just read from. There's no support to track array-item lvalues.
this.lValueDereference = false;
scan(node.getExpression(), p);
scan(node.getIndex(), p);
this.lValueDereference = lv;
return null;
}
示例11: performRewrite
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
ArrayAccessTree aa = (ArrayAccessTree) ctx.getPath().getLeaf();
TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
if (assignment) {
AssignmentTree at = (AssignmentTree) ctx.getPath().getParentPath().getLeaf();
ctx.getWorkingCopy().rewrite(at, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(aa.getExpression(), map ? " put" : "set"), Arrays.asList(aa.getIndex(), at.getExpression())));
} else {
ctx.getWorkingCopy().rewrite(aa, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(aa.getExpression(), "get"), Collections.singletonList(aa.getIndex())));
}
}
示例12: visitArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
/**
* Index in array access must be int
*/
@Override
public List<? extends TypeMirror> visitArrayAccess(ArrayAccessTree node, Object p) {
if (theExpression == null) {
return null;
}
// for now we do not guess array type, just the indexes.
if (theExpression == node.getExpression()) {
return null;
}
return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.INT));
}
示例13: getElement
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
private Element getElement(Tree tree) {
TreePath expPath = TreePath.getPath(cut, tree);
Element e = trees.getElement(expPath);
if (e == null) {
if (tree instanceof ParenthesizedTree) {
e = getElement(((ParenthesizedTree) tree).getExpression());
//if (e == null) {
// System.err.println("Have null element for "+tree);
//}
//System.err.println("\nHAVE "+e.asType().toString()+" for ParenthesizedTree "+tree);
}
else if (tree instanceof TypeCastTree) {
e = getElement(((TypeCastTree) tree).getType());
//if (e == null) {
// System.err.println("Have null element for "+tree);
//}
//System.err.println("\nHAVE "+e.asType().toString()+" for TypeCastTree "+tree);
}
else if (tree instanceof AssignmentTree) {
e = getElement(((AssignmentTree) tree).getVariable());
}
else if (tree instanceof ArrayAccessTree) {
e = getElement(((ArrayAccessTree) tree).getExpression());
if (e != null) {
TypeMirror tm = e.asType();
if (tm.getKind() == TypeKind.ARRAY) {
tm = ((ArrayType) tm).getComponentType();
e = types.asElement(tm);
}
}
//System.err.println("ArrayAccessTree = "+((ArrayAccessTree) tree).getExpression()+", element = "+getElement(((ArrayAccessTree) tree).getExpression())+", type = "+getElement(((ArrayAccessTree) tree).getExpression()).asType());
}
}
return e;
}
示例14: matchArrayAccess
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
@Override
public Description matchArrayAccess(ArrayAccessTree tree, VisitorState state) {
if (!matchWithinClass) {
return Description.NO_MATCH;
}
return matchDereference(tree.getExpression(), tree, state);
}
示例15: getArrayBase
import com.sun.source.tree.ArrayAccessTree; //导入依赖的package包/类
/**
* Returns the base expression of an erray access, e.g. given {@code foo[0][0]} returns {@code
* foo}.
*/
private ExpressionTree getArrayBase(ExpressionTree node) {
while (node instanceof ArrayAccessTree) {
node = ((ArrayAccessTree) node).getExpression();
}
return node;
}