1 11 package org.eclipse.jdt.apt.core.internal.util; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv; 16 import org.eclipse.jdt.core.IPackageFragment; 17 import org.eclipse.jdt.core.IPackageFragmentRoot; 18 import org.eclipse.jdt.core.JavaModelException; 19 20 24 public class PackageUtil { 25 26 private PackageUtil() {} 27 28 public static IPackageFragment[] getPackageFragments( 29 final String packageName, 30 final BaseProcessorEnv env) { 31 32 List <IPackageFragment> packages = new ArrayList <IPackageFragment>(); 33 try { 34 IPackageFragmentRoot[] roots = env.getAllPackageFragmentRoots(); 36 for (IPackageFragmentRoot root : roots) { 37 IPackageFragment fragment = root.getPackageFragment(packageName); 38 if (fragment != null && fragment.exists()) 39 packages.add(fragment); 40 } 41 } 42 catch (JavaModelException e) { 43 return new IPackageFragment[0]; 44 } 45 46 return packages.toArray(new IPackageFragment[packages.size()]); 47 } 48 49 } 50 | Popular Tags |