本文整理汇总了Java中org.eclipse.jdt.core.dom.AST.resolveWellKnownType方法的典型用法代码示例。如果您正苦于以下问题:Java AST.resolveWellKnownType方法的具体用法?Java AST.resolveWellKnownType怎么用?Java AST.resolveWellKnownType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.AST
的用法示例。
在下文中一共展示了AST.resolveWellKnownType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeBinding
import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
public ITypeBinding getTypeBinding(AST ast) {
boolean couldBeObject= false;
for (int i= 0; i < fResult.size(); i++) {
ReturnStatement node= fResult.get(i);
Expression expr= node.getExpression();
if (expr != null) {
ITypeBinding binding= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
if (binding != null) {
return binding;
} else {
couldBeObject= true;
}
} else {
return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
}
if (couldBeObject) {
return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
}
return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
示例2: evaluateVariableType
import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
private Type evaluateVariableType(AST ast, ImportRewrite imports, ImportRewriteContext importRewriteContext, IBinding targetContext, TypeLocation location) {
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) {
return imports.addImport(bindings[0], ast, importRewriteContext, location);
}
}
}
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$
}
}
return imports.addImport(binding, ast, importRewriteContext, location);
}
// 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$
}
示例3: normalizeForDeclarationUse
import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
/**
* Normalizes the binding so that it can be used as a type inside a declaration (e.g. variable
* declaration, method return type, parameter type, ...).
* For null bindings, java.lang.Object is returned.
* For void bindings, <code>null</code> is returned.
*
* @param binding binding to normalize
* @param ast current AST
* @return the normalized type to be used in declarations, or <code>null</code>
*/
public static ITypeBinding normalizeForDeclarationUse(ITypeBinding binding, AST ast) {
if (binding.isNullType())
{
return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
}
if (binding.isPrimitive()) {
return binding;
}
binding= normalizeTypeBinding(binding);
if (binding == null) {
return binding;
}
if (binding.isArray()) {
return normalizeForDeclarationUse(binding.getComponentType(), ast).createArrayType(1);
}
if (!binding.isWildcardType()) {
return binding;
}
ITypeBinding bound= binding.getBound();
if (bound == null || !binding.isUpperbound()) {
ITypeBinding[] typeBounds= binding.getTypeBounds();
if (typeBounds.length > 0) {
return typeBounds[0];
} else {
return binding.getErasure();
}
} else {
return bound;
}
}
示例4: getBoxedTypeBinding
import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
/**
* Returns the boxed type binding according to JLS3 5.1.7, or the original binding if
* the given type is not a primitive type.
*
* @param type a type binding
* @param ast an AST to resolve the boxed type
* @return the boxed type, or the original type if no boxed type found
*/
public static ITypeBinding getBoxedTypeBinding(ITypeBinding type, AST ast) {
if (!type.isPrimitive()) {
return type;
}
String boxedTypeName= getBoxedTypeName(type.getName());
if (boxedTypeName == null) {
return type;
}
ITypeBinding boxed= ast.resolveWellKnownType(boxedTypeName);
if (boxed == null) {
return type;
}
return boxed;
}
示例5: getUnboxedTypeBinding
import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
/**
* Returns the unboxed type binding according to JLS3 5.1.7, or the original binding if
* the given type is not a boxed type.
*
* @param type a type binding
* @param ast an AST to resolve the unboxed type
* @return the unboxed type, or the original type if no unboxed type found
*/
public static ITypeBinding getUnboxedTypeBinding(ITypeBinding type, AST ast) {
if (!type.isClass()) {
return type;
}
String unboxedTypeName= getUnboxedTypeName(type.getQualifiedName());
if (unboxedTypeName == null) {
return type;
}
ITypeBinding unboxed= ast.resolveWellKnownType(unboxedTypeName);
if (unboxed == null) {
return type;
}
return unboxed;
}
示例6: initReturnType
import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
private void initReturnType(ImportRewrite rewriter) {
AST ast = fEnclosingBodyDeclaration.getAST();
fReturnType = null;
fReturnTypeBinding = null;
switch (fReturnKind) {
case ACCESS_TO_LOCAL:
VariableDeclaration declaration = ASTNodes.findVariableDeclaration(fReturnValue, fEnclosingBodyDeclaration);
fReturnType = ASTNodeFactory.newType(ast, declaration, rewriter, new ContextSensitiveImportRewriteContext(declaration, rewriter));
if (declaration.resolveBinding() != null) {
fReturnTypeBinding = declaration.resolveBinding().getType();
}
break;
case EXPRESSION:
Expression expression = (Expression) getFirstSelectedNode();
if (expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
fExpressionBinding = ((ClassInstanceCreation) expression).getType().resolveBinding();
} else {
fExpressionBinding = expression.resolveTypeBinding();
}
if (fExpressionBinding != null) {
if (fExpressionBinding.isNullType()) {
getStatus().addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_null_type, JavaStatusContext.create(fCUnit, expression));
} else {
ITypeBinding normalizedBinding = Bindings.normalizeForDeclarationUse(fExpressionBinding, ast);
if (normalizedBinding != null) {
ImportRewriteContext context = new ContextSensitiveImportRewriteContext(fEnclosingBodyDeclaration, rewriter);
fReturnType = rewriter.addImport(normalizedBinding, ast, context, TypeLocation.RETURN_TYPE);
fReturnTypeBinding = normalizedBinding;
}
}
} else {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
getStatus().addError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_determine_return_type, JavaStatusContext.create(fCUnit, expression));
}
break;
case RETURN_STATEMENT_VALUE:
LambdaExpression enclosingLambdaExpr = ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
if (enclosingLambdaExpr != null) {
fReturnType = ASTNodeFactory.newReturnType(enclosingLambdaExpr, ast, rewriter, null);
IMethodBinding methodBinding = enclosingLambdaExpr.resolveMethodBinding();
fReturnTypeBinding = methodBinding != null ? methodBinding.getReturnType() : null;
} else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
fReturnType = ((MethodDeclaration) fEnclosingBodyDeclaration).getReturnType2();
fReturnTypeBinding = fReturnType != null ? fReturnType.resolveBinding() : null;
}
break;
default:
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
if (fReturnType == null) {
fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
}
示例7: addMissingReturnTypeProposals
import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
public static void addMissingReturnTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
ICompilationUnit cu= context.getCompilationUnit();
CompilationUnit astRoot= context.getASTRoot();
ASTNode selectedNode= problem.getCoveringNode(astRoot);
if (selectedNode == null) {
return;
}
BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
if (decl instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration= (MethodDeclaration) decl;
ReturnStatementCollector eval= new ReturnStatementCollector();
decl.accept(eval);
AST ast= astRoot.getAST();
ITypeBinding typeBinding= eval.getTypeBinding(decl.getAST());
typeBinding= Bindings.normalizeTypeBinding(typeBinding);
if (typeBinding == null) {
typeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
if (typeBinding.isWildcardType()) {
typeBinding= ASTResolving.normalizeWildcardType(typeBinding, true, ast);
}
ASTRewrite rewrite= ASTRewrite.create(ast);
String label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_missingreturntype_description, BindingLabelProvider.getBindingLabel(typeBinding, BindingLabelProvider.DEFAULT_TEXTFLAGS));
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.MISSING_RETURN_TYPE);
ImportRewrite imports= proposal.createImportRewrite(astRoot);
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
Type type= imports.addImport(typeBinding, ast, importRewriteContext, TypeLocation.RETURN_TYPE);
rewrite.set(methodDeclaration, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null);
rewrite.set(methodDeclaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.FALSE, null);
Javadoc javadoc= methodDeclaration.getJavadoc();
if (javadoc != null && typeBinding != null) {
TagElement newTag= ast.newTagElement();
newTag.setTagName(TagElement.TAG_RETURN);
TextElement commentStart= ast.newTextElement();
newTag.fragments().add(commentStart);
JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$
}
String key= "return_type"; //$NON-NLS-1$
proposal.addLinkedPosition(rewrite.track(type), true, key);
if (typeBinding != null) {
ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, typeBinding);
for (int i= 0; i < bindings.length; i++) {
proposal.addLinkedPositionProposal(key, bindings[i]);
}
}
proposals.add(proposal);
// change to constructor
ASTNode parentType= ASTResolving.findParentType(decl);
if (parentType instanceof AbstractTypeDeclaration) {
boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
if (!isInterface) {
String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
ASTNode nameNode= methodDeclaration.getName();
label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName));
proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, IProposalRelevance.CHANGE_TO_CONSTRUCTOR));
}
}
}
}