本文整理汇总了Java中org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getQualifierGuess方法的典型用法代码示例。如果您正苦于以下问题:Java ASTResolving.getQualifierGuess方法的具体用法?Java ASTResolving.getQualifierGuess怎么用?Java ASTResolving.getQualifierGuess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.ui.text.correction.ASTResolving
的用法示例。
在下文中一共展示了ASTResolving.getQualifierGuess方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateVariableType
import org.eclipse.jdt.internal.ui.text.correction.ASTResolving; //导入方法依赖的package包/类
private Type evaluateVariableType(
AST ast,
ImportRewrite imports,
ImportRewriteContext importRewriteContext,
IBinding targetContext) {
if (fOriginalNode.getParent() instanceof MethodInvocation) {
MethodInvocation parent = (MethodInvocation) fOriginalNode.getParent();
if (parent.getExpression() == fOriginalNode) {
// _x_.foo() -> guess qualifier type by looking for a type with method 'foo'
ITypeBinding[] bindings =
ASTResolving.getQualifierGuess(
fOriginalNode.getRoot(),
parent.getName().getIdentifier(),
parent.arguments(),
targetContext);
if (bindings.length > 0) {
for (int i = 0; i < bindings.length; i++) {
addLinkedPositionProposal(KEY_TYPE, bindings[i]);
}
return imports.addImport(bindings[0], ast, importRewriteContext);
}
}
}
ITypeBinding binding = ASTResolving.guessBindingForReference(fOriginalNode);
if (binding != null) {
if (binding.isWildcardType()) {
binding = ASTResolving.normalizeWildcardType(binding, isVariableAssigned(), ast);
if (binding == null) {
// only null binding applies
binding = ast.resolveWellKnownType("java.lang.Object"); // $NON-NLS-1$
}
}
if (isVariableAssigned()) {
ITypeBinding[] typeProposals = ASTResolving.getRelaxingTypes(ast, binding);
for (int i = 0; i < typeProposals.length; i++) {
addLinkedPositionProposal(KEY_TYPE, typeProposals[i]);
}
}
return imports.addImport(binding, ast, importRewriteContext);
}
// no binding, find type AST node instead -> ABC a= x-> use 'ABC' as is
Type type = ASTResolving.guessTypeForReference(ast, fOriginalNode);
if (type != null) {
return type;
}
if (fVariableKind == CONST_FIELD) {
return ast.newSimpleType(ast.newSimpleName("String")); // $NON-NLS-1$
}
return ast.newSimpleType(ast.newSimpleName("Object")); // $NON-NLS-1$
}
示例2: getNewCastTypeNode
import org.eclipse.jdt.internal.ui.text.correction.ASTResolving; //导入方法依赖的package包/类
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
AST ast= rewrite.getAST();
ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);
if (fCastType != null) {
return importRewrite.addImport(fCastType, ast,context);
}
ASTNode node= fNodeToCast;
ASTNode parent= node.getParent();
if (parent instanceof CastExpression) {
node= parent;
parent= parent.getParent();
}
while (parent instanceof ParenthesizedExpression) {
node= parent;
parent= parent.getParent();
}
if (parent instanceof MethodInvocation) {
MethodInvocation invocation= (MethodInvocation) node.getParent();
if (invocation.getExpression() == node) {
IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node);
ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext);
if (bindings.length > 0) {
ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());
Type newTypeNode= importRewrite.addImport(first, ast, context);
addLinkedPosition(rewrite.track(newTypeNode), true, "casttype"); //$NON-NLS-1$
for (int i= 0; i < bindings.length; i++) {
addLinkedPositionProposal("casttype", bindings[i]); //$NON-NLS-1$
}
return newTypeNode;
}
}
}
Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
addLinkedPosition(rewrite.track(newCastType), true, "casttype"); //$NON-NLS-1$
return newCastType;
}
示例3: getNewCastTypeNode
import org.eclipse.jdt.internal.ui.text.correction.ASTResolving; //导入方法依赖的package包/类
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
AST ast = rewrite.getAST();
ImportRewriteContext context =
new ContextSensitiveImportRewriteContext(
(CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);
if (fCastType != null) {
return importRewrite.addImport(fCastType, ast, context);
}
ASTNode node = fNodeToCast;
ASTNode parent = node.getParent();
if (parent instanceof CastExpression) {
node = parent;
parent = parent.getParent();
}
while (parent instanceof ParenthesizedExpression) {
node = parent;
parent = parent.getParent();
}
if (parent instanceof MethodInvocation) {
MethodInvocation invocation = (MethodInvocation) node.getParent();
if (invocation.getExpression() == node) {
IBinding targetContext = ASTResolving.getParentMethodOrTypeBinding(node);
ITypeBinding[] bindings =
ASTResolving.getQualifierGuess(
node.getRoot(),
invocation.getName().getIdentifier(),
invocation.arguments(),
targetContext);
if (bindings.length > 0) {
ITypeBinding first = getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());
Type newTypeNode = importRewrite.addImport(first, ast, context);
addLinkedPosition(rewrite.track(newTypeNode), true, "casttype"); // $NON-NLS-1$
for (int i = 0; i < bindings.length; i++) {
addLinkedPositionProposal("casttype", bindings[i]); // $NON-NLS-1$
}
return newTypeNode;
}
}
}
Type newCastType = ast.newSimpleType(ast.newSimpleName("Object")); // $NON-NLS-1$
addLinkedPosition(rewrite.track(newCastType), true, "casttype"); // $NON-NLS-1$
return newCastType;
}
示例4: evaluateVariableType
import org.eclipse.jdt.internal.ui.text.correction.ASTResolving; //导入方法依赖的package包/类
private Type evaluateVariableType(AST ast, ImportRewrite imports, ImportRewriteContext importRewriteContext, IBinding targetContext) {
if (fOriginalNode.getParent() instanceof MethodInvocation) {
MethodInvocation parent= (MethodInvocation) fOriginalNode.getParent();
if (parent.getExpression() == fOriginalNode) {
// _x_.foo() -> guess qualifier type by looking for a type with method 'foo'
ITypeBinding[] bindings= ASTResolving.getQualifierGuess(fOriginalNode.getRoot(), parent.getName().getIdentifier(), parent.arguments(), targetContext);
if (bindings.length > 0) {
for (int i= 0; i < bindings.length; i++) {
addLinkedPositionProposal(KEY_TYPE, bindings[i]);
}
return imports.addImport(bindings[0], ast, importRewriteContext);
}
}
}
ITypeBinding binding= ASTResolving.guessBindingForReference(fOriginalNode);
if (binding != null) {
if (binding.isWildcardType()) {
binding= ASTResolving.normalizeWildcardType(binding, isVariableAssigned(), ast);
if (binding == null) {
// only null binding applies
binding= ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
}
}
if (isVariableAssigned()) {
ITypeBinding[] typeProposals= ASTResolving.getRelaxingTypes(ast, binding);
for (int i= 0; i < typeProposals.length; i++) {
addLinkedPositionProposal(KEY_TYPE, typeProposals[i]);
}
}
return imports.addImport(binding, ast, importRewriteContext);
}
// no binding, find type AST node instead -> ABC a= x-> use 'ABC' as is
Type type= ASTResolving.guessTypeForReference(ast, fOriginalNode);
if (type != null) {
return type;
}
if (fVariableKind == CONST_FIELD) {
return ast.newSimpleType(ast.newSimpleName("String")); //$NON-NLS-1$
}
return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:44,代码来源:NewVariableCorrectionProposal.java