本文整理汇总了Java中com.sun.source.tree.NewClassTree.getIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java NewClassTree.getIdentifier方法的具体用法?Java NewClassTree.getIdentifier怎么用?Java NewClassTree.getIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.NewClassTree
的用法示例。
在下文中一共展示了NewClassTree.getIdentifier方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Void visitNewClass(NewClassTree node, Stack<Tree> p) {
if (instantRename) {
return super.visitNewClass(node, p);
}
Element el = info.getTrees().getElement(getCurrentPath());
if (toFind.equals(el) && node.getIdentifier() != null) {
Token<JavaTokenId> t = Utilities.getToken(info, doc, new TreePath(getCurrentPath(), node.getIdentifier()));
if (t != null)
usages.add(t);
return null;
}
if (el != null && toFind.equals(el.getEnclosingElement())) {
return null;
}
return super.visitNewClass(node, p);
}
示例2: performRewrite
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) {
WorkingCopy copy = ctx.getWorkingCopy();
TreePath tp = ctx.getPath();
if (tp.getLeaf().getKind() != Tree.Kind.NEW_CLASS) {
//XXX: warning
return ;
}
NewClassTree nct = (NewClassTree) tp.getLeaf();
if (nct.getIdentifier().getKind() != Tree.Kind.PARAMETERIZED_TYPE) {
//XXX: warning
return ;
}
TreeMaker make = copy.getTreeMaker();
ParameterizedTypeTree ptt = (ParameterizedTypeTree) nct.getIdentifier();
ParameterizedTypeTree nue = make.ParameterizedType(ptt.getType(), Collections.<Tree>emptyList());
copy.rewrite(ptt, nue);
}
示例3: checkAlternativeInvocation
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
/**
* Attempts to resolve a method or a constructor call with an altered argument tree.
*
* @param ci the context
* @param invPath path to the method invocation node
* @param origPath path to the Tree within method's arguments which should be replaced
* @param valPath the replacement tree
* @return
*/
public static boolean checkAlternativeInvocation(CompilationInfo ci, TreePath invPath,
TreePath origPath,
TreePath valPath, String customPrefix) {
Tree l = invPath.getLeaf();
Tree sel;
if (l.getKind() == Tree.Kind.NEW_CLASS) {
NewClassTree nct = (NewClassTree)invPath.getLeaf();
sel = nct.getIdentifier();
} else if (l.getKind() == Tree.Kind.METHOD_INVOCATION) {
MethodInvocationTree mit = (MethodInvocationTree)invPath.getLeaf();
sel = mit.getMethodSelect();
} else {
return false;
}
return resolveAlternativeInvocation(ci, invPath,
origPath, sel, valPath, customPrefix);
}
示例4: computeNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeNewClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
NewClassTree nct = (NewClassTree) parent.getLeaf();
boolean errorInRealArguments = false;
for (Tree param : nct.getArguments()) {
errorInRealArguments |= param == error;
}
if (errorInRealArguments) {
List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
int[] proposedIndex = new int[1];
List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
if (ee.isEmpty()) { //cannot be resolved
return null;
}
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return proposedTypes;
}
Tree id = nct.getIdentifier();
if (id.getKind() == Kind.PARAMETERIZED_TYPE) {
id = ((ParameterizedTypeTree) id).getType();
}
if (id == error) {
return resolveType(EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null);
}
return null;
}
示例5: computeNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeNewClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
NewClassTree nct = (NewClassTree) parent.getLeaf();
boolean errorInRealArguments = false;
for (Tree param : nct.getArguments()) {
errorInRealArguments |= param == error;
}
if (errorInRealArguments) {
List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
int[] proposedIndex = new int[1];
List<ExecutableElement> ee = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
if (ee.isEmpty()) { //cannot be resolved
return null;
}
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return proposedTypes;
}
Tree id = nct.getIdentifier();
if (id.getKind() == Kind.PARAMETERIZED_TYPE) {
id = ((ParameterizedTypeTree) id).getType();
}
if (id == error) {
return resolveType(EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null);
}
return null;
}
示例6: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Void visitNewClass(NewClassTree node, Void p) {
AnnotatedDeclaredType type = atypeFactory.getAnnotatedType(node);
ExpressionTree identifier = node.getIdentifier();
if (identifier instanceof AnnotatedTypeTree) {
AnnotatedTypeTree t = (AnnotatedTypeTree) identifier;
for (AnnotationMirror a : atypeFactory.getAnnotatedType(t).getAnnotations()) {
// is this an annotation of the nullness checker?
boolean nullnessCheckerAnno = containsSameIgnoringValues(
atypeFactory.getNullnessAnnotations(), a);
if (nullnessCheckerAnno && !AnnotationUtils.areSame(NONNULL, a)) {
// The type is not non-null => warning
checker.report(
Result.warning("new.class.type.invalid",
type.getAnnotations()), node);
// Note that other consistency checks are made by isValid.
}
}
if (t.toString().contains("@PolyNull")) {
// TODO: this is a hack, but PolyNull gets substituted
// afterwards
checker.report(
Result.warning("new.class.type.invalid",
type.getAnnotations()), node);
}
}
// TODO: It might be nicer to introduce a framework-level
// isValidNewClassType or some such.
return super.visitNewClass(node, p);
}
示例7: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Object visitNewClass(NewClassTree c, Trees ts) {
ExpressionTree type = c.getIdentifier();
if (type != null) {
count("new", type.toString());
}
return super.visitNewClass(c, ts);
}
示例8: getElementPosition
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
static List<Integer> getElementPosition( CompilationInfo info, Tree tree ) {
SourcePositions srcPos = info.getTrees().getSourcePositions();
Tree subjectTree = tree;
if (Tree.Kind.ANNOTATION.equals(subjectTree.getKind())) {
subjectTree = ((AnnotationTree) subjectTree).getAnnotationType();
}
int startOffset =
(int) srcPos.getStartPosition(info.getCompilationUnit(),
subjectTree);
int endOffset =
(int) srcPos.getEndPosition(info.getCompilationUnit(),
subjectTree);
Tree startTree = null;
NewClassTree newClassTree = getNewClassTree(info, tree);
if (newClassTree != null) {
startTree = newClassTree.getIdentifier();
subjectTree = newClassTree;
}
else if (TreeUtilities.CLASS_TREE_KINDS.contains(subjectTree.getKind()))
{
startTree = ((ClassTree) subjectTree).getModifiers();
}
else if (subjectTree.getKind() == Tree.Kind.METHOD) {
startTree = ((MethodTree) subjectTree).getReturnType();
}
else if (subjectTree.getKind() == Tree.Kind.VARIABLE) {
startTree = ((VariableTree) subjectTree).getType();
}
if (startTree != null) {
int searchStart;
if (newClassTree == null) {
searchStart =
(int) srcPos.getEndPosition(info.getCompilationUnit(),
startTree);
}
else {
searchStart =
(int) srcPos.getStartPosition(
info.getCompilationUnit(), startTree);
}
TokenSequence<?> tokenSequence =
info.getTreeUtilities().tokensFor(subjectTree);
if (tokenSequence != null) {
boolean eob = false;
tokenSequence.move(searchStart);
do {
eob = !tokenSequence.moveNext();
}
while (!eob
&& tokenSequence.token().id() != JavaTokenId.IDENTIFIER);
if (!eob) {
Token<?> identifier = tokenSequence.token();
startOffset = identifier.offset(info.getTokenHierarchy());
endOffset = startOffset + identifier.length();
}
}
}
List<Integer> result = new ArrayList<>(2);
result.add(startOffset);
result.add(endOffset);
return result;
}