本文整理汇总了Java中org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext类的典型用法代码示例。如果您正苦于以下问题:Java ImportRewriteContext类的具体用法?Java ImportRewriteContext怎么用?Java ImportRewriteContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImportRewriteContext类属于org.eclipse.jdt.core.dom.rewrite.ImportRewrite包,在下文中一共展示了ImportRewriteContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNewCastTypeNode
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的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, TypeLocation.CAST);
}
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, TypeLocation.CAST);
return newTypeNode;
}
}
}
Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
return newCastType;
}
示例2: createTypeParameters
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private static void createTypeParameters(
ImportRewrite imports,
ImportRewriteContext context,
AST ast,
IMethodBinding binding,
MethodDeclaration decl) {
ITypeBinding[] typeParams = binding.getTypeParameters();
List<TypeParameter> typeParameters = decl.typeParameters();
for (int i = 0; i < typeParams.length; i++) {
ITypeBinding curr = typeParams[i];
TypeParameter newTypeParam = ast.newTypeParameter();
newTypeParam.setName(ast.newSimpleName(curr.getName()));
ITypeBinding[] typeBounds = curr.getTypeBounds();
if (typeBounds.length != 1
|| !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) { // $NON-NLS-1$
List<Type> newTypeBounds = newTypeParam.typeBounds();
for (int k = 0; k < typeBounds.length; k++) {
newTypeBounds.add(imports.addImport(typeBounds[k], ast, context));
}
}
typeParameters.add(newTypeParam);
}
}
示例3: newType
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private static Type newType(LambdaExpression lambdaExpression, VariableDeclarationFragment declaration, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
IMethodBinding method= lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding[] parameterTypes= method.getParameterTypes();
int index= lambdaExpression.parameters().indexOf(declaration);
ITypeBinding typeBinding= parameterTypes[index];
if (importRewrite != null) {
return importRewrite.addImport(typeBinding, ast, context);
} else {
String qualifiedName= typeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
示例4: newReturnType
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
/**
* Returns the new type node representing the return type of <code>lambdaExpression</code>
* including the extra dimensions.
*
* @param lambdaExpression the lambda expression
* @param ast the AST to create the return type with
* @param importRewrite the import rewrite to use, or <code>null</code>
* @param context the import rewrite context, or <code>null</code>
* @return a new type node created with the given AST representing the return type of
* <code>lambdaExpression</code>
*
* @since 3.10
*/
public static Type newReturnType(LambdaExpression lambdaExpression, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
IMethodBinding method= lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding returnTypeBinding= method.getReturnType();
if (importRewrite != null) {
return importRewrite.addImport(returnTypeBinding, ast);
} else {
String qualifiedName= returnTypeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
示例5: newCreationType
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
/**
* Create a Type suitable as the creationType in a ClassInstanceCreation expression.
* @param ast The AST to create the nodes for.
* @param typeBinding binding representing the given class type
* @param importRewrite the import rewrite to use
* @param importContext the import context used to determine which (null) annotations to consider
* @return a Type suitable as the creationType in a ClassInstanceCreation expression.
*/
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
if (typeBinding.isParameterizedType()) {
Type baseType= newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
IAnnotationBinding[] typeAnnotations= importContext.removeRedundantTypeAnnotations(typeBinding.getTypeAnnotations(), TypeLocation.NEW, typeBinding);
for (IAnnotationBinding typeAnnotation : typeAnnotations) {
((AnnotatableType)baseType).annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
}
ParameterizedType parameterizedType= ast.newParameterizedType(baseType);
for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
typeArgument= StubUtility2.replaceWildcardsAndCaptures(typeArgument);
parameterizedType.typeArguments().add(importRewrite.addImport(typeArgument, ast, importContext, TypeLocation.TYPE_ARGUMENT));
}
return parameterizedType;
} else {
return importRewrite.addImport(typeBinding, ast, importContext, TypeLocation.NEW);
}
}
示例6: createTypeParameters
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) {
ITypeBinding[] typeParams= binding.getTypeParameters();
List<TypeParameter> typeParameters= decl.typeParameters();
for (int i= 0; i < typeParams.length; i++) {
ITypeBinding curr= typeParams[i];
TypeParameter newTypeParam= ast.newTypeParameter();
newTypeParam.setName(ast.newSimpleName(curr.getName()));
ITypeBinding[] typeBounds= curr.getTypeBounds();
if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$
List<Type> newTypeBounds= newTypeParam.typeBounds();
for (int k= 0; k < typeBounds.length; k++) {
newTypeBounds.add(imports.addImport(typeBounds[k], ast, context, TypeLocation.TYPE_BOUND));
}
}
typeParameters.add(newTypeParam);
}
}
示例7: addNewJavadoc
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private void addNewJavadoc(ASTRewrite rewrite, MethodDeclaration decl, ImportRewriteContext context) throws CoreException {
IType parentType = fField.getDeclaringType();
String typeName = Signature.toString(fField.getTypeSignature());
String accessorName = StubUtility.getBaseName(fField);
String lineDelim = "\n";
String comment = null;
String name = getFunctionName();
if (isGetter) {
comment = CodeGeneration.getGetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, accessorName, lineDelim);
} else {
String argname = getArgumentName();
comment = CodeGeneration.getSetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, argname, accessorName, lineDelim);
}
comment = comment.substring(0, comment.lastIndexOf(lineDelim));
if (comment != null) {
Javadoc javadoc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
decl.setJavadoc(javadoc);
}
}
示例8: getRewrite
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() throws CoreException {
ASTNode boundNode= fAstRoot.findDeclaringNode(fBinding);
ASTNode declNode= null;
CompilationUnit newRoot= fAstRoot;
if (boundNode != null) {
declNode= boundNode; // is same CU
} else {
newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
declNode= newRoot.findDeclaringNode(fBinding.getKey());
}
ImportRewrite imports= createImportRewrite(newRoot);
if (declNode instanceof TypeDeclaration) {
AST ast= declNode.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(declNode, imports);
Type newInterface= imports.addImport(fNewInterface, ast, importRewriteContext, TypeLocation.OTHER);
ListRewrite listRewrite= rewrite.getListRewrite(declNode, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY);
listRewrite.insertLast(newInterface, null);
return rewrite;
}
return null;
}
示例9: evaluateVariableType
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的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$
}
示例10: getNewType
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private Type getNewType(ASTRewrite rewrite) {
AST ast= rewrite.getAST();
Type newTypeNode= null;
ITypeBinding binding= null;
if (fInvocationNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) {
Expression value= ((MemberValuePair) fInvocationNode.getParent()).getValue();
binding= value.resolveTypeBinding();
} else if (fInvocationNode instanceof Expression) {
binding= ((Expression) fInvocationNode).resolveTypeBinding();
}
if (binding != null) {
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(fInvocationNode, getImportRewrite());
newTypeNode= getImportRewrite().addImport(binding, ast, importRewriteContext);
}
if (newTypeNode == null) {
newTypeNode= ast.newSimpleType(ast.newSimpleName("String")); //$NON-NLS-1$
}
return newTypeNode;
}
示例11: addNewParameters
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
@Override
protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params, ImportRewriteContext context) throws CoreException {
AST ast= rewrite.getAST();
List<Expression> arguments= fArguments;
for (int i= 0; i < arguments.size(); i++) {
Expression elem= arguments.get(i);
SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
// argument type
String argTypeKey= "arg_type_" + i; //$NON-NLS-1$
Type type= evaluateParameterType(ast, elem, argTypeKey, context);
param.setType(type);
// argument name
String argNameKey= "arg_name_" + i; //$NON-NLS-1$
String name= evaluateParameterName(takenNames, elem, type, argNameKey);
param.setName(ast.newSimpleName(name));
params.add(param);
}
}
示例12: newType
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private static Type newType(
LambdaExpression lambdaExpression,
VariableDeclarationFragment declaration,
AST ast,
ImportRewrite importRewrite,
ImportRewriteContext context) {
IMethodBinding method = lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding[] parameterTypes = method.getParameterTypes();
int index = lambdaExpression.parameters().indexOf(declaration);
ITypeBinding typeBinding = parameterTypes[index];
if (importRewrite != null) {
return importRewrite.addImport(typeBinding, ast, context);
} else {
String qualifiedName = typeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); // $NON-NLS-1$
}
示例13: newReturnType
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
/**
* Returns the new type node representing the return type of <code>lambdaExpression</code>
* including the extra dimensions.
*
* @param lambdaExpression the lambda expression
* @param ast the AST to create the return type with
* @param importRewrite the import rewrite to use, or <code>null</code>
* @param context the import rewrite context, or <code>null</code>
* @return a new type node created with the given AST representing the return type of <code>
* lambdaExpression</code>
* @since 3.10
*/
public static Type newReturnType(
LambdaExpression lambdaExpression,
AST ast,
ImportRewrite importRewrite,
ImportRewriteContext context) {
IMethodBinding method = lambdaExpression.resolveMethodBinding();
if (method != null) {
ITypeBinding returnTypeBinding = method.getReturnType();
if (importRewrite != null) {
return importRewrite.addImport(returnTypeBinding, ast);
} else {
String qualifiedName = returnTypeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
return newType(ast, qualifiedName);
}
}
}
// fall-back
return ast.newSimpleType(ast.newSimpleName("Object")); // $NON-NLS-1$
}
示例14: getReceiver
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private String getReceiver(
CallContext context, int modifiers, ImportRewriteContext importRewriteContext) {
String receiver = context.receiver;
ITypeBinding invocationType = ASTNodes.getEnclosingType(context.invocation);
ITypeBinding sourceType = fDeclaration.resolveBinding().getDeclaringClass();
if (!context.receiverIsStatic && Modifier.isStatic(modifiers)) {
if ("this".equals(receiver)
&& invocationType != null
&& Bindings.equals(invocationType, sourceType)) { // $NON-NLS-1$
receiver = null;
} else {
receiver = context.importer.addImport(sourceType, importRewriteContext);
}
}
return receiver;
}
示例15: newDefaultExpression
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private Expression newDefaultExpression(
AST ast, ITypeBinding type, ImportRewriteContext context) {
if (type.isPrimitive()) {
String name = type.getName();
if ("boolean".equals(name)) { // $NON-NLS-1$
return ast.newBooleanLiteral(false);
} else {
return ast.newNumberLiteral("0"); // $NON-NLS-1$
}
}
if (type == ast.resolveWellKnownType("java.lang.String")) { // $NON-NLS-1$
return ast.newStringLiteral();
}
if (type.isArray()) {
ArrayInitializer initializer = ast.newArrayInitializer();
initializer.expressions().add(newDefaultExpression(ast, type.getElementType(), context));
return initializer;
}
if (type.isAnnotation()) {
MarkerAnnotation annotation = ast.newMarkerAnnotation();
annotation.setTypeName(ast.newName(getImportRewrite().addImport(type, context)));
return annotation;
}
return ast.newNullLiteral();
}