本文整理汇总了Java中org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext类的典型用法代码示例。如果您正苦于以下问题:Java ImportRewriteContext类的具体用法?Java ImportRewriteContext怎么用?Java ImportRewriteContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImportRewriteContext类属于org.eclipse.jdt.core.dom.rewrite.ImportRewrite包,在下文中一共展示了ImportRewriteContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:CastCorrectionProposal.java
示例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);
}
}
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:StubUtility2.java
示例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$
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:ASTNodeFactory.java
示例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$
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:30,代码来源:ASTNodeFactory.java
示例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);
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodeFactory.java
示例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);
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:StubUtility2.java
示例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);
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:SelfEncapsulateFieldProposal.java
示例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;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:ImplementInterfaceProposal.java
示例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$
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:35,代码来源:NewVariableCorrectionProposal.java
示例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;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:NewAnnotationMemberProposal.java
示例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);
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:NewMethodCorrectionProposal.java
示例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$
}
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:ASTNodeFactory.java
示例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$
}
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:ASTNodeFactory.java
示例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;
}
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:SourceProvider.java
示例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();
}
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:MissingAnnotationAttributesProposal.java
示例16: getRewrite
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
@Override
protected ASTRewrite getRewrite() throws CoreException {
AST ast = fTypeNode.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
createImportRewrite((CompilationUnit) fTypeNode.getRoot());
CodeGenerationSettings settings =
JavaPreferencesSettings.getCodeGenerationSettings(getCompilationUnit().getJavaProject());
if (!settings.createComments) {
settings = null;
}
ImportRewriteContext importRewriteContext =
new ContextSensitiveImportRewriteContext(fTypeNode, getImportRewrite());
MethodDeclaration newMethodDecl =
createNewMethodDeclaration(ast, fSuperConstructor, rewrite, importRewriteContext, settings);
rewrite
.getListRewrite(fTypeNode, TypeDeclaration.BODY_DECLARATIONS_PROPERTY)
.insertFirst(newMethodDecl, null);
addLinkedRanges(rewrite, newMethodDecl);
return rewrite;
}
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:ConstructorFromSuperclassProposal.java
示例17: doAddField
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
private ASTRewrite doAddField(CompilationUnit astRoot) {
SimpleName node = fOriginalNode;
boolean isInDifferentCU = false;
ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
isInDifferentCU = true;
}
ImportRewrite imports = createImportRewrite(astRoot);
ImportRewriteContext importRewriteContext =
new ContextSensitiveImportRewriteContext(
ASTResolving.findParentBodyDeclaration(node), imports);
if (newTypeDecl != null) {
AST ast = newTypeDecl.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(node.getIdentifier()));
Type type = evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding);
FieldDeclaration newDecl = ast.newFieldDeclaration(fragment);
newDecl.setType(type);
newDecl
.modifiers()
.addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));
if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
}
ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls =
ASTNodes.<BodyDeclaration>getChildListProperty(newTypeDecl, property);
int maxOffset = isInDifferentCU ? -1 : node.getStartPosition();
int insertIndex = findFieldInsertIndex(decls, newDecl, maxOffset);
ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, property);
listRewriter.insertAt(newDecl, insertIndex, null);
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
getLinkedProposalModel(), rewrite, newDecl.modifiers(), fSenderBinding.isInterface());
addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
if (!isInDifferentCU) {
addLinkedPosition(rewrite.track(node), true, KEY_NAME);
}
addLinkedPosition(rewrite.track(fragment.getName()), false, KEY_NAME);
if (fragment.getInitializer() != null) {
addLinkedPosition(rewrite.track(fragment.getInitializer()), false, KEY_INITIALIZER);
}
return rewrite;
}
return null;
}
开发者ID:eclipse,项目名称:che,代码行数:63,代码来源:NewVariableCorrectionProposal.java
示例18: 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$
}
addLinkedPosition(rewrite.track(newTypeNode), false, KEY_TYPE);
return newTypeNode;
}
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:NewAnnotationMemberProposal.java
示例19: rewrite
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
protected void rewrite(FieldAccess node, ITypeBinding type) {
Expression exp= node.getExpression();
if (exp == null) {
ImportRewriteContext context= new ContextSensitiveImportRewriteContext(node, fCuRewrite.getImportRewrite());
Type result= fCuRewrite.getImportRewrite().addImport(type, fCuRewrite.getAST(), context);
fCuRewrite.getImportRemover().registerAddedImport(type.getQualifiedName());
exp= ASTNodeFactory.newName(fCuRewrite.getAST(), ASTFlattener.asString(result));
fCuRewrite.getASTRewrite().set(node, FieldAccess.EXPRESSION_PROPERTY, exp, fCuRewrite.createGroupDescription(REFERENCE_UPDATE));
fNeedsImport= true;
} else if (exp instanceof Name) {
rewriteName((Name)exp, type);
} else {
rewriteExpression(node, exp, type);
}
fProcessed.add(node.getName());
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:MoveStaticMemberAnalyzer.java
示例20: createParameterClassAwareContext
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; //导入依赖的package包/类
ContextSensitiveImportRewriteContext createParameterClassAwareContext(final boolean asTopLevelClass, final CompilationUnitRewrite cuRewrite, int position) {
ContextSensitiveImportRewriteContext context= new ContextSensitiveImportRewriteContext(cuRewrite.getRoot(), position, cuRewrite.getImportRewrite()) {
@Override
public int findInContext(String qualifier, String name, int kind) {
String parameterClassName= getClassName();
if (kind == ImportRewriteContext.KIND_TYPE && parameterClassName.equals(name)) {
String parameterClassQualifier= asTopLevelClass ? getPackage() : getEnclosingType();
if (super.findInContext(qualifier, "", kind) == ImportRewriteContext.RES_NAME_FOUND) { //$NON-NLS-1$ // TODO: should be "*", not " "!
if (parameterClassQualifier.equals(qualifier)) {
return ImportRewriteContext.RES_NAME_FOUND;
} else {
return ImportRewriteContext.RES_NAME_CONFLICT;
}
}
}
return super.findInContext(qualifier, name, kind);
}
};
return context;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ParameterObjectFactory.java
注:本文中的org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论