本文整理汇总了Java中org.eclipse.jdt.core.dom.Name.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java Name.getParent方法的具体用法?Java Name.getParent怎么用?Java Name.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.Name
的用法示例。
在下文中一共展示了Name.getParent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVariableDeclaration
import org.eclipse.jdt.core.dom.Name; //导入方法依赖的package包/类
private static VariableDeclaration getVariableDeclaration(Name node) {
IBinding binding = node.resolveBinding();
if (binding == null && node.getParent() instanceof VariableDeclaration)
return (VariableDeclaration) node.getParent();
if (binding != null && binding.getKind() == IBinding.VARIABLE) {
CompilationUnit cu = (CompilationUnit) ASTNodes.getParent(node, CompilationUnit.class);
return ASTNodes.findVariableDeclaration(((IVariableBinding) binding), cu);
}
return null;
}
示例2: doesParentQualify
import org.eclipse.jdt.core.dom.Name; //导入方法依赖的package包/类
private static boolean doesParentQualify(Name fieldName) {
ASTNode parent = fieldName.getParent();
Assert.isNotNull(parent);
if (parent instanceof FieldAccess && ((FieldAccess) parent).getName() == fieldName)
return true;
if (parent instanceof QualifiedName && ((QualifiedName) parent).getName() == fieldName)
return true;
if (parent instanceof MethodInvocation && ((MethodInvocation) parent).getName() == fieldName)
return true;
return false;
}
示例3: getTypeName
import org.eclipse.jdt.core.dom.Name; //导入方法依赖的package包/类
private static String getTypeName(int typeKind, Name node) {
String name = ASTNodes.getSimpleNameIdentifier(node);
if (typeKind == K_CLASS || typeKind == K_INTERFACE) {
ASTNode parent = node.getParent();
if (parent.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) {
String typeArgBaseName =
name.startsWith(String.valueOf('T'))
? String.valueOf('S')
: String.valueOf('T'); // use 'S' or 'T'
int nTypeArgs = ((ParameterizedType) parent.getParent()).typeArguments().size();
StringBuffer buf = new StringBuffer(name);
buf.append('<');
if (nTypeArgs == 1) {
buf.append(typeArgBaseName);
} else {
for (int i = 0; i < nTypeArgs; i++) {
if (i != 0) buf.append(", "); // $NON-NLS-1$
buf.append(typeArgBaseName).append(i + 1);
}
}
buf.append('>');
return buf.toString();
}
}
return name;
}
示例4: addSimilarTypeProposals
import org.eclipse.jdt.core.dom.Name; //导入方法依赖的package包/类
private static void addSimilarTypeProposals(int kind, ICompilationUnit cu, Name node, int relevance,
Collection<CUCorrectionProposal> proposals) throws CoreException {
SimilarElement[] elements= SimilarElementsRequestor.findSimilarElement(cu, node, kind);
// try to resolve type in context -> highest severity
String resolvedTypeName= null;
ITypeBinding binding= ASTResolving.guessBindingForTypeReference(node);
if (binding != null) {
ITypeBinding simpleBinding= binding;
if (simpleBinding.isArray()) {
simpleBinding= simpleBinding.getElementType();
}
simpleBinding= simpleBinding.getTypeDeclaration();
if (!simpleBinding.isRecovered()) {
resolvedTypeName= simpleBinding.getQualifiedName();
CUCorrectionProposal proposal= createTypeRefChangeProposal(cu, resolvedTypeName, node, relevance + 2, elements.length);
proposals.add(proposal);
if (proposal instanceof AddImportCorrectionProposal) {
proposal.setRelevance(relevance + elements.length + 2);
}
if (binding.isParameterizedType()
&& (node.getParent() instanceof SimpleType || node.getParent() instanceof NameQualifiedType)
&& !(node.getParent().getParent() instanceof Type)) {
proposals.add(createTypeRefChangeFullProposal(cu, binding, node, relevance + 5));
}
}
} else {
ASTNode normalizedNode= ASTNodes.getNormalizedNode(node);
if (!(normalizedNode.getParent() instanceof Type) && node.getParent() != normalizedNode) {
ITypeBinding normBinding= ASTResolving.guessBindingForTypeReference(normalizedNode);
if (normBinding != null && !normBinding.isRecovered()) {
proposals.add(createTypeRefChangeFullProposal(cu, normBinding, normalizedNode, relevance + 5));
}
}
}
// add all similar elements
for (int i= 0; i < elements.length; i++) {
SimilarElement elem= elements[i];
if ((elem.getKind() & SimilarElementsRequestor.ALL_TYPES) != 0) {
String fullName= elem.getName();
if (!fullName.equals(resolvedTypeName)) {
proposals.add(createTypeRefChangeProposal(cu, fullName, node, relevance, elements.length));
}
}
}
}
示例5: getQualifiedReference
import org.eclipse.jdt.core.dom.Name; //导入方法依赖的package包/类
private static Expression getQualifiedReference(Name fieldName) {
if (doesParentQualify(fieldName)) return (Expression) fieldName.getParent();
return fieldName;
}
示例6: addSimilarTypeProposals
import org.eclipse.jdt.core.dom.Name; //导入方法依赖的package包/类
private static void addSimilarTypeProposals(
int kind, ICompilationUnit cu, Name node, int relevance, Collection<ICommandAccess> proposals)
throws CoreException {
SimilarElement[] elements = SimilarElementsRequestor.findSimilarElement(cu, node, kind);
// try to resolve type in context -> highest severity
String resolvedTypeName = null;
ITypeBinding binding = ASTResolving.guessBindingForTypeReference(node);
if (binding != null) {
ITypeBinding simpleBinding = binding;
if (simpleBinding.isArray()) {
simpleBinding = simpleBinding.getElementType();
}
simpleBinding = simpleBinding.getTypeDeclaration();
if (!simpleBinding.isRecovered()) {
resolvedTypeName = simpleBinding.getQualifiedName();
CUCorrectionProposal proposal =
createTypeRefChangeProposal(cu, resolvedTypeName, node, relevance + 2, elements.length);
proposals.add(proposal);
if (proposal instanceof AddImportCorrectionProposal)
proposal.setRelevance(relevance + elements.length + 2);
if (binding.isParameterizedType()
&& (node.getParent() instanceof SimpleType
|| node.getParent() instanceof NameQualifiedType)
&& !(node.getParent().getParent() instanceof Type)) {
proposals.add(createTypeRefChangeFullProposal(cu, binding, node, relevance + 5));
}
}
} else {
ASTNode normalizedNode = ASTNodes.getNormalizedNode(node);
if (!(normalizedNode.getParent() instanceof Type) && node.getParent() != normalizedNode) {
ITypeBinding normBinding = ASTResolving.guessBindingForTypeReference(normalizedNode);
if (normBinding != null && !normBinding.isRecovered()) {
proposals.add(
createTypeRefChangeFullProposal(cu, normBinding, normalizedNode, relevance + 5));
}
}
}
// add all similar elements
for (int i = 0; i < elements.length; i++) {
SimilarElement elem = elements[i];
if ((elem.getKind() & SimilarElementsRequestor.ALL_TYPES) != 0) {
String fullName = elem.getName();
if (!fullName.equals(resolvedTypeName)) {
proposals.add(
createTypeRefChangeProposal(cu, fullName, node, relevance, elements.length));
}
}
}
}