本文整理汇总了Java中org.eclipse.jdt.core.dom.rewrite.ImportRewrite.addStaticImport方法的典型用法代码示例。如果您正苦于以下问题:Java ImportRewrite.addStaticImport方法的具体用法?Java ImportRewrite.addStaticImport怎么用?Java ImportRewrite.addStaticImport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.rewrite.ImportRewrite
的用法示例。
在下文中一共展示了ImportRewrite.addStaticImport方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
}
}
示例2: addStaticImport
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
private void addStaticImport(
ICompilationUnit movedUnit, IImportDeclaration importDecl, ImportRewrite rewrite) {
String old = importDecl.getElementName();
int oldPackLength = movedUnit.getParent().getElementName().length();
StringBuffer result = new StringBuffer(fDestination.getElementName());
if (oldPackLength == 0) // move FROM default package
result.append('.').append(old);
else if (result.length() == 0) // move TO default package
result.append(old.substring(oldPackLength + 1)); // cut "."
else result.append(old.substring(oldPackLength));
int index = result.lastIndexOf("."); // $NON-NLS-1$
if (index > 0 && index < result.length() - 1)
rewrite.addStaticImport(
result.substring(0, index), result.substring(index + 1, result.length()), true);
}
示例3: addStaticImports
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
private void addStaticImports(List<SimpleName> staticReferences, ImportRewrite importsStructure) {
for (int i = 0; i < staticReferences.size(); i++) {
Name name = staticReferences.get(i);
IBinding binding = name.resolveBinding();
if (binding != null) { // paranoia check
importsStructure.addStaticImport(binding);
}
}
}
示例4: updateNode
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
@Override
public void updateNode() throws JavaModelException {
ImportRewrite importRewrite = fCuRewrite.getImportRewrite();
QualifiedName name = (QualifiedName) fImportDecl.getName();
// will be removed by importRemover if not used elsewhere ...
// importRewrite.removeStaticImport(name.getFullyQualifiedName());
importRewrite.addStaticImport(
name.getQualifier().getFullyQualifiedName(), fMethodName, false);
}
示例5: rewriteImports
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
public void rewriteImports(TextChangeManager changeManager, IProgressMonitor pm)
throws CoreException {
for (Iterator<Entry<ICompilationUnit, ImportChange>> iter =
fImportChanges.entrySet().iterator();
iter.hasNext(); ) {
Entry<ICompilationUnit, ImportChange> entry = iter.next();
ICompilationUnit cu = entry.getKey();
ImportChange importChange = entry.getValue();
ImportRewrite importRewrite = StubUtility.createImportRewrite(cu, true);
importRewrite.setFilterImplicitImports(false);
for (Iterator<String> iterator = importChange.fStaticToRemove.iterator();
iterator.hasNext(); ) {
importRewrite.removeStaticImport(iterator.next());
}
for (Iterator<String> iterator = importChange.fToRemove.iterator(); iterator.hasNext(); ) {
importRewrite.removeImport(iterator.next());
}
for (Iterator<String[]> iterator = importChange.fStaticToAdd.iterator();
iterator.hasNext(); ) {
String[] toAdd = iterator.next();
importRewrite.addStaticImport(toAdd[0], toAdd[1], true);
}
for (Iterator<String> iterator = importChange.fToAdd.iterator(); iterator.hasNext(); ) {
importRewrite.addImport(iterator.next());
}
if (importRewrite.hasRecordedChanges()) {
TextEdit importEdit = importRewrite.rewriteImports(pm);
String name = RefactoringCoreMessages.RenamePackageRefactoring_update_imports;
try {
TextChangeCompatibility.addTextEdit(changeManager.get(cu), name, importEdit);
} catch (MalformedTreeException e) {
JavaPlugin.logErrorMessage(
"MalformedTreeException while processing cu " + cu); // $NON-NLS-1$
throw e;
}
}
}
}
示例6: updateStaticReferences
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
private void updateStaticReferences(ASTRewrite rewriter, CallContext context) {
ImportRewrite importer = context.importer;
for (Iterator<SimpleName> iter = fAnalyzer.getStaticsToImport().iterator(); iter.hasNext(); ) {
Name element = iter.next();
IBinding binding = element.resolveBinding();
if (binding != null) {
String s = importer.addStaticImport(binding);
if (!ASTNodes.asString(element).equals(s)) {
rewriter.replace(element, rewriter.createStringPlaceholder(s, ASTNode.SIMPLE_NAME), null);
}
}
}
}
示例7: addStaticImportFavoriteProposals
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
private static void addStaticImportFavoriteProposals(IInvocationContext context, SimpleName node, boolean isMethod,
Collection<CUCorrectionProposal> proposals) throws JavaModelException {
IJavaProject project= context.getCompilationUnit().getJavaProject();
if (JavaModelUtil.is50OrHigher(project)) {
String pref = PreferenceManager.getPrefs(context.getCompilationUnit().getResource())
.getFavoriteStaticMembers();
String[] favourites= pref.split(";"); //$NON-NLS-1$
if (favourites.length == 0) {
return;
}
CompilationUnit root= context.getASTRoot();
AST ast= root.getAST();
String name= node.getIdentifier();
String[] staticImports= SimilarElementsRequestor.getStaticImportFavorites(context.getCompilationUnit(), name, isMethod, favourites);
for (int i= 0; i < staticImports.length; i++) {
String curr= staticImports[i];
ImportRewrite importRewrite= StubUtility.createImportRewrite(root, true);
ASTRewrite astRewrite= ASTRewrite.create(ast);
String label;
String qualifiedTypeName= Signature.getQualifier(curr);
String elementLabel= BasicElementLabels.getJavaElementName(JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
String res= importRewrite.addStaticImport(qualifiedTypeName, name, isMethod, new ContextSensitiveImportRewriteContext(root, node.getStartPosition(), importRewrite));
int dot= res.lastIndexOf('.');
if (dot != -1) {
String usedTypeName= importRewrite.addImport(qualifiedTypeName);
Name newName= ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
astRewrite.replace(node, newName, null);
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_change_to_static_import_description, elementLabel);
} else {
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description, elementLabel);
}
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label,
context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_STATIC_IMPORT);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}
示例8: addStaticImportFavoriteProposals
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; //导入方法依赖的package包/类
private static void addStaticImportFavoriteProposals(
IInvocationContext context,
SimpleName node,
boolean isMethod,
Collection<ICommandAccess> proposals)
throws JavaModelException {
IJavaProject project = context.getCompilationUnit().getJavaProject();
if (JavaModelUtil.is50OrHigher(project)) {
String pref =
PreferenceConstants.getPreference(
PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, project);
String[] favourites = pref.split(";"); // $NON-NLS-1$
if (favourites.length == 0) {
return;
}
CompilationUnit root = context.getASTRoot();
AST ast = root.getAST();
String name = node.getIdentifier();
String[] staticImports =
SimilarElementsRequestor.getStaticImportFavorites(
context.getCompilationUnit(), name, isMethod, favourites);
for (int i = 0; i < staticImports.length; i++) {
String curr = staticImports[i];
ImportRewrite importRewrite = StubUtility.createImportRewrite(root, true);
ASTRewrite astRewrite = ASTRewrite.create(ast);
String label;
String qualifiedTypeName = Signature.getQualifier(curr);
String elementLabel =
BasicElementLabels.getJavaElementName(
JavaModelUtil.concatenateName(Signature.getSimpleName(qualifiedTypeName), name));
String res =
importRewrite.addStaticImport(
qualifiedTypeName,
name,
isMethod,
new ContextSensitiveImportRewriteContext(
root, node.getStartPosition(), importRewrite));
int dot = res.lastIndexOf('.');
if (dot != -1) {
String usedTypeName = importRewrite.addImport(qualifiedTypeName);
Name newName = ast.newQualifiedName(ast.newName(usedTypeName), ast.newSimpleName(name));
astRewrite.replace(node, newName, null);
label =
Messages.format(
CorrectionMessages
.UnresolvedElementsSubProcessor_change_to_static_import_description,
elementLabel);
} else {
label =
Messages.format(
CorrectionMessages.UnresolvedElementsSubProcessor_add_static_import_description,
elementLabel);
}
Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
astRewrite,
IProposalRelevance.ADD_STATIC_IMPORT,
image);
proposal.setImportRewrite(importRewrite);
proposals.add(proposal);
}
}
}