List of usage examples for java.lang Class getPackage
public Package getPackage()
From source file:com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfigurationTest.java
/** * Tests that all classes in *.javascript.* which have {@link JsxClasses}/{@link JsxClass} annotation, * are included in {@link JavaScriptConfiguration#CLASSES_}. *///w ww .j a v a 2 s. co m @Test public void jsxClasses() { final List<String> foundJsxClasses = new ArrayList<>(); for (final String className : getClassesForPackage(JavaScriptEngine.class)) { if (!className.contains("$")) { Class<?> klass = null; try { klass = Class.forName(className); } catch (final Throwable t) { continue; } if ("com.gargoylesoftware.htmlunit.javascript.host.intl".equals(klass.getPackage().getName())) { continue; } if (klass.getAnnotation(JsxClasses.class) != null) { foundJsxClasses.add(className); } else if (klass.getAnnotation(JsxClass.class) != null) { foundJsxClasses.add(className); } } } foundJsxClasses.remove(DedicatedWorkerGlobalScope.class.getName()); final List<String> definedClasses = new ArrayList<>(); for (final Class<?> klass : JavaScriptConfiguration.CLASSES_) { definedClasses.add(klass.getName()); } foundJsxClasses.removeAll(definedClasses); if (!foundJsxClasses.isEmpty()) { fail("Class " + foundJsxClasses.get(0) + " is not in JavaScriptConfiguration.CLASSES_"); } }
From source file:org.nuunframework.cli.NuunCliPlugin.java
boolean hasAnnotationDeep(Class<? extends Annotation> from, Class<? extends Annotation> toFind) { if (from.equals(toFind)) { return true; }/* w w w .ja v a 2s .c o m*/ for (Annotation anno : from.getAnnotations()) { Class<? extends Annotation> annoClass = anno.annotationType(); if (!annoClass.getPackage().getName().startsWith("java.lang") && hasAnnotationDeep(annoClass, toFind)) { return true; } } return false; }
From source file:org.codehaus.enunciate.modules.xfire.EnunciatedJAXWSOperationBinding.java
/** * Loads the set of output properties for the specified operation. * * @param op The operation.//from w w w.j av a 2 s .co m * @return The output properties. */ protected OperationBeanInfo getResponseInfo(OperationInfo op) throws XFireFault { Method method = op.getMethod(); Class ei = method.getDeclaringClass(); Package pckg = ei.getPackage(); SOAPBinding.ParameterStyle paramStyle = SOAPBinding.ParameterStyle.WRAPPED; if (method.isAnnotationPresent(SOAPBinding.class)) { SOAPBinding annotation = method.getAnnotation(SOAPBinding.class); paramStyle = annotation.parameterStyle(); } else if (ei.isAnnotationPresent(SOAPBinding.class)) { SOAPBinding annotation = ((SOAPBinding) ei.getAnnotation(SOAPBinding.class)); paramStyle = annotation.parameterStyle(); } if (paramStyle == SOAPBinding.ParameterStyle.BARE) { //bare return type. //todo: it's not necessarily the return type! it could be an OUT parameter... return new OperationBeanInfo(method.getReturnType(), null, op.getOutputMessage()); } else { String responseWrapperClassName; ResponseWrapper responseWrapperInfo = method.getAnnotation(ResponseWrapper.class); if ((responseWrapperInfo != null) && (responseWrapperInfo.className() != null) && (responseWrapperInfo.className().length() > 0)) { responseWrapperClassName = responseWrapperInfo.className(); } else { StringBuilder builder = new StringBuilder(pckg == null ? "" : pckg.getName()); if (builder.length() > 0) { builder.append("."); } builder.append("jaxws."); String methodName = method.getName(); builder.append(capitalize(methodName)).append("Response"); responseWrapperClassName = builder.toString(); } Class wrapperClass; try { wrapperClass = ClassLoaderUtils.loadClass(responseWrapperClassName, getClass()); } catch (ClassNotFoundException e) { LOG.debug("Unabled to find request wrapper class " + responseWrapperClassName + "... Operation " + op.getQName() + " will not be able to send..."); return null; } return new OperationBeanInfo(wrapperClass, loadOrderedProperties(wrapperClass), op.getOutputMessage()); } }
From source file:com.ethanruffing.preferenceabstraction.AutoPreferences.java
/** * Constructs a new preferences tracker for the given class, defaulting to * the system's native preferences storage system if no higher priority type * is found. Defaults to look for an XML file. * * @param c The class for which the preferences are to be stored. * @throws ConfigurationException Thrown if an error occurs while loading * the configuration file. *///from w w w. jav a 2 s. c o m public AutoPreferences(Class<?> c) throws ConfigurationException { prefs = null; fileConfig = null; if (new File(c.getPackage().getName() + ".xml").exists()) { setup(c, ConfigurationType.LOCAL); } else if (new File(System.getProperty("user.home"), c.getPackage().getName() + ".xml").exists()) { setup(c, ConfigurationType.HOME); } else { setup(c, ConfigurationType.SYSTEM); } }
From source file:org.assertj.assertions.generator.description.TypeName.java
public TypeName(Class<?> clazz) { super();/* www .jav a2s. co m*/ this.typeSimpleName = clazz.getSimpleName(); this.typeSimpleNameWithOuterClass = ClassUtil.getSimpleNameWithOuterClass(clazz); this.typeSimpleNameWithOuterClassNotSeparatedByDots = ClassUtil .getSimpleNameWithOuterClassNotSeparatedByDots(clazz); this.packageName = clazz.getPackage() == null ? NO_PACKAGE : clazz.getPackage().getName(); }
From source file:org.eclipse.wb.tests.utils.ProjectClassLoaderTest.java
/** * Test that {@link ProjectClassLoader} defines packages. */// www. j a va 2 s .c o m public void test_getPackage() throws Exception { setFileContentSrc("test/SuperPanel.java", getTestSource("// filler filler filler filler filler", "// filler filler filler filler filler", "abstract public class SuperPanel extends JPanel {", "}")); waitForAutoBuild(); ContainerInfo panel = parseContainer("// filler filler filler", "abstract class Test extends SuperPanel {", " public Test() {", " }", "}"); // Class<?> superPanelClass = panel.getDescription().getComponentClass(); assertNotNull(superPanelClass.getPackage()); assertEquals("test", superPanelClass.getPackage().getName()); }
From source file:org.diorite.impl.bean.BeanScanner.java
private void processClass(final Class<?> clazz) throws BeanException { // Bean registration by class if (clazz.isAnnotationPresent(DioriteBean.class)) { final DioriteBean beanInfo = clazz.getAnnotation(DioriteBean.class); final BeanContainer beanContainer = new BeanContainer(clazz, new ClassBeanProvider(clazz)); this.beanManager.registerBean(beanContainer); }//ww w . j a v a2 s . c o m // Bean registration by constructor for (final Constructor<?> constructor : clazz.getConstructors()) { if (constructor.isAnnotationPresent(DioriteBean.class)) { final DioriteBean beanInfo = constructor.getAnnotation(DioriteBean.class); final BeanContainer beanContainer = new BeanContainer(clazz, new ConstructorBeanProvider(constructor)); this.beanManager.registerBean(beanContainer); } } // Bean registration by method for (final Method method : clazz.getMethods()) { if (method.isAnnotationPresent(DioriteBean.class)) { final Class<?> returnType = method.getReturnType(); if (returnType.equals(Void.TYPE) || returnType.isPrimitive()) { throw new BeanRegisteringException(MessageFormat.format( "Can't register method '{0}' in class '{1}' as Diorite Bean. Method must return object.", method.getName(), clazz.getName())); } else if (returnType.getPackage().equals(JAVA_PACKAGE)) { throw new BeanRegisteringException(MessageFormat.format( "Can't register method '{0}' in class '{1}' as Diorite Bean. Method can't return object from java package.", method.getName(), clazz.getName())); } final DioriteBean beanInfo = method.getAnnotation(DioriteBean.class); final BeanContainer beanContainer = new BeanContainer(returnType, new MethodBeanProvider(method)); this.beanManager.registerBean(beanContainer); } } for (final Field field : clazz.getDeclaredFields()) { if (field.isAnnotationPresent(InjectedValue.class)) { this.beanManager.addInjectorCode(clazz); break; } } }
From source file:org.kie.workbench.common.screens.datamodeller.backend.server.DataModelTestUtil.java
public DataObject createDataObject(Class clazz) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Class superClass = clazz.getSuperclass(); String superClassName = null; if (superClass != null && !superClass.equals(Object.class)) { superClassName = superClass.getCanonicalName(); }/*from w ww .j ava2 s. com*/ DataObject dataObj = createDataObject(clazz.getPackage().getName(), clazz.getSimpleName(), superClassName); addAnnotations(dataObj, clazz.getAnnotations()); for (Field field : clazz.getDeclaredFields()) { String fieldName = field.getName(); String fieldType = field.getType().getCanonicalName(); ObjectProperty fieldProp = addProperty(dataObj, fieldName, fieldType, true, false, null); addAnnotations(fieldProp, field.getAnnotations()); } return dataObj; }
From source file:jp.gr.java_conf.petit_lycee.subsonico.MethodConstants.java
private Field getField(@SuppressWarnings("rawtypes") Class cls, String fieldName) throws NoSuchFieldException { try {/*w w w . ja v a 2 s .c om*/ return cls.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { @SuppressWarnings("rawtypes") Class super_cls = cls.getSuperclass(); //???? //?? if (super_cls != null && super_cls.getPackage().equals(cls.getPackage())) { return getField(super_cls, fieldName); } throw e; } }
From source file:org.dasein.cloud.aws.AWSCloud.java
static public Logger getWireLogger(Class<?> cls) { return Logger.getLogger("dasein.cloud.aws.wire." + getLastItem(cls.getPackage().getName()) + "." + getLastItem(cls.getName())); }