当前位置: 首页>>代码示例>>Java>>正文


Java ImportRewrite类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.rewrite.ImportRewrite的典型用法代码示例。如果您正苦于以下问题:Java ImportRewrite类的具体用法?Java ImportRewrite怎么用?Java ImportRewrite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ImportRewrite类属于org.eclipse.jdt.core.dom.rewrite包,在下文中一共展示了ImportRewrite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNewCastTypeNode

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的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; //导入依赖的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: getImportStaticConstructsProposal

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的package包/类
private IJavaCompletionProposal[] getImportStaticConstructsProposal(
    IInvocationContext context) {
  final ICompilationUnit unit = context.getCompilationUnit();
  final IJavaProject project = unit.getJavaProject();
  final ImportRewrite rewrite = getImportRewrite(context.getASTRoot(),
      "static apgas.Constructs.*");
  final ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
  proposals.add(new ConstructsImportProposal(project, rewrite));

  final IJavaCompletionProposal[] propArr = new IJavaCompletionProposal[proposals
      .size()];
  for (int i = 0; i < proposals.size(); i++) {
    propArr[i] = proposals.get(i);
  }
  return propArr;
}
 
开发者ID:x10-lang,项目名称:apgas,代码行数:17,代码来源:APGASQuickfixProcessor.java

示例4: getAddAPGASToBuildPathProposals

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的package包/类
private IJavaCompletionProposal[] getAddAPGASToBuildPathProposals(
    IInvocationContext context) {
  final ICompilationUnit unit = context.getCompilationUnit();
  final IJavaProject project = unit.getJavaProject();
  final String name = "static apgas.Constructs.*";
  final ClasspathFixProposal[] fixProposals = ClasspathFixProcessor
      .getContributedFixImportProposals(project, name, null);

  final List<ImportRewrite> importRewrites = new ArrayList<ImportRewrite>();
  importRewrites.add(getImportRewrite(context.getASTRoot(), name));
  importRewrites.add(getImportRewrite(context.getASTRoot(), "apgas.*"));

  final ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
  for (final ClasspathFixProposal fixProposal : fixProposals) {
    proposals.add(new APGASClasspathFixCorrelationProposal(project,
        fixProposal, importRewrites));
  }

  final IJavaCompletionProposal[] propArr = new IJavaCompletionProposal[proposals
      .size()];
  for (int i = 0; i < proposals.size(); i++) {
    propArr[i] = proposals.get(i);
  }
  return propArr;
}
 
开发者ID:x10-lang,项目名称:apgas,代码行数:26,代码来源:APGASQuickfixProcessor.java

示例5: updateReplacementString

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的package包/类
/**
 * @param document
 * @param offset
 * @param importRewrite
 * @param completionSnippetsSupported
 * @return
 * @throws CoreException
 * @throws BadLocationException
 */
public String updateReplacementString(IDocument document, int offset, ImportRewrite importRewrite, boolean completionSnippetsSupported) throws CoreException, BadLocationException {
	int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic);

	String stub;
	if (fIsGetter) {
		String getterName= GetterSetterUtil.getGetterName(fField, null);
		stub = GetterSetterUtil.getGetterStub(fField, getterName, true, flags);
	} else {
		String setterName= GetterSetterUtil.getSetterName(fField, null);
		stub = GetterSetterUtil.getSetterStub(fField, setterName, true, flags);
	}

	// use the code formatter
	String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
	String replacement = CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, 0, lineDelim, fField.getJavaProject());

	if (replacement.endsWith(lineDelim)) {
		replacement = replacement.substring(0, replacement.length() - lineDelim.length());
	}

	return replacement;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:32,代码来源:GetterSetterCompletionProposal.java

示例6: newType

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的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

示例7: newReturnType

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的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

示例8: newCreationType

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的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

示例9: addOverrideAnnotation

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的package包/类
/**
 * Adds <code>@Override</code> annotation to <code>methodDecl</code> if not already present and
 * if requested by code style settings or compiler errors/warnings settings.
 *
 * @param settings the code generation style settings, may be <code>null</code>
 * @param project the Java project used to access the compiler settings
 * @param rewrite the ASTRewrite
 * @param imports the ImportRewrite
 * @param methodDecl the method declaration to add the annotation to
 * @param isDeclaringTypeInterface <code>true</code> if the type declaring the method overridden
 *            by <code>methodDecl</code> is an interface
 * @param group the text edit group, may be <code>null</code>
 */
public static void addOverrideAnnotation(CodeGenerationSettings settings, IJavaProject project, ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration methodDecl,
		boolean isDeclaringTypeInterface, TextEditGroup group) {
	if (!JavaModelUtil.is50OrHigher(project)) {
		return;
	}
	if (isDeclaringTypeInterface) {
		String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
		if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
		{
			return; // not allowed in 1.5
		}
		if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
		{
			return; // user doesn't want to use 1.6 style
		}
	}
	if ((settings != null && settings.overrideAnnotation) || !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true))) {
		createOverrideAnnotation(rewrite, imports, methodDecl, group);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:34,代码来源:StubUtility2.java

示例10: createTypeParameters

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的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

示例11: TypeReferenceProcessor

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的package包/类
public TypeReferenceProcessor(Set<String> oldSingleImports, Set<String> oldDemandImports, CompilationUnit root, ImportRewrite impStructure, boolean ignoreLowerCaseNames, UnresolvableImportMatcher unresolvableImportMatcher) {
	fOldSingleImports= oldSingleImports;
	fOldDemandImports= oldDemandImports;
	fImpStructure= impStructure;
	fDoIgnoreLowerCaseNames= ignoreLowerCaseNames;
	fUnresolvableImportMatcher= unresolvableImportMatcher;

	ICompilationUnit cu= impStructure.getCompilationUnit();

	fImplicitImports= new HashSet<>(3);
	fImplicitImports.add(""); //$NON-NLS-1$
	fImplicitImports.add("java.lang"); //$NON-NLS-1$
	fImplicitImports.add(cu.getParent().getElementName());

	fAnalyzer= new ScopeAnalyzer(root);

	fCurrPackage= (IPackageFragment) cu.getParent();

	fAllowDefaultPackageImports= cu.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true).equals(JavaCore.VERSION_1_3);

	fImportsAdded= new HashSet<>();
	fUnresolvedTypes= new HashMap<>();
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:OrganizeImportsOperation.java

示例12: addStaticImports

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的package包/类
private void addStaticImports(
		Collection<SimpleName> staticReferences,
		ImportRewrite importRewrite,
		UnresolvableImportMatcher unresolvableImportMatcher) {
	for (SimpleName name : staticReferences) {
		IBinding binding= name.resolveBinding();
		if (binding != null) {
			importRewrite.addStaticImport(binding);
		} else {
			// This could be an unresolvable reference to a static member.
			String identifier= name.getIdentifier();
			Set<String> unresolvableImports= unresolvableImportMatcher.matchStaticImports(identifier);
			for (String unresolvableImport : unresolvableImports) {
				int lastDotIndex= unresolvableImport.lastIndexOf('.');
				// It's OK to skip invalid imports.
				if (lastDotIndex != -1) {
					String declaringTypeName= unresolvableImport.substring(0, lastDotIndex);
					String simpleName= unresolvableImport.substring(lastDotIndex + 1);
					// Whether name refers to a field or to a method is unknown.
					boolean isField= false;
					importRewrite.addStaticImport(declaringTypeName, simpleName, isField, UNRESOLVABLE_IMPORT_CONTEXT);
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:OrganizeImportsOperation.java

示例13: getImportRewrite

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的package包/类
public ImportRewrite getImportRewrite() {
	if (fImportRewrite == null) {
		// lazily initialized to avoid lengthy processing in checkInitialConditions(..)
		try {
			/* If bindings are to be resolved, then create the AST, so that
			 * ImportRewrite#setUseContextToFilterImplicitImports(boolean) will be set to true
			 * and ContextSensitiveImportRewriteContext etc. can be used. */
			if (fRoot == null && ! fResolveBindings) {
				fImportRewrite= StubUtility.createImportRewrite(fCu, true);
			} else {
				fImportRewrite= StubUtility.createImportRewrite(getRoot(), true);
			}
		} catch (CoreException e) {
			JavaLanguageServerPlugin.log(e);
			throw new IllegalStateException(e.getMessage()); // like ASTParser#createAST(..) does
		}
	}
	return fImportRewrite;

}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:CompilationUnitRewrite.java

示例14: getRewrite

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的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

示例15: evaluateVariableType

import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入依赖的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


注:本文中的org.eclipse.jdt.core.dom.rewrite.ImportRewrite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。