private RenamingResult doClassRenaming(CssTree cssTree, JMethod method, TreeLogger logger, ResourceContext context) throws UnableToCompleteException { Map<String, Map<String, String>> replacementsWithPrefix = computeReplacements(method, logger, context); RenamingSubstitutionMap substitutionMap = new RenamingSubstitutionMap(replacementsWithPrefix); new CssClassRenaming(cssTree.getMutatingVisitController(), substitutionMap, null).runPass(); Map<String, String> mapping = replacementsWithPrefix.get(""); mapping = Maps.newHashMap(Maps.filterKeys(mapping, Predicates.in(substitutionMap .getStyleClasses()))); return new RenamingResult(mapping, substitutionMap.getExternalClassCandidates()); }
/** * Restricts the compiled permutations by applying the given binding properties, if possible. * In some cases, a different binding may be chosen instead. */ private Map<String, String> restrictPermutations(TreeLogger logger, ModuleDef moduleDef, Map<String, String> bindingProperties) { Map<String, String> chosenProps = Maps.newHashMap(); for (Map.Entry<String, String> entry : bindingProperties.entrySet()) { String propName = entry.getKey(); String propValue = entry.getValue(); String actual = maybeSetBinding(logger, moduleDef, propName, propValue); if (actual != null) { chosenProps.put(propName, actual); } } return chosenProps; }
/** * Create a property oracle that will return the supplied values. * * @param orderedProps array of binding properties * @param orderedPropValues values of the above binding properties * @param configProps array of config properties */ public StaticPropertyOracle(BindingProperty[] orderedProps, String[] orderedPropValues, ConfigurationProperty[] configProps) { this.orderedProps = orderedProps; this.orderedPropValues = orderedPropValues; this.configPropertiesByName = Maps.uniqueIndex(Arrays.asList(configProps), getConfigNameExtractor()); // Reject illegal values at construction time int len = orderedProps.length; for (int i = 0; i < len; i++) { BindingProperty prop = orderedProps[i]; String value = orderedPropValues[i]; if (!prop.isAllowedValue(value)) { throw new IllegalArgumentException("Property " + prop.getName() + " cannot have value " + value); } } }
return ImmutableMap.copyOf( Maps.transformValues( propertyAccessors, new Function<PropertyAccessorsBuilder, PropertyAccessors>() {
/** * Restricts the compiled permutations by applying the given binding properties, if possible. * In some cases, a different binding may be chosen instead. */ private Map<String, String> restrictPermutations(TreeLogger logger, ModuleDef moduleDef, Map<String, String> bindingProperties) { Map<String, String> chosenProps = Maps.newHashMap(); for (Map.Entry<String, String> entry : bindingProperties.entrySet()) { String propName = entry.getKey(); String propValue = entry.getValue(); String actual = maybeSetBinding(logger, moduleDef, propName, propValue); if (actual != null) { chosenProps.put(propName, actual); } } return chosenProps; }
/** * Create a property oracle that will return the supplied values. * * @param orderedProps array of binding properties * @param orderedPropValues values of the above binding properties * @param configProps array of config properties */ public StaticPropertyOracle(BindingProperty[] orderedProps, String[] orderedPropValues, ConfigurationProperty[] configProps) { this.orderedProps = orderedProps; this.orderedPropValues = orderedPropValues; this.configPropertiesByName = Maps.uniqueIndex(Arrays.asList(configProps), getConfigNameExtractor()); // Reject illegal values at construction time int len = orderedProps.length; for (int i = 0; i < len; i++) { BindingProperty prop = orderedProps[i]; String value = orderedPropValues[i]; if (!prop.isAllowedValue(value)) { throw new IllegalArgumentException("Property " + prop.getName() + " cannot have value " + value); } } }
static <A extends Annotation> ImmutableSet<Class<? extends ConstraintValidator<A, ?>>> // getValidatorForType(final Class<?> ptype, final List<Class<? extends ConstraintValidator<A, ?>>> constraintValidatorClasses) { final Class<?> type = Primitives.wrap(ptype); final Map<Class<?>, Class<? extends ConstraintValidator<A, ?>>> map = Maps.newHashMap(); for (final Class<? extends ConstraintValidator<A, ?>> conClass : constraintValidatorClasses) { final Class<?> aType = Primitives.wrap(getTypeOfConstraintValidator(conClass)); if (aType.isAssignableFrom(type)) { map.put(aType, conClass); } } // TODO(nchalko) implement per spec // Handle Arrays and Generics final Set<Class<?>> best = Util.findBestMatches(type, map.keySet()); final Predicate<Class<?>> inBest = key -> best.contains(key); return ImmutableSet.copyOf(Maps.filterKeys(map, inBest).values()); }
public void addGenerator(RestyJsonSerializerGenerator generator, TypeOracle typeOracle) { JType type = generator.getType(typeOracle); if (type.isPrimitive() != null) { if (primitiveMappings == null) { primitiveMappings = Maps.newHashMap(); } primitiveMappings.put(type.isPrimitive(), generator); } else if (type.isClass() != null) { if (classMappings == null) { classMappings = Maps.newHashMap(); } classMappings.put(type.isClass(), generator); } }
static <A extends Annotation> ImmutableSet<Class<? extends ConstraintValidator<A, ?>>> getValidatorForType( Class<?> type, List<Class<? extends ConstraintValidator<A, ?>>> constraintValidatorClasses) { type = Primitives.wrap(type); Map<Class<?>, Class<? extends ConstraintValidator<A, ?>>> map = Maps.newHashMap(); for (Class<? extends ConstraintValidator<A, ?>> constraintClass : constraintValidatorClasses) { Class<?> aType = Primitives.wrap(getTypeOfConstraintValidator(constraintClass)); if (aType.isAssignableFrom(type)) { map.put(aType, constraintClass); } } // TODO(nchalko) implement per spec // Handle Arrays and Generics final Set<Class<?>> best = Util.findBestMatches(type, map.keySet()); Predicate<Class<?>> inBest = new Predicate<Class<?>>() { @Override public boolean apply(Class<?> key) { return best.contains(key); } }; return ImmutableSet.copyOf(Maps.filterKeys(map, inBest).values()); }
public void addGenerator(RestyJsonSerializerGenerator generator, TypeOracle typeOracle) { JType type = generator.getType(typeOracle); if (type.isPrimitive() != null) { if (primitiveMappings == null) { primitiveMappings = Maps.newHashMap(); } primitiveMappings.put(type.isPrimitive(), generator); } else if (type.isClass() != null) { if (classMappings == null) { classMappings = Maps.newHashMap(); } classMappings.put(type.isClass(), generator); } }
static <A extends Annotation> ImmutableSet<Class<? extends ConstraintValidator<A, ?>>> getValidatorForType( Class<?> type, List<Class<? extends ConstraintValidator<A, ?>>> constraintValidatorClasses) { type = Primitives.wrap(type); Map<Class<?>, Class<? extends ConstraintValidator<A, ?>>> map = Maps.newHashMap(); for (Class<? extends ConstraintValidator<A, ?>> constraintClass : constraintValidatorClasses) { Class<?> aType = Primitives.wrap(getTypeOfConstraintValidator(constraintClass)); if (aType.isAssignableFrom(type)) { map.put(aType, constraintClass); } } // TODO(nchalko) implement per spec // Handle Arrays and Generics final Set<Class<?>> best = Util.findBestMatches(type, map.keySet()); Predicate<Class<?>> inBest = new Predicate<Class<?>>() { @Override public boolean apply(Class<?> key) { return best.contains(key); } }; return ImmutableSet.copyOf(Maps.filterKeys(map, inBest).values()); }
public static Map<Class<?>, RestyJsonTypeIdResolver> getRestyResolverClassMap(GeneratorContext context, TreeLogger logger) throws UnableToCompleteException { if (sTypeIdResolverMap == null) { try { Map<Class<?>, RestyJsonTypeIdResolver> map = Maps.newHashMap(); List<String> values = context.getPropertyOracle().getConfigurationProperty("org.fusesource.restygwt.jsontypeidresolver") .getValues(); for (String value : values) { try { Class<?> clazz = Class.forName(value); RestyJsonTypeIdResolver resolver = (RestyJsonTypeIdResolver) clazz.newInstance(); map.put(resolver.getTypeIdResolverClass(), resolver); } catch (Exception e) { logger.log(WARN, "Could not access class: " + values.get(0), e); } } sTypeIdResolverMap = map; } catch (BadPropertyValueException e) { logger.log(ERROR, "Could not acccess property: RestyJsonTypeIdResolver", e); throw new UnableToCompleteException(); } } return sTypeIdResolverMap; }
private RenamingResult doClassRenaming(CssTree cssTree, JMethod method, TreeLogger logger, ResourceContext context) throws UnableToCompleteException { Map<String, Map<String, String>> replacementsWithPrefix = computeReplacements(method, logger, context); RenamingSubstitutionMap substitutionMap = new RenamingSubstitutionMap(replacementsWithPrefix); new CssClassRenaming(cssTree.getMutatingVisitController(), substitutionMap, null).runPass(); Map<String, String> mapping = replacementsWithPrefix.get(""); mapping = Maps.newHashMap(Maps.filterKeys(mapping, Predicates.in(substitutionMap .getStyleClasses()))); return new RenamingResult(mapping, substitutionMap.getExternalClassCandidates()); }
public static Map<Class<?>, RestyJsonTypeIdResolver> getRestyResolverClassMap(GeneratorContext context, TreeLogger logger) throws UnableToCompleteException { if (sTypeIdResolverMap == null) { try { Map<Class<?>, RestyJsonTypeIdResolver> map = Maps.newHashMap(); List<String> values = context.getPropertyOracle().getConfigurationProperty("org.fusesource.restygwt.jsontypeidresolver") .getValues(); for (String value : values) { try { Class<?> clazz = Class.forName(value); RestyJsonTypeIdResolver resolver = (RestyJsonTypeIdResolver) clazz.newInstance(); map.put(resolver.getTypeIdResolverClass(), resolver); } catch (Exception e) { logger.log(WARN, "Could not access class: " + values.get(0), e); } } sTypeIdResolverMap = map; } catch (BadPropertyValueException e) { logger.log(ERROR, "Could not acccess property: RestyJsonTypeIdResolver", e); throw new UnableToCompleteException(); } } return sTypeIdResolverMap; }
private RenamingResult doClassRenaming(CssTree cssTree, JMethod method, TreeLogger logger, ResourceContext context) throws UnableToCompleteException { Map<String, Map<String, String>> replacementsWithPrefix = computeReplacements(method, logger, context); RenamingSubstitutionMap substitutionMap = new RenamingSubstitutionMap(replacementsWithPrefix); new CssClassRenaming(cssTree.getMutatingVisitController(), substitutionMap, null).runPass(); Map<String, String> mapping = replacementsWithPrefix.get(""); mapping = Maps.newHashMap(Maps.filterKeys(mapping, Predicates.in(substitutionMap .getStyleClasses()))); return new RenamingResult(mapping, substitutionMap.getExternalClassCandidates()); }
@Override protected void setUp() throws Exception { super.setUp(); LocalWaveletContainer.Factory localFactory = mock(LocalWaveletContainer.Factory.class); WaveletNotificationSubscriber notifiee = mock(WaveletNotificationSubscriber.class); SettableFuture<ImmutableSet<WaveletId>> lookedupWavelets = SettableFuture.create(); lookedupWavelets.set(ImmutableSet.of(WAVELET_NAME.waveletId)); Wave wave = new Wave(WAVELET_NAME.waveId, lookedupWavelets, notifiee, localFactory, null, WAVELET_NAME.waveId.getDomain()); Map<WaveId, Wave> waves = Maps.newHashMap(); waves.put(WAVELET_NAME.waveId, wave); when(waveMap.getWaves()).thenReturn(waves); ImmutableSet<WaveletId> wavelets = ImmutableSet.of(WAVELET_NAME.waveletId); when(waveMap.lookupWavelets(WAVELET_NAME.waveId)).thenReturn(wavelets); LocalWaveletContainer c = mock(LocalWaveletContainer.class); when(c.hasParticipant(PARTICIPANT)).thenReturn(true); when(waveMap.getLocalWavelet(WAVELET_NAME)).thenReturn(c); }
@Override protected void setUp() throws Exception { super.setUp(); LocalWaveletContainer.Factory localFactory = mock(LocalWaveletContainer.Factory.class); WaveletNotificationSubscriber notifiee = mock(WaveletNotificationSubscriber.class); SettableFuture<ImmutableSet<WaveletId>> lookedupWavelets = SettableFuture.create(); lookedupWavelets.set(ImmutableSet.of(WAVELET_NAME.waveletId)); Wave wave = new Wave(WAVELET_NAME.waveId, lookedupWavelets, notifiee, localFactory, null, WAVELET_NAME.waveId.getDomain()); Map<WaveId, Wave> waves = Maps.newHashMap(); waves.put(WAVELET_NAME.waveId, wave); when(waveMap.getWaves()).thenReturn(waves); ImmutableSet<WaveletId> wavelets = ImmutableSet.of(WAVELET_NAME.waveletId); when(waveMap.lookupWavelets(WAVELET_NAME.waveId)).thenReturn(wavelets); LocalWaveletContainer c = mock(LocalWaveletContainer.class); when(c.hasParticipant(PARTICIPANT)).thenReturn(true); when(waveMap.getLocalWavelet(WAVELET_NAME)).thenReturn(c); }