public String getName() { return mp.getName(); }
public RankableField(String name, MetaProperty mp) { this.f = mp; this.score = delDistance(name,mp.getName()); }
/** * Returns a string detailing possible solutions to a missing field or property * if no good solutions can be found a empty string is returned. * * @param fieldName the missing field * @param type the class on which the field is sought * @return a string with probable solutions to the exception */ public static String getPropertySuggestionString(String fieldName, Class type){ ClassInfo ci = ClassInfo.getClassInfo(type); List<MetaProperty> fi = ci.getMetaClass().getProperties(); List<RankableField> rf = new ArrayList<RankableField>(fi.size()); StringBuilder sb = new StringBuilder(); sb.append("\nPossible solutions: "); for(MetaProperty mp : fi) rf.add(new RankableField(fieldName, mp)); Collections.sort(rf); int i = 0; for (RankableField f : rf) { if (i > MAX_RECOMENDATIONS) break; if (f.score > MAX_FIELD_SCORE) break; if(i > 0) sb.append(", "); sb.append(f.f.getName()); i++; } return i > 0? sb.toString(): ""; }
public MixinInstanceMetaProperty(MetaProperty property, MixinInMetaClass mixinInMetaClass) { super(property.getName(), property.getType(), createGetter(property, mixinInMetaClass), createSetter(property, mixinInMetaClass)); }
private static MetaMethod createGetter(final MetaProperty property, final MixinInMetaClass mixinInMetaClass) { return new MetaMethod() { final String name = getGetterName(property.getName(), property.getType()); { setParametersTypes (CachedClass.EMPTY_ARRAY); } public int getModifiers() { return Modifier.PUBLIC; } public String getName() { return name; } public Class getReturnType() { return property.getType(); } public CachedClass getDeclaringClass() { return mixinInMetaClass.getInstanceClass(); } public Object invoke(Object object, Object[] arguments) { return property.getProperty(mixinInMetaClass.getMixinInstance(object)); } }; } }
private static MetaMethod createSetter(final MetaProperty property, final MixinInMetaClass mixinInMetaClass) { return new MetaMethod() { final String name = getSetterName(property.getName()); { setParametersTypes (new CachedClass [] {ReflectionCache.getCachedClass(property.getType())} ); } public int getModifiers() { return Modifier.PUBLIC; } public String getName() { return name; } public Class getReturnType() { return property.getType(); } public CachedClass getDeclaringClass() { return mixinInMetaClass.getInstanceClass(); } public Object invoke(Object object, Object[] arguments) { property.setProperty(mixinInMetaClass.getMixinInstance(object), arguments[0]); return null; } }; }
final List<MetaProperty> propList = metaClass.getProperties(); for (MetaProperty prop : propList) if (self.getMetaProperty(prop.getName()) == null) { mc.registerBeanProperty(prop.getName(), new MixinInstanceMetaProperty(prop, mixin)); if (self.getMetaProperty(prop.getName()) == null) { mc.registerBeanProperty(prop.getName(), new MixinInstanceMetaProperty(prop, mixin));
public String getName() { return mp.getName(); }
public String getName() { return mp.getName(); }
public String getName() { return mp.getName(); }
public String getName() { return mp.getName(); }
public RankableField(String name, MetaProperty mp) { this.f = mp; this.score = delDistance(name,mp.getName()); }
public List<PropertyDescriptor> getPropertiesOfType(Class javaClass) { List<MetaProperty> properties = theMetaClass.getProperties(); List<PropertyDescriptor> propertyDescriptors = new ArrayList<>(2); for (MetaProperty property : properties) { int modifiers = property.getModifiers(); if(Modifier.isStatic(modifiers) || property.getName().contains("$") || !property.getType().equals(javaClass)) continue; addBeanProperty(propertyDescriptors, property); } return propertyDescriptors; }
@SuppressWarnings("unchecked") public List<PropertyDescriptor> getPropertiesAssignableFromType(Class assignableType) { List<MetaProperty> properties = theMetaClass.getProperties(); List<PropertyDescriptor> propertyDescriptors = new ArrayList<>(2); for (MetaProperty property : properties) { int modifiers = property.getModifiers(); if(Modifier.isStatic(modifiers) || property.getName().contains("$") || !property.getType().isAssignableFrom( assignableType )) continue; addBeanProperty(propertyDescriptors, property); } return propertyDescriptors; }
@SuppressWarnings("unchecked") public List<PropertyDescriptor> getPropertiesAssignableToType(Class assignableType) { List<MetaProperty> properties = theMetaClass.getProperties(); List<PropertyDescriptor> propertyDescriptors = new ArrayList<>(2); for (MetaProperty property : properties) { int modifiers = property.getModifiers(); if(Modifier.isStatic(modifiers) || property.getName().contains("$") || !assignableType.isAssignableFrom(property.getType())) { continue; } addBeanProperty(propertyDescriptors, property); } return propertyDescriptors; }
private void initGroovyCommands(final ScriptEngine scriptEngine, final ScriptContext scriptContext) { Commands commands = new Commands(scriptContext); for (MetaProperty mp : commands.getMetaClass().getProperties()) { String propertyType = mp.getType().getCanonicalName(); String propertyName = mp.getName(); if (propertyType.equals(groovy.lang.Closure.class.getCanonicalName())) { scriptEngine.put(propertyName, commands.getProperty(propertyName)); } } }
public MixinInstanceMetaProperty(MetaProperty property, MixinInMetaClass mixinInMetaClass) { super(property.getName(), property.getType(), createGetter(property, mixinInMetaClass), createSetter(property, mixinInMetaClass)); }
public MixinInstanceMetaProperty(MetaProperty property, MixinInMetaClass mixinInMetaClass) { super(property.getName(), property.getType(), createGetter(property, mixinInMetaClass), createSetter(property, mixinInMetaClass)); }
public MixinInstanceMetaProperty(MetaProperty property, MixinInMetaClass mixinInMetaClass) { super(property.getName(), property.getType(), createGetter(property, mixinInMetaClass), createSetter(property, mixinInMetaClass)); }