com.vaadin.flow.component.dependency.CssImport Java Examples
The following examples show how to use
com.vaadin.flow.component.dependency.CssImport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FullDependenciesScanner.java From flow with Apache License 2.0 | 6 votes |
private Set<CssData> discoverCss() { try { Class<? extends Annotation> loadedAnnotation = getFinder() .loadClass(CssImport.class.getName()); Set<Class<?>> annotatedClasses = getFinder() .getAnnotatedClasses(loadedAnnotation); Set<CssData> result = new LinkedHashSet<>(); for (Class<?> clazz : annotatedClasses) { classes.add(clazz.getName()); List<? extends Annotation> imports = annotationFinder .apply(clazz, loadedAnnotation); imports.stream().forEach(imp -> result.add(createCssData(imp))); } return result; } catch (ClassNotFoundException exception) { throw new IllegalStateException( COULD_NOT_LOAD_ERROR_MSG + CssData.class.getName(), exception); } }
Example #2
Source File: FrontendClassVisitor.java From flow with Apache License 2.0 | 5 votes |
@Override public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { addSignatureToClasses(children, descriptor); // We return different visitor implementations depending on the // annotation String cname = descriptor.replace("/", "."); if (className.equals(endPoint.name) && cname.contains(Route.class.getName())) { return routeVisitor; } if (cname.contains(JsModule.class.getName())) { return jsModuleVisitor; } if (cname.contains(JavaScript.class.getName())) { return jScriptVisitor; } if (cname.contains(NoTheme.class.getName())) { if (className.equals(endPoint.name)) { endPoint.theme.notheme = true; } return null; } if (cname.contains(Theme.class.getName())) { if (className.equals(endPoint.name)) { return themeRouteVisitor; } if (className.equals(endPoint.layout)) { return themeLayoutVisitor; } } if (cname.contains(CssImport.class.getName())) { return new CssAnnotationVisitor(endPoint.css); } // default visitor return annotationVisitor; }
Example #3
Source File: FullDependenciesScannerTest.java From flow with Apache License 2.0 | 5 votes |
@Test public void getCss_returnAllCss_orderPerClassIsPreserved_getClassesReturnAllCssAnnotatedComponents() throws ClassNotFoundException { FrontendDependenciesScanner scanner = setUpAnnotationScanner( CssImport.class); List<CssData> css = new ArrayList<>(scanner.getCss()); Assert.assertEquals(7, css.size()); Assert.assertEquals( createCssData("@vaadin/vaadin-mixed-component/bar.css", null, null, null), css.get(0)); Assert.assertEquals(createCssData("./foo.css", null, null, null), css.get(1)); Assert.assertEquals(createCssData("./foo.css", null, "bar", null), css.get(2)); Assert.assertEquals(createCssData("./foo.css", "baz", null, null), css.get(3)); Assert.assertEquals(createCssData("./foo.css", "baz", "bar", null), css.get(4)); Assert.assertEquals(createCssData("./foo.css", null, null, "foo-bar"), css.get(5)); Assert.assertEquals(createCssData("./foo.css", null, "bar", "foo-bar"), css.get(6)); Set<String> visitedClasses = scanner.getClasses(); Assert.assertEquals(1, visitedClasses.size()); Assert.assertEquals(FlatImport.class.getName(), visitedClasses.iterator().next()); }
Example #4
Source File: DevModeClassFinderTest.java From flow with Apache License 2.0 | 5 votes |
@Test public void applicableClasses_knownClasses() { Collection<Class<?>> classes = getApplicableClasses(); List<Class<?>> knownClasses = Arrays.asList( Route.class, UIInitListener.class, VaadinServiceInitListener.class, WebComponentExporter.class, WebComponentExporterFactory.class, NpmPackage.class, NpmPackage.Container.class, JsModule.class, JsModule.Container.class, JavaScript.class, JavaScript.Container.class, CssImport.class, CssImport.Container.class, Theme.class, NoTheme.class, HasErrorParameter.class); for (Class<?> clz : classes) { assertTrue("should be a known class " + clz.getName(), knownClasses.contains(clz)); } Assert.assertEquals(knownClasses.size(), classes.size()); }
Example #5
Source File: ComponentMetaData.java From flow with Apache License 2.0 | 4 votes |
List<CssImport> getCssImports() { return Collections.unmodifiableList(cssImports); }
Example #6
Source File: UIInternals.java From flow with Apache License 2.0 | 4 votes |
private void addFallbackDependencies(DependencyInfo dependency) { if (isFallbackChunkLoaded) { return; } VaadinContext context = ui.getSession().getService().getContext(); FallbackChunk chunk = context.getAttribute(FallbackChunk.class); if (chunk == null) { if (getLogger().isDebugEnabled()) { getLogger().debug( "Fallback chunk is not available, skipping fallback dependencies load"); } return; } Set<String> modules = chunk.getModules(); Set<CssImportData> cssImportsData = chunk.getCssImports(); if (modules.isEmpty() && cssImportsData.isEmpty()) { getLogger().debug( "Fallback chunk is empty, skipping fallback dependencies load"); return; } List<CssImport> cssImports = dependency.getCssImports(); List<JavaScript> javaScripts = dependency.getJavaScripts(); List<JsModule> jsModules = dependency.getJsModules(); if (jsModules.stream().map(JsModule::value) .anyMatch(modules::contains)) { loadFallbackChunk(); return; } if (javaScripts.stream().map(JavaScript::value) .anyMatch(modules::contains)) { loadFallbackChunk(); return; } if (cssImports.stream().map(this::buildData) .anyMatch(cssImportsData::contains)) { loadFallbackChunk(); return; } }
Example #7
Source File: UIInternals.java From flow with Apache License 2.0 | 4 votes |
private CssImportData buildData(CssImport imprt) { Function<String, String> converter = str -> str.isEmpty() ? null : str; return new CssImportData(converter.apply(imprt.value()), converter.apply(imprt.id()), converter.apply(imprt.include()), converter.apply(imprt.themeFor())); }
Example #8
Source File: AnnotationReader.java From flow with Apache License 2.0 | 2 votes |
/** * Finds all {@link CssImport} annotations on the given {@link Component} * class, its super classes and implemented interfaces. * * @param componentClass * the component class to search for the annotation * @return a list the CssImport annotations found * @see #getAnnotationFor(Class, Class) for what order the annotations are * in the list */ public static List<CssImport> getCssImportAnnotations( Class<? extends Component> componentClass) { return getAnnotationsFor(componentClass, CssImport.class); }