@Kroll.method public void deselectAnnotation(Object[] args) { String title = null; AnnotationProxy selectedAnnotation = null; if (args.length > 0) { if (args[0] instanceof AnnotationProxy) { selectedAnnotation = (AnnotationProxy) args[0]; title = TiConvert.toString(selectedAnnotation.getProperty("title")); } else if (args[0] instanceof String) { title = TiConvert.toString(args[0]); } } if (title != null) { boolean animate = false; if (args.length > 1) { animate = TiConvert.toBoolean(args[1]); } if (mapView == null) { int numSelectedAnnotations = selectedAnnotations.size(); for (int i = 0; i < numSelectedAnnotations; i++) { if ((selectedAnnotations.get(i)).title.equals(title)) { selectedAnnotations.remove(i); } } } else { mapView.selectAnnotation(false, title, selectedAnnotation, animate, false); } } }
@Kroll.method public void removeAnnotation(Object arg) { String title = null; AnnotationProxy annotation = null; if (arg != null) { if (arg instanceof AnnotationProxy) { annotation = (AnnotationProxy) arg; title = TiConvert.toString(annotation.getProperty(TiC.PROPERTY_TITLE)); } else { title = TiConvert.toString(arg); } if (title != null) { int existsIndex = findAnnotation(title, annotation); if (existsIndex > -1) { annotations.get(existsIndex).setViewProxy(null); annotations.remove(existsIndex); } if (mapView != null) { mapView.updateAnnotations(); } } } }
protected int findAnnotation(String title, AnnotationProxy annotation) { int existsIndex = -1; // Check for existence int len = annotations.size(); if (annotation != null) { for (int i = 0; i < len && existsIndex == -1; i++) { if (annotation == annotations.get(i)) { existsIndex = i; break; } } } for (int i = 0; i < len && existsIndex == -1; i++) { AnnotationProxy a = annotations.get(i); String t = (String) a.getProperty(TiC.PROPERTY_TITLE); if (t != null) { if (title.equals(t)) { existsIndex = i; break; } } } return existsIndex; }
@Kroll.method public void selectAnnotation(Object[] args) { AnnotationProxy selAnnotation = null; String title = null; boolean animate = false; boolean center = true; // keep existing default behavior if (args != null && args.length > 0) { if (args[0] instanceof HashMap) { HashMap<String, Object> params = (HashMap) args[0]; Object selectedAnnotation = params.get(TiC.PROPERTY_ANNOTATION); if (selectedAnnotation instanceof AnnotationProxy) { selAnnotation = (AnnotationProxy) selectedAnnotation; title = TiConvert.toString(selAnnotation.getProperty(TiC.PROPERTY_TITLE)); } else { title = TiConvert.toString(params, TiC.PROPERTY_TITLE); } Object animateProperty = params.containsKey(TiC.PROPERTY_ANIMATE); if (animateProperty != null) { animate = TiConvert.toBoolean(animateProperty); } Object centerProperty = params.containsKey(TiC.PROPERTY_CENTER); if (centerProperty != null) { center = TiConvert.toBoolean(centerProperty); } } else { if (args[0] instanceof AnnotationProxy) { selAnnotation = (AnnotationProxy) args[0]; title = TiConvert.toString(selAnnotation.getProperty(TiC.PROPERTY_TITLE)); } else if (args[0] instanceof String) { title = TiConvert.toString(args[0]); } if (args.length > 1) { animate = TiConvert.toBoolean(args[1]); } } } if (title != null) { if (mapView == null) { Log.i(TAG, "calling selectedAnnotations.add", Log.DEBUG_MODE); selectedAnnotations.add( new TiMapView.SelectedAnnotation(title, selAnnotation, animate, center)); } else { Log.i(TAG, "calling selectedAnnotations.add2", Log.DEBUG_MODE); mapView.selectAnnotation(true, title, selAnnotation, animate, center); } } }
@Kroll.method public void addAnnotation(AnnotationProxy annotation) { annotation.setViewProxy(this); annotations.add(annotation); if (mapView != null) { mapView.updateAnnotations(); } }
@Override public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) { org.jboss.forge.parser.java.Annotation<?> annotation = null; // https://issues.jboss.org/browse/FORGE-439: support annotations on readMethod if (this.readMethod != null) { annotation = this.readMethod.getAnnotation(annotationClass.getName()); } if (annotation == null && this.privateField != null) { annotation = this.privateField.getAnnotation(annotationClass.getName()); } if (annotation != null) { T annotationProxy = AnnotationProxy.newInstance(annotation); return annotationProxy; } return null; }
private Map<Class<? extends Annotation>, Annotation> initAnnotations( String componentName, String propertyName, Map<String, Map<String, Object>> annotationsInfo) { final Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>(); if (annotationsInfo == null) { return annotations; } for (Map.Entry<String, Map<String, Object>> annInfoE : annotationsInfo.entrySet()) { try { @SuppressWarnings("unchecked") final Class<? extends Annotation> anClass = (Class<? extends Annotation>) Class.forName(annInfoE.getKey()); final Map<String, Object> anProperties = annInfoE.getValue(); final Annotation anProxy = AnnotationProxy.newAnnotation(anClass, anProperties); annotations.put(anClass, anProxy); } catch (Exception e) { logger.warn( "Cannot create annotation '{}' for component '{}' property '{}'", annInfoE.getKey(), componentName, propertyName); } } return annotations; }
/** * Parses the given literal value into the given returnType. Supports all standard annotation * types (JLS 9.7). */ private Object parse(String literalValue, Class<?> returnType) throws ClassNotFoundException { // Primitives if (byte.class.equals(returnType)) { return Byte.valueOf(literalValue); } if (short.class.equals(returnType)) { return Short.valueOf(literalValue); } if (int.class.equals(returnType)) { return Integer.valueOf(literalValue); } if (long.class.equals(returnType)) { String valueToUse = literalValue; if (valueToUse.endsWith("l") || valueToUse.endsWith("L")) { valueToUse = valueToUse.substring(0, valueToUse.length() - 1); } return Long.valueOf(valueToUse); } if (float.class.equals(returnType)) { String valueToUse = literalValue; if (valueToUse.endsWith("f") || valueToUse.endsWith("F")) { valueToUse = valueToUse.substring(0, valueToUse.length() - 1); } return Float.valueOf(valueToUse); } if (double.class.equals(returnType)) { String valueToUse = literalValue; if (valueToUse.endsWith("d") || valueToUse.endsWith("D")) { valueToUse = literalValue.substring(0, valueToUse.length() - 1); } return Double.valueOf(valueToUse); } if (boolean.class.equals(returnType)) { return Boolean.valueOf(literalValue); } if (char.class.equals(returnType)) { return Character.valueOf(literalValue.charAt(1)); } // Arrays if (returnType.isArray()) { String[] values = literalValue.substring(1, literalValue.length() - 1).split(","); int length = values.length; Class<?> componentType = returnType.getComponentType(); Object array = Array.newInstance(componentType, length); for (int loop = 0; loop < length; loop++) { Array.set(array, loop, parse(values[loop], componentType)); } return array; } // Enums if (returnType.isEnum()) { Enum<?>[] constants = (Enum<?>[]) returnType.getEnumConstants(); String valueToUse = StringUtils.substringAfterLast(literalValue, '.'); for (Enum<?> inst : constants) { if (inst.name().equals(valueToUse)) { return inst; } } return null; } // Strings if (String.class.equals(returnType)) { return literalValue.substring(1, literalValue.length() - 1); } // Classes if (Class.class.equals(returnType)) { String resolvedType = StringUtils.substringBefore(literalValue, ".class"); resolvedType = ((JavaSource<?>) this.annotationSource.getOrigin()).resolveType(resolvedType); return Class.forName(resolvedType); } // Annotations if (Annotation.class.isAssignableFrom(returnType)) { String resolvedType = StringUtils.substringAfter(literalValue, "@"); resolvedType = ((JavaSource<?>) this.annotationSource.getOrigin()).resolveType(resolvedType); return AnnotationProxy.newInstance(this.annotationSource); } // Unknown throw new UnsupportedOperationException(returnType.getSimpleName()); }
public static TiAnnotation fromAnnotationProxy(AnnotationProxy ap) { return fromDict(ap.getProperties()); }