List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander.java
private String packageName(Class<?> type) { return Optional.fromNullable(type.getPackage()).transform(toPackageName()).or("java"); }
From source file:com.sshtools.common.ui.ResourceIcon.java
/** * Creates a new ResourceIcon object.//from www . j a v a 2 s . co m * * @param cls * @param image */ public ResourceIcon(Class cls, String image) { super(); this.cls = cls; if (image.startsWith("/")) { loadImage(image); } else { String path = "/" + cls.getPackage().getName(); path = path.replace('.', '/'); path += ("/" + image); loadImage(path); } }
From source file:name.ikysil.beanpathdsl.codegen.CodeGen.java
private String getTargetPackageName(Class<?> clazz) { final String packageName = clazz.getPackage().getName(); StringBuilder sb = new StringBuilder(); if (!StringUtils.isBlank(configuration.getPackageNamePrefix())) { sb.append(configuration.getPackageNamePrefix()).append("."); }//from ww w . j ava2 s . c o m sb.append(packageName); if (!StringUtils.isBlank(configuration.getPackageNameSuffix())) { sb.append(".").append(configuration.getPackageNameSuffix()); } return sb.toString(); }
From source file:net.sradonia.i18n.StringBundle.java
public StringBundle(Class<?> clazz) { this(clazz.getPackage()); setPrefix(clazz); }
From source file:org.jbpm.services.task.jaxb.ComparePair.java
private Class<?> getInterface(Object obj) { Class<?> newInterface = obj.getClass(); Class<?> parent = newInterface; while (parent != null) { parent = null;//from ww w . jav a 2s .com if (newInterface.getInterfaces().length > 0) { Class<?> newParent = newInterface.getInterfaces()[0]; if (newParent.getPackage().getName().startsWith("org.")) { parent = newInterface = newParent; } } } return newInterface; }
From source file:net.sf.cocmvc.ConventionalHandlerMapping.java
private String determineControllerPrefix(Class<?> handlerType) { if (basePackage == null) return ""; String relativePackage = handlerType.getPackage().getName().replaceFirst(basePackage, ""); return packageToPath(relativePackage); }
From source file:hcm.ssj.creator.dialogs.AddDialog.java
/** * @param clazzes Class[]//from ww w. j av a2 s. c o m */ public void setOption(ArrayList<Class> clazzes) { hashMap = new LinkedHashMap<>(); //get each package once HashSet<Package> hashSet = new HashSet<>(); for (Class clazz : clazzes) { hashSet.add(clazz.getPackage()); } //only show last part of the package name String[] packages = new String[hashSet.size()]; int count = 0; for (Package pack : hashSet) { String name = pack.getName(); packages[count++] = name.substring(name.lastIndexOf(".") + 1); } //sort packages by name and add them to map Arrays.sort(packages); for (String name : packages) { hashMap.put(name, new ArrayList<Class>()); } //sort classes by name Collections.sort(clazzes, new Comparator<Class>() { @Override public int compare(Class lhs, Class rhs) { return lhs.getSimpleName().compareTo(rhs.getSimpleName()); } }); //add every class to its corresponding package for (Class clazz : clazzes) { String name = clazz.getPackage().getName(); hashMap.get(name.substring(name.lastIndexOf(".") + 1)).add(clazz); } //create internal variables to save the state of the list itemState = new boolean[hashMap.size()][]; count = 0; allItems = 0; allItems += hashMap.size(); for (Map.Entry<String, ArrayList<Class>> entry : hashMap.entrySet()) { itemState[count++] = new boolean[entry.getValue().size()]; allItems += entry.getValue().size(); } }
From source file:com.github.springfox.loader.SpringfoxLoaderConfig.java
@Bean @Conditional(ActiveProfilesCondition.class) public Docket api() { ApiSelectorBuilder apiSelectorBuilder = new Docket(DocumentationType.SWAGGER_2).select(); Predicate<RequestHandler> predicate = RequestHandlerSelectors .basePackage(springfoxLoader.getBasePackage())::apply; if (springfoxLoader.includeControllers().length > 0) { Class<?>[] controllers = springfoxLoader.includeControllers(); for (Class<?> controller : controllers) { Predicate<RequestHandler> includeControllerRequestHandler = RequestHandlerSelectors .basePackage(controller.getPackage().getName())::apply; predicate = predicate.or(includeControllerRequestHandler); }//from w w w . ja v a 2 s .co m } apiSelectorBuilder.apis(predicate::test); apiSelectorBuilder.paths(PathSelectors.any()).build().apiInfo(apiInfo()) .pathMapping(springfoxLoader.getPath()); return apiSelectorBuilder.build(); }
From source file:net.sradonia.i18n.StringBundle.java
public StringBundle(Class<?> clazz, Locale locale) { this(clazz.getPackage(), locale); setPrefix(clazz); }
From source file:org.evosuite.junit.CoverageAnalysisOfProjectSystemTest.java
private void copyClassFile(String root, String tmp, Class<?> clazz) throws IOException { // create structure new File(tmp, clazz.getPackage().getName().replace(".", File.separator)).mkdirs(); // copy .class file Files.copy(Paths.get(root + clazz.getCanonicalName().replace(".", File.separator) + ".class"), Paths.get(tmp + File.separator + clazz.getCanonicalName().replace(".", File.separator) + ".class"), StandardCopyOption.COPY_ATTRIBUTES); }