public String getFieldNameForKeyCode(int keyCode) { if (keyNamesByCode == null) { keyNamesByCode = new HashMap<>(); List<VariableElement> keyEventEnclosedFieldElements = getKeyEventEnclosedFieldElements(); for (VariableElement element : keyEventEnclosedFieldElements) { if (element.getSimpleName().toString().contains(KEYCODE_PREFIX)) { keyNamesByCode.put((Integer) element.getConstantValue(), element.getSimpleName().toString()); } } } return keyNamesByCode.get(keyCode); }
public int getKeyCodeForName(String fieldName) { if (keyCodesByName == null) { keyCodesByName = new HashMap<>(); List<VariableElement> keyEventEnclosedFieldElements = getKeyEventEnclosedFieldElements(); for (VariableElement element : keyEventEnclosedFieldElements) { if (element.getSimpleName().toString().contains(KEYCODE_PREFIX)) { keyCodesByName.put(element.getSimpleName().toString(), (Integer) element.getConstantValue()); } } } Integer keyCode = keyCodesByName.get(fieldName); return keyCode != null ? keyCode : KEYCODE_NOT_FOUND; }
private Long findSerialVersionUID() { for (VariableElement field : ElementFilter.fieldsIn(element.getEnclosedElements())) { if (field.getSimpleName().contentEquals(SERIAL_VERSION_FIELD_NAME) && field.asType().getKind() == TypeKind.LONG) { return (Long) field.getConstantValue(); } } return null; }
public RInnerClass(TypeElement rInnerTypeElement) { if (rInnerTypeElement != null) { rInnerQualifiedName = rInnerTypeElement.getQualifiedName().toString(); List<? extends Element> idEnclosedElements = rInnerTypeElement.getEnclosedElements(); List<VariableElement> idFields = ElementFilter.fieldsIn(idEnclosedElements); for (VariableElement idField : idFields) { TypeKind fieldType = idField.asType().getKind(); if (fieldType.isPrimitive() && fieldType.equals(TypeKind.INT)) { String idQualifiedName = rInnerQualifiedName + "." + idField.getSimpleName(); idQualifiedNames.add(idQualifiedName); Integer idFieldId = (Integer) idField.getConstantValue(); if (idFieldId != null) { idQualifiedNamesByIdValues.put(idFieldId, idQualifiedName); } } } } else { rInnerQualifiedName = ""; } }
private static boolean hasNonNullConstantValue(LocalVariableNode node) { if (node.getElement() instanceof VariableElement) { VariableElement element = (VariableElement) node.getElement(); return (element.getConstantValue() != null); } return false; }
private static boolean hasNonNullConstantValue(LocalVariableNode node) { if (node.getElement() instanceof VariableElement) { VariableElement element = (VariableElement) node.getElement(); return (element.getConstantValue() != null); } return false; }
TypedMember(VariableElement variable, int position) { element = Assert.notNull(variable, "field"); name = variable.getSimpleName().toString(); hasInitialValue = variable.getConstantValue() != null; typeInfo = new CompileTimeTypeInfo(variable.asType()); this.position = position; getter = new GetterSetterMetaData(element); setter = (GetterSetterMetaData) getter; }
private ResourceValue parseResourceSymbol(VariableElement symbol) { TypeElement resourceClass = (TypeElement) symbol.getEnclosingElement(); // eg com.airbnb.epoxy.R String rClass = ((TypeElement) resourceClass.getEnclosingElement()).getQualifiedName().toString(); // eg com.airbnb.epoxy.R.layout String resourceClassName = resourceClass.getQualifiedName().toString(); // Make sure this is the right resource type if (!(rClass + "." + resourceType).equals(resourceClassName)) { errorLogger .logError("%s annotation requires a %s resource but received %s. (Element: %s)", annotationClass.getSimpleName(), resourceType, resourceClass, element.getSimpleName()); return null; } // eg button_layout, as in R.layout.button_layout String resourceName = symbol.getSimpleName().toString(); Object resourceValue = symbol.getConstantValue(); if (!(resourceValue instanceof Integer)) { errorLogger.logError("%s annotation requires an int value but received %s. (Element: %s)", annotationClass.getSimpleName(), symbol.getSimpleName(), element.getSimpleName()); return null; } ClassName rClassName = getClassName(resourceClassName, resourceType); saveResourceValuesForRClass(rClassName, resourceClass); return new ResourceValue(rClassName, resourceName, (int) resourceValue); }
String type = "0"; String level = "0"; types.put(type, variableMember.getConstantValue().toString()); levels.put(level, types); int headerResId = defaultTypeAnno.headerResId(); String level = variableMember.getConstantValue().toString(); Map<String, String> types = new HashMap<>(); int[] type = allTypeAnno.type(); String level = variableMember.getConstantValue().toString(); Map<String, String> types = new HashMap<>(); int[] type = typeAnno.type(); int level = layoutResAnno.level(); Map<String, String> types = new HashMap<>(); types.put(String.valueOf(type), variableMember.getConstantValue().toString()); levels.put(String.valueOf(level), types); int[] headerLevels = headerResAnno.level(); for (int level : headerLevels) { headerRess.put(String.valueOf(level), variableMember.getConstantValue().toString()); int[] loadingLayoutLevels = loadingLayoutResAnno.level(); for (int level : loadingLayoutLevels) { loadingLayoutRess.put(String.valueOf(level), variableMember.getConstantValue().toString()); int[] loadingHeaderLevels = loadingHeaderResAnno.level(); for (int level : loadingHeaderLevels) {
key = var.getConstantValue().toString(); } else if (e.getKind() == ElementKind.CLASS) { if (!isAssignable(e.asType(), actionListener)) {
@Override public Object getConstantValue() { return parent.getConstantValue(); }
@Override public Object getConstantValue() { return variableElement.getConstantValue(); }
@Override public Object getConstantValue() { return variableElement.getConstantValue(); }
@Override public Object getConstantValue() { return this.delegate.getConstantValue(); }
private boolean isConstant(Element e) { if (e == null) return false; switch (e.getKind()) { case FIELD: Object value = ((VariableElement) e).getConstantValue(); return (value != null); // can't distinguish "not a constant" from "constant is null" default: return false; } }
private boolean isConstant(Element e) { if (e == null) return false; switch (e.getKind()) { case FIELD: Object value = ((VariableElement) e).getConstantValue(); return (value != null); // can't distinguish "not a constant" from "constant is null" default: return false; } }
private static boolean hasNonNullConstantValue(LocalVariableNode node) { if (node.getElement() instanceof VariableElement) { VariableElement element = (VariableElement) node.getElement(); return (element.getConstantValue() != null); } return false; }
@Override protected void doVisitField(JavaFieldElement oldField, JavaFieldElement newField) { if (!isBothAccessible(oldField, newField)) { return; } if (oldField.getDeclaringElement().getConstantValue() == null && newField.getDeclaringElement().getConstantValue() != null) { pushActive(oldField, newField); } }
@Override protected List<Difference> doEnd() { ActiveElements<JavaFieldElement> fields = popIfActive(); if (fields == null) { return null; } return Collections.singletonList( createDifference(Code.FIELD_NO_LONGER_CONSTANT, Code.attachmentsFor(fields.oldElement, fields.newElement, "value", Objects.toString(fields.oldElement.getDeclaringElement().getConstantValue())))); } }
public void copyConstants(TypeElement element) { List<VariableElement> fields = ElementFilter.fieldsIn(element.getEnclosedElements()); for (VariableElement field: fields) { if (field.getModifiers().contains(Modifier.STATIC) && field.getModifiers().contains(Modifier.FINAL)) { MutableDeclaredTypeValue constantValue = processingEnv.getTypeUtils().getDeclaredValue( (MutableDeclaredType) processingEnv.getTypeUtils().toMutableType(field.asType()), field.getConstantValue()); pw.println("public static final ", field.asType(), " " + field.getSimpleName().toString() + " = ", constantValue, ";"); pw.println(); } } } }