private String fieldFullName( VariableElement field ) { return String.format( "%s#%s", field.getEnclosingElement().getSimpleName(), field.getSimpleName() ); }
@Override public Void visitEnumConstant(VariableElement c, Void p) { builder.append(c.getEnclosingElement()).append('.').append(c.getSimpleName()); return null; }
private static Stream<CompilationMessage> validateNonContextField( VariableElement field ) { Set<Modifier> modifiers = field.getModifiers(); if ( !modifiers.contains( Modifier.STATIC ) ) { return Stream.of( new FieldError( field, "Field %s#%s should be static", field.getEnclosingElement().getSimpleName(), field.getSimpleName() ) ); } return Stream.empty(); }
private boolean isValidUsageOfNavigationModelField(VariableElement element) { final TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); boolean valid = true; // Verify modifiers. Set<Modifier> modifiers = element.getModifiers(); if (modifiers.contains(PRIVATE) || modifiers.contains(STATIC)) { loggingUtil.error( element, "@DartModel field must not be private or static. (%s.%s)", enclosingElement.getQualifiedName(), element.getSimpleName()); valid = false; } return valid; } }
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); }
@Override public Stream<CompilationMessage> visitVariable( VariableElement parameter, Void ignored ) { Name annotation = parameter.getAnnotation( Name.class ); if ( annotation == null ) { return Stream.of( new ParameterMissingAnnotationError( parameter, annotationMirror( parameter.getAnnotationMirrors() ), "@%s usage error: missing on parameter <%s>", Name.class.getName(), nameOf( parameter ) ) ); } if ( !parameterTypeVisitor.visit( parameter.asType() ) ) { Element method = parameter.getEnclosingElement(); return Stream.of( new ParameterTypeError( parameter, "Unsupported parameter type <%s> of " + "procedure|function" + " %s#%s", parameter.asType().toString(), method.getEnclosingElement().getSimpleName(), method.getSimpleName() ) ); } return Stream.empty(); }
private void parseNavigationModelField( VariableElement element, Map<TypeElement, NavigationModelBindingTarget> targetClassMap) { final TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); if (targetClassMap.containsKey(enclosingElement)) { loggingUtil.error( enclosingElement, "Component %s cannot bind more than one NavigationModel.", enclosingElement.getSimpleName()); return; } // Verify common generated code restrictions. if (!isValidUsageOfNavigationModelField(element)) { return; } // Assemble information on the binding point. final NavigationModelBindingTarget navigationModelBindingTarget = navigationModelBindingTargetUtil.createTargetClass(enclosingElement, element); targetClassMap.put(enclosingElement, navigationModelBindingTarget); }
private void checkForMutableFields(Protoclass protoclass, TypeElement element) { Elements elementUtils = protoclass.environment().processing().getElementUtils(); for (VariableElement field : ElementFilter.fieldsIn( elementUtils.getAllMembers(CachingElements.getDelegate(element)))) { if (!field.getModifiers().contains(Modifier.FINAL)) { Reporter report = protoclass.report(); boolean ownField = CachingElements.equals(element, field.getEnclosingElement()); if (ownField) { report.withElement(field) .warning(About.INCOMPAT, "Avoid introduction of fields (except constants) in abstract value types"); } else { report.warning(About.INCOMPAT, "Abstract value type inherits mutable fields"); } } } }
VariableElement ve = (VariableElement)getElement(vt); if (ve.getEnclosingElement().getKind() == ElementKind.CLASS) {
@Override public Void visitVariable(VariableElement e, Void p) { TypeElement dt = (TypeElement) e.getEnclosingElement(); optionBeans.add(dt); return null; }
@Override public Element getTargetElement() { return getVariable().getEnclosingElement(); }
private void createFactoriesForClassesWithInjectAnnotatedFields(RoundEnvironment roundEnv) { for (VariableElement fieldElement : ElementFilter.fieldsIn(roundEnv.getElementsAnnotatedWith(Inject.class))) { processClassContainingInjectAnnotatedMember(fieldElement.getEnclosingElement(), mapTypeElementToConstructorInjectionTarget); } }
private void processInjectAnnotatedField(VariableElement fieldElement, Map<TypeElement, List<FieldInjectionTarget>> mapTypeElementToMemberInjectorTargetList) { TypeElement enclosingElement = (TypeElement) fieldElement.getEnclosingElement(); // Verify common generated code restrictions. if (!isValidInjectAnnotatedFieldOrParameter(fieldElement)) { return; } List<FieldInjectionTarget> fieldInjectionTargetList = mapTypeElementToMemberInjectorTargetList.get(enclosingElement); if (fieldInjectionTargetList == null) { fieldInjectionTargetList = new ArrayList<>(); mapTypeElementToMemberInjectorTargetList.put(enclosingElement, fieldInjectionTargetList); } mapTypeToMostDirectSuperTypeThatNeedsInjection(enclosingElement); fieldInjectionTargetList.add(createFieldOrParamInjectionTarget(fieldElement)); }
Element enclosingElement = injectedTypeElement.getEnclosingElement(); final String typeName; if (typeElement != null) {
protected void processInjectAnnotatedFields(RoundEnvironment roundEnv) { for (VariableElement element : ElementFilter.fieldsIn(roundEnv.getElementsAnnotatedWith(Inject.class))) { if (!isExcludedByFilters((TypeElement) element.getEnclosingElement())) { processInjectAnnotatedField(element, mapTypeElementToFieldInjectorTargetList); } } }
protected boolean isValidInjectAnnotatedFieldOrParameter(VariableElement variableElement) { TypeElement enclosingElement = (TypeElement) variableElement.getEnclosingElement(); // Verify modifiers. Set<Modifier> modifiers = variableElement.getModifiers(); if (modifiers.contains(PRIVATE)) { error(variableElement, "@Inject annotated fields must be non private : %s#%s", enclosingElement.getQualifiedName(), variableElement.getSimpleName()); return false; } // Verify parentScope modifiers. Set<Modifier> parentModifiers = enclosingElement.getModifiers(); if (parentModifiers.contains(PRIVATE)) { error(variableElement, "@Injected fields in class %s. The class must be non private.", enclosingElement.getSimpleName()); return false; } if (!isValidInjectedType(variableElement)) { return false; } return true; }
@Override public StringBuilder visitVariable(VariableElement e, Boolean p) { if (p != Boolean.TRUE || e.getEnclosingElement() == null) { return DEFAULT_VALUE.append(e.getSimpleName()); } else { return e.getEnclosingElement().accept(this, p). append("."). append(e.getSimpleName()); } }
@Override public String resolveFieldLink(VariableElement elt, Coordinate coordinate) { TypeElement typeElt = (TypeElement) elt.getEnclosingElement(); String link = resolveTypeLink(typeElt, null); return link + "#" + elt.getSimpleName(); }
protected VariableTree createEnhancedForLoopArrayVariable( ExpressionTree expression, VariableElement variableElement) { TypeMirror arrayType = TreeUtils.typeOf(expression); // Declare and initialize a temporary array variable VariableTree arrayVariable = treeBuilder.buildVariableDecl( arrayType, uniqueName("array"), variableElement.getEnclosingElement(), expression); return arrayVariable; }
@Test public void testResolveFieldSignature() throws Exception { Utils.assertProcess((processingEnv, roundEnv) -> { Element elt = Helper.resolveSignature(processingEnv.getElementUtils(), processingEnv.getTypeUtils(), null, "java.util.Locale#FRENCH"); assertEquals(ElementKind.FIELD, elt.getKind()); VariableElement varElt = (VariableElement) elt; TypeElement typeElt = (TypeElement) varElt.getEnclosingElement(); assertEquals("java.util.Locale", typeElt.getQualifiedName().toString()); assertEquals("FRENCH", varElt.getSimpleName().toString()); }); }