1 11 12 package org.eclipse.jdt.core.dom.rewrite; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.NullProgressMonitor; 20 import org.eclipse.core.runtime.SubProgressMonitor; 21 import org.eclipse.jdt.core.Flags; 22 import org.eclipse.jdt.core.ICompilationUnit; 23 import org.eclipse.jdt.core.IImportDeclaration; 24 import org.eclipse.jdt.core.ITypeRoot; 25 import org.eclipse.jdt.core.JavaModelException; 26 import org.eclipse.jdt.core.Signature; 27 import org.eclipse.jdt.core.compiler.CharOperation; 28 import org.eclipse.jdt.core.dom.*; 29 import org.eclipse.jdt.internal.core.dom.rewrite.ImportRewriteAnalyzer; 30 import org.eclipse.jdt.internal.core.util.Messages; 31 import org.eclipse.text.edits.MultiTextEdit; 32 import org.eclipse.text.edits.TextEdit; 33 34 35 57 public final class ImportRewrite { 58 59 69 public static abstract class ImportRewriteContext { 70 71 74 public final static int RES_NAME_FOUND= 1; 75 76 79 public final static int RES_NAME_UNKNOWN= 2; 80 81 84 public final static int RES_NAME_CONFLICT= 3; 85 86 89 public final static int KIND_TYPE= 1; 90 91 94 public final static int KIND_STATIC_FIELD= 2; 95 96 99 public final static int KIND_STATIC_METHOD= 3; 100 101 112 public abstract int findInContext(String qualifier, String name, int kind); 113 } 114 115 private static final char STATIC_PREFIX= 's'; 116 private static final char NORMAL_PREFIX= 'n'; 117 118 private final ImportRewriteContext defaultContext; 119 120 private final ICompilationUnit compilationUnit; 121 private final CompilationUnit astRoot; 122 123 private final boolean restoreExistingImports; 124 private final List existingImports; 125 126 private String [] importOrder; 127 private int importOnDemandThreshold; 128 private int staticImportOnDemandThreshold; 129 130 private List addedImports; 131 private List removedImports; 132 133 private String [] createdImports; 134 private String [] createdStaticImports; 135 136 private boolean filterImplicitImports; 137 138 152 public static ImportRewrite create(ICompilationUnit cu, boolean restoreExistingImports) throws JavaModelException { 153 if (cu == null) { 154 throw new IllegalArgumentException ("Compilation unit must not be null"); } 156 List existingImport= null; 157 if (restoreExistingImports) { 158 existingImport= new ArrayList (); 159 IImportDeclaration[] imports= cu.getImports(); 160 for (int i= 0; i < imports.length; i++) { 161 IImportDeclaration curr= imports[i]; 162 char prefix= Flags.isStatic(curr.getFlags()) ? STATIC_PREFIX : NORMAL_PREFIX; 163 existingImport.add(prefix + curr.getElementName()); 164 } 165 } 166 return new ImportRewrite(cu, null, existingImport); 167 } 168 169 183 public static ImportRewrite create(CompilationUnit astRoot, boolean restoreExistingImports) { 184 if (astRoot == null) { 185 throw new IllegalArgumentException ("AST must not be null"); } 187 ITypeRoot typeRoot = astRoot.getTypeRoot(); 188 if (!(typeRoot instanceof ICompilationUnit)) { 189 throw new IllegalArgumentException ("AST must have been constructed from a Java element"); } 191 List existingImport= null; 192 if (restoreExistingImports) { 193 existingImport= new ArrayList (); 194 List imports= astRoot.imports(); 195 for (int i= 0; i < imports.size(); i++) { 196 ImportDeclaration curr= (ImportDeclaration) imports.get(i); 197 StringBuffer buf= new StringBuffer (); 198 buf.append(curr.isStatic() ? STATIC_PREFIX : NORMAL_PREFIX).append(curr.getName().getFullyQualifiedName()); 199 if (curr.isOnDemand()) { 200 if (buf.length() > 1) 201 buf.append('.'); 202 buf.append('*'); 203 } 204 existingImport.add(buf.toString()); 205 } 206 } 207 return new ImportRewrite((ICompilationUnit) typeRoot, astRoot, existingImport); 208 } 209 210 private ImportRewrite(ICompilationUnit cu, CompilationUnit astRoot, List existingImports) { 211 this.compilationUnit= cu; 212 this.astRoot= astRoot; if (existingImports != null) { 214 this.existingImports= existingImports; 215 this.restoreExistingImports= !existingImports.isEmpty(); 216 } else { 217 this.existingImports= new ArrayList (); 218 this.restoreExistingImports= false; 219 } 220 this.filterImplicitImports= true; 221 222 this.defaultContext= new ImportRewriteContext() { 223 public int findInContext(String qualifier, String name, int kind) { 224 return findInImports(qualifier, name, kind); 225 } 226 }; 227 this.addedImports= null; this.removedImports= null; this.createdImports= null; 230 this.createdStaticImports= null; 231 232 this.importOrder= CharOperation.NO_STRINGS; 233 this.importOnDemandThreshold= 99; 234 this.staticImportOnDemandThreshold= 99; 235 } 236 237 238 245 public void setImportOrder(String [] order) { 246 if (order == null) 247 throw new IllegalArgumentException ("Order must not be null"); this.importOrder= order; 249 } 250 251 261 public void setOnDemandImportThreshold(int threshold) { 262 if (threshold <= 0) 263 throw new IllegalArgumentException ("Threshold must be positive."); this.importOnDemandThreshold= threshold; 265 } 266 267 277 public void setStaticOnDemandImportThreshold(int threshold) { 278 if (threshold <= 0) 279 throw new IllegalArgumentException ("Threshold must be positive."); this.staticImportOnDemandThreshold= threshold; 281 } 282 283 287 public ICompilationUnit getCompilationUnit() { 288 return this.compilationUnit; 289 } 290 291 296 public ImportRewriteContext getDefaultImportRewriteContext() { 297 return this.defaultContext; 298 } 299 300 306 public void setFilterImplicitImports(boolean filterImplicitImports) { 307 this.filterImplicitImports= filterImplicitImports; 308 } 309 310 private static int compareImport(char prefix, String qualifier, String name, String curr) { 311 if (curr.charAt(0) != prefix || !curr.endsWith(name)) { 312 return ImportRewriteContext.RES_NAME_UNKNOWN; 313 } 314 315 curr= curr.substring(1); 317 if (curr.length() == name.length()) { 318 if (qualifier.length() == 0) { 319 return ImportRewriteContext.RES_NAME_FOUND; 320 } 321 return ImportRewriteContext.RES_NAME_CONFLICT; 322 } 323 325 int dotPos= curr.length() - name.length() - 1; 326 if (curr.charAt(dotPos) != '.') { 327 return ImportRewriteContext.RES_NAME_UNKNOWN; 328 } 329 if (qualifier.length() != dotPos || !curr.startsWith(qualifier)) { 330 return ImportRewriteContext.RES_NAME_CONFLICT; 331 } 332 return ImportRewriteContext.RES_NAME_FOUND; 333 } 334 335 338 final int findInImports(String qualifier, String name, int kind) { 339 boolean allowAmbiguity= (kind == ImportRewriteContext.KIND_STATIC_METHOD) || (name.length() == 1 && name.charAt(0) == '*'); 340 List imports= this.existingImports; 341 char prefix= (kind == ImportRewriteContext.KIND_TYPE) ? NORMAL_PREFIX : STATIC_PREFIX; 342 343 for (int i= imports.size() - 1; i >= 0 ; i--) { 344 String curr= (String ) imports.get(i); 345 int res= compareImport(prefix, qualifier, name, curr); 346 if (res != ImportRewriteContext.RES_NAME_UNKNOWN) { 347 if (!allowAmbiguity || res == ImportRewriteContext.RES_NAME_FOUND) { 348 return res; 349 } 350 } 351 } 352 return ImportRewriteContext.RES_NAME_UNKNOWN; 353 } 354 355 373 public Type addImportFromSignature(String typeSig, AST ast) { 374 return addImportFromSignature(typeSig, ast, this.defaultContext); 375 } 376 377 397 public Type addImportFromSignature(String typeSig, AST ast, ImportRewriteContext context) { 398 if (typeSig == null || typeSig.length() == 0) { 399 throw new IllegalArgumentException ("Invalid type signature: empty or null"); } 401 int sigKind= Signature.getTypeSignatureKind(typeSig); 402 switch (sigKind) { 403 case Signature.BASE_TYPE_SIGNATURE: 404 return ast.newPrimitiveType(PrimitiveType.toCode(Signature.toString(typeSig))); 405 case Signature.ARRAY_TYPE_SIGNATURE: 406 Type elementType= addImportFromSignature(Signature.getElementType(typeSig), ast, context); 407 return ast.newArrayType(elementType, Signature.getArrayCount(typeSig)); 408 case Signature.CLASS_TYPE_SIGNATURE: 409 String erasureSig= Signature.getTypeErasure(typeSig); 410 411 String erasureName= Signature.toString(erasureSig); 412 if (erasureSig.charAt(0) == Signature.C_RESOLVED) { 413 erasureName= internalAddImport(erasureName, context); 414 } 415 Type baseType= ast.newSimpleType(ast.newName(erasureName)); 416 String [] typeArguments= Signature.getTypeArguments(typeSig); 417 if (typeArguments.length > 0) { 418 ParameterizedType type= ast.newParameterizedType(baseType); 419 List argNodes= type.typeArguments(); 420 for (int i= 0; i < typeArguments.length; i++) { 421 String curr= typeArguments[i]; 422 if (containsNestedCapture(curr)) { argNodes.add(ast.newWildcardType()); 424 } else { 425 argNodes.add(addImportFromSignature(curr, ast, context)); 426 } 427 } 428 return type; 429 } 430 return baseType; 431 case Signature.TYPE_VARIABLE_SIGNATURE: 432 return ast.newSimpleType(ast.newSimpleName(Signature.toString(typeSig))); 433 case Signature.WILDCARD_TYPE_SIGNATURE: 434 WildcardType wildcardType= ast.newWildcardType(); 435 char ch= typeSig.charAt(0); 436 if (ch != Signature.C_STAR) { 437 Type bound= addImportFromSignature(typeSig.substring(1), ast, context); 438 wildcardType.setBound(bound, ch == Signature.C_EXTENDS); 439 } 440 return wildcardType; 441 case Signature.CAPTURE_TYPE_SIGNATURE: 442 return addImportFromSignature(typeSig.substring(1), ast, context); 443 default: 444 throw new IllegalArgumentException ("Unknown type signature kind: " + typeSig); } 446 } 447 448 449 450 467 public String addImport(ITypeBinding binding) { 468 return addImport(binding, this.defaultContext); 469 } 470 471 490 public String addImport(ITypeBinding binding, ImportRewriteContext context) { 491 if (binding.isPrimitive() || binding.isTypeVariable() || binding.isRecovered()) { 492 return binding.getName(); 493 } 494 495 ITypeBinding normalizedBinding= normalizeTypeBinding(binding); 496 if (normalizedBinding == null) { 497 return "invalid"; } 499 if (normalizedBinding.isWildcardType()) { 500 StringBuffer res= new StringBuffer ("?"); ITypeBinding bound= normalizedBinding.getBound(); 502 if (bound != null && !bound.isWildcardType() && !bound.isCapture()) { if (normalizedBinding.isUpperbound()) { 504 res.append(" extends "); } else { 506 res.append(" super "); } 508 res.append(addImport(bound, context)); 509 } 510 return res.toString(); 511 } 512 513 if (normalizedBinding.isArray()) { 514 StringBuffer res= new StringBuffer (addImport(normalizedBinding.getElementType(), context)); 515 for (int i= normalizedBinding.getDimensions(); i > 0; i--) { 516 res.append("[]"); } 518 return res.toString(); 519 } 520 521 String qualifiedName= getRawQualifiedName(normalizedBinding); 522 if (qualifiedName.length() > 0) { 523 String str= internalAddImport(qualifiedName, context); 524 525 ITypeBinding[] typeArguments= normalizedBinding.getTypeArguments(); 526 if (typeArguments.length > 0) { 527 StringBuffer res= new StringBuffer (str); 528 res.append('<'); 529 for (int i= 0; i < typeArguments.length; i++) { 530 if (i > 0) { 531 res.append(','); 532 } 533 ITypeBinding curr= typeArguments[i]; 534 if (containsNestedCapture(curr, false)) { res.append('?'); 536 } else { 537 res.append(addImport(curr, context)); 538 } 539 } 540 res.append('>'); 541 return res.toString(); 542 } 543 return str; 544 } 545 return getRawName(normalizedBinding); 546 } 547 548 private boolean containsNestedCapture(ITypeBinding binding, boolean isNested) { 549 if (binding == null || binding.isPrimitive() || binding.isTypeVariable()) { 550 return false; 551 } 552 if (binding.isCapture()) { 553 if (isNested) { 554 return true; 555 } 556 return containsNestedCapture(binding.getWildcard(), true); 557 } 558 if (binding.isWildcardType()) { 559 return containsNestedCapture(binding.getBound(), true); 560 } 561 if (binding.isArray()) { 562 return containsNestedCapture(binding.getElementType(), true); 563 } 564 ITypeBinding[] typeArguments= binding.getTypeArguments(); 565 for (int i= 0; i < typeArguments.length; i++) { 566 if (containsNestedCapture(typeArguments[i], true)) { 567 return true; 568 } 569 } 570 return false; 571 } 572 573 private boolean containsNestedCapture(String signature) { 574 return signature.length() > 1 && signature.indexOf(Signature.C_CAPTURE, 1) != -1; 575 } 576 577 private static ITypeBinding normalizeTypeBinding(ITypeBinding binding) { 578 if (binding != null && !binding.isNullType() && !"void".equals(binding.getName())) { if (binding.isAnonymous()) { 580 ITypeBinding[] baseBindings= binding.getInterfaces(); 581 if (baseBindings.length > 0) { 582 return baseBindings[0]; 583 } 584 return binding.getSuperclass(); 585 } 586 if (binding.isCapture()) { 587 return binding.getWildcard(); 588 } 589 return binding; 590 } 591 return null; 592 } 593 594 612 public Type addImport(ITypeBinding binding, AST ast) { 613 return addImport(binding, ast, this.defaultContext); 614 } 615 616 636 public Type addImport(ITypeBinding binding, AST ast, ImportRewriteContext context) { 637 if (binding.isPrimitive()) { 638 return ast.newPrimitiveType(PrimitiveType.toCode(binding.getName())); 639 } 640 641 ITypeBinding normalizedBinding= normalizeTypeBinding(binding); 642 if (normalizedBinding == null) { 643 return ast.newSimpleType(ast.newSimpleName("invalid")); } 645 646 if (normalizedBinding.isTypeVariable()) { 647 return ast.newSimpleType(ast.newSimpleName(binding.getName())); 649 } 650 if (normalizedBinding.isWildcardType()) { 651 WildcardType wcType= ast.newWildcardType(); 652 ITypeBinding bound= normalizedBinding.getBound(); 653 if (bound != null && !bound.isWildcardType() && !bound.isCapture()) { Type boundType= addImport(bound, ast, context); 655 wcType.setBound(boundType, normalizedBinding.isUpperbound()); 656 } 657 return wcType; 658 } 659 660 if (normalizedBinding.isArray()) { 661 Type elementType= addImport(normalizedBinding.getElementType(), ast, context); 662 return ast.newArrayType(elementType, normalizedBinding.getDimensions()); 663 } 664 665 String qualifiedName= getRawQualifiedName(normalizedBinding); 666 if (qualifiedName.length() > 0) { 667 String res= internalAddImport(qualifiedName, context); 668 669 ITypeBinding[] typeArguments= normalizedBinding.getTypeArguments(); 670 if (typeArguments.length > 0) { 671 Type erasureType= ast.newSimpleType(ast.newName(res)); 672 ParameterizedType paramType= ast.newParameterizedType(erasureType); 673 List arguments= paramType.typeArguments(); 674 for (int i= 0; i < typeArguments.length; i++) { 675 ITypeBinding curr= typeArguments[i]; 676 if (containsNestedCapture(curr, false)) { arguments.add(ast.newWildcardType()); 678 } else { 679 arguments.add(addImport(curr, ast, context)); 680 } 681 } 682 return paramType; 683 } 684 return ast.newSimpleType(ast.newName(res)); 685 } 686 return ast.newSimpleType(ast.newName(getRawName(normalizedBinding))); 687 } 688 689 690 706 public String addImport(String qualifiedTypeName, ImportRewriteContext context) { 707 int angleBracketOffset= qualifiedTypeName.indexOf('<'); 708 if (angleBracketOffset != -1) { 709 return internalAddImport(qualifiedTypeName.substring(0, angleBracketOffset), context) + qualifiedTypeName.substring(angleBracketOffset); 710 } 711 int bracketOffset= qualifiedTypeName.indexOf('['); 712 if (bracketOffset != -1) { 713 return internalAddImport(qualifiedTypeName.substring(0, bracketOffset), context) + qualifiedTypeName.substring(bracketOffset); 714 } 715 return internalAddImport(qualifiedTypeName, context); 716 } 717 718 732 public String addImport(String qualifiedTypeName) { 733 return addImport(qualifiedTypeName, this.defaultContext); 734 } 735 736 753 public String addStaticImport(IBinding binding) { 754 return addStaticImport(binding, this.defaultContext); 755 } 756 757 776 public String addStaticImport(IBinding binding, ImportRewriteContext context) { 777 if (Modifier.isStatic(binding.getModifiers())) { 778 if (binding instanceof IVariableBinding) { 779 IVariableBinding variableBinding= (IVariableBinding) binding; 780 if (variableBinding.isField()) { 781 ITypeBinding declaringType= variableBinding.getDeclaringClass(); 782 return addStaticImport(getRawQualifiedName(declaringType), binding.getName(), true, context); 783 } 784 } else if (binding instanceof IMethodBinding) { 785 ITypeBinding declaringType= ((IMethodBinding) binding).getDeclaringClass(); 786 return addStaticImport(getRawQualifiedName(declaringType), binding.getName(), false, context); 787 } 788 } 789 throw new IllegalArgumentException ("Binding must be a static field or method."); } 791 792 810 public String addStaticImport(String declaringTypeName, String simpleName, boolean isField) { 811 return addStaticImport(declaringTypeName, simpleName, isField, this.defaultContext); 812 } 813 814 834 public String addStaticImport(String declaringTypeName, String simpleName, boolean isField, ImportRewriteContext context) { 835 if (declaringTypeName.indexOf('.') == -1) { 836 return declaringTypeName + '.' + simpleName; 837 } 838 if (context == null) { 839 context= this.defaultContext; 840 } 841 int kind= isField ? ImportRewriteContext.KIND_STATIC_FIELD : ImportRewriteContext.KIND_STATIC_METHOD; 842 int res= context.findInContext(declaringTypeName, simpleName, kind); 843 if (res == ImportRewriteContext.RES_NAME_CONFLICT) { 844 return declaringTypeName + '.' + simpleName; 845 } 846 if (res == ImportRewriteContext.RES_NAME_UNKNOWN) { 847 addEntry(STATIC_PREFIX + declaringTypeName + '.' + simpleName); 848 } 849 return simpleName; 850 } 851 852 private String internalAddImport(String fullTypeName, ImportRewriteContext context) { 853 int idx= fullTypeName.lastIndexOf('.'); 854 String typeContainerName, typeName; 855 if (idx != -1) { 856 typeContainerName= fullTypeName.substring(0, idx); 857 typeName= fullTypeName.substring(idx + 1); 858 } else { 859 typeContainerName= ""; typeName= fullTypeName; 861 } 862 863 if (typeContainerName.length() == 0 && PrimitiveType.toCode(typeName) != null) { 864 return fullTypeName; 865 } 866 867 if (context == null) 868 context= this.defaultContext; 869 870 int res= context.findInContext(typeContainerName, typeName, ImportRewriteContext.KIND_TYPE); 871 if (res == ImportRewriteContext.RES_NAME_CONFLICT) { 872 return fullTypeName; 873 } 874 if (res == ImportRewriteContext.RES_NAME_UNKNOWN) { 875 addEntry(NORMAL_PREFIX + fullTypeName); 876 } 877 return typeName; 878 } 879 880 private void addEntry(String entry) { 881 this.existingImports.add(entry); 882 883 if (this.removedImports != null) { 884 if (this.removedImports.remove(entry)) { 885 return; 886 } 887 } 888 889 if (this.addedImports == null) { 890 this.addedImports= new ArrayList (); 891 } 892 this.addedImports.add(entry); 893 } 894 895 private boolean removeEntry(String entry) { 896 if (this.existingImports.remove(entry)) { 897 if (this.addedImports != null) { 898 if (this.addedImports.remove(entry)) { 899 return true; 900 } 901 } 902 if (this.removedImports == null) { 903 this.removedImports= new ArrayList (); 904 } 905 this.removedImports.add(entry); 906 return true; 907 } 908 return false; 909 } 910 911 921 public boolean removeImport(String qualifiedName) { 922 return removeEntry(NORMAL_PREFIX + qualifiedName); 923 } 924 925 935 public boolean removeStaticImport(String qualifiedName) { 936 return removeEntry(STATIC_PREFIX + qualifiedName); 937 } 938 939 private static String getRawName(ITypeBinding normalizedBinding) { 940 return normalizedBinding.getTypeDeclaration().getName(); 941 } 942 943 private static String getRawQualifiedName(ITypeBinding normalizedBinding) { 944 return normalizedBinding.getTypeDeclaration().getQualifiedName(); 945 } 946 947 948 961 public final TextEdit rewriteImports(IProgressMonitor monitor) throws CoreException { 962 if (monitor == null) { 963 monitor= new NullProgressMonitor(); 964 } 965 966 try { 967 monitor.beginTask(Messages.bind(Messages.importRewrite_processDescription), 2); 968 if (!hasRecordedChanges()) { 969 this.createdImports= CharOperation.NO_STRINGS; 970 this.createdStaticImports= CharOperation.NO_STRINGS; 971 return new MultiTextEdit(); 972 } 973 974 CompilationUnit usedAstRoot= this.astRoot; 975 if (usedAstRoot == null) { 976 ASTParser parser= ASTParser.newParser(AST.JLS3); 977 parser.setSource(this.compilationUnit); 978 parser.setFocalPosition(0); parser.setResolveBindings(false); 980 usedAstRoot= (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1)); 981 } 982 983 ImportRewriteAnalyzer computer= new ImportRewriteAnalyzer(this.compilationUnit, usedAstRoot, this.importOrder, this.importOnDemandThreshold, this.staticImportOnDemandThreshold, this.restoreExistingImports); 984 computer.setFilterImplicitImports(this.filterImplicitImports); 985 986 if (this.addedImports != null) { 987 for (int i= 0; i < this.addedImports.size(); i++) { 988 String curr= (String ) this.addedImports.get(i); 989 computer.addImport(curr.substring(1), STATIC_PREFIX == curr.charAt(0)); 990 } 991 } 992 993 if (this.removedImports != null) { 994 for (int i= 0; i < this.removedImports.size(); i++) { 995 String curr= (String ) this.removedImports.get(i); 996 computer.removeImport(curr.substring(1), STATIC_PREFIX == curr.charAt(0)); 997 } 998 } 999 1000 TextEdit result= computer.getResultingEdits(new SubProgressMonitor(monitor, 1)); 1001 this.createdImports= computer.getCreatedImports(); 1002 this.createdStaticImports= computer.getCreatedStaticImports(); 1003 return result; 1004 } finally { 1005 monitor.done(); 1006 } 1007 } 1008 1009 1018 public String [] getCreatedImports() { 1019 return this.createdImports; 1020 } 1021 1022 1031 public String [] getCreatedStaticImports() { 1032 return this.createdStaticImports; 1033 } 1034 1035 1040 public String [] getAddedImports() { 1041 return filterFromList(this.addedImports, NORMAL_PREFIX); 1042 } 1043 1044 1049 public String [] getAddedStaticImports() { 1050 return filterFromList(this.addedImports, STATIC_PREFIX); 1051 } 1052 1053 1058 public String [] getRemovedImports() { 1059 return filterFromList(this.removedImports, NORMAL_PREFIX); 1060 } 1061 1062 1067 public String [] getRemovedStaticImports() { 1068 return filterFromList(this.removedImports, STATIC_PREFIX); 1069 } 1070 1071 1075 public boolean hasRecordedChanges() { 1076 return !this.restoreExistingImports || 1077 (this.addedImports != null && !this.addedImports.isEmpty()) || 1078 (this.removedImports != null && !this.removedImports.isEmpty()); 1079 } 1080 1081 1082 private static String [] filterFromList(List imports, char prefix) { 1083 if (imports == null) { 1084 return CharOperation.NO_STRINGS; 1085 } 1086 ArrayList res= new ArrayList (); 1087 for (int i= 0; i < imports.size(); i++) { 1088 String curr= (String ) imports.get(i); 1089 if (prefix == curr.charAt(0)) { 1090 res.add(curr.substring(1)); 1091 } 1092 } 1093 return (String []) res.toArray(new String [res.size()]); 1094 } 1095 1096} 1097 | Popular Tags |