コード例 #1
0
 @Override
 public TypeUsageNode getFieldType(String fieldName, boolean staticContext) {
   for (Property property : getAllProperties(symbolResolver())) {
     if (property.getName().equals(fieldName)) {
       return property.getTypeUsage();
     }
   }
   throw new IllegalArgumentException(fieldName);
 }
コード例 #2
0
 public List<Property> getDirectProperties(SymbolResolver resolver) {
   List<Property> properties = new ArrayList<>();
   for (Node member : members) {
     if (member instanceof PropertyDefinition) {
       properties.add(Property.fromDefinition((PropertyDefinition) member));
     } else if (member instanceof PropertyReference) {
       properties.add(Property.fromReference((PropertyReference) member, resolver));
     }
   }
   return properties;
 }
コード例 #3
0
  @Override
  public Optional<Symbol> findSymbol(String name, SymbolResolver resolver) {
    // TODO support references to methods
    for (Property property : this.getAllProperties(resolver)) {
      if (property.getName().equals(name)) {
        return Optional.of(property);
      }
    }

    return super.findSymbol(name, resolver);
  }
コード例 #4
0
 private void initializeMethodsByName(SymbolResolver resolver) {
   methodsByName = new HashMap<>();
   // TODO methods inherited by Object
   // TODO if we implement inheritance also other methods inherited from classes or interfaces
   for (Property property : getDirectProperties(resolver)) {
     {
       String descriptor = "()" + property.getTypeUsage().jvmType().getDescriptor();
       JvmMethodDefinition jvmMethodDefinition =
           new JvmMethodDefinition(
               getInternalName(), property.getterName(resolver), descriptor, false, false);
       InternalMethodDefinition getter =
           new InternalMethodDefinition(
               property.getterName(resolver),
               Collections.emptyList(),
               property.getTypeUsage(),
               jvmMethodDefinition);
       registerMethod(getter);
     }
     {
       String descriptor = "(" + property.getTypeUsage().jvmType().getDescriptor() + ")V";
       JvmMethodDefinition jvmMethodDefinition =
           new JvmMethodDefinition(
               getInternalName(), property.setterName(), descriptor, false, false);
       FormalParameterNode param =
           new FormalParameterNode(property.getTypeUsage().copy(), property.getName());
       param.setParent(this);
       InternalMethodDefinition setter =
           new InternalMethodDefinition(
               property.setterName(),
               ImmutableList.of(param),
               new VoidTypeUsageNode(),
               jvmMethodDefinition);
       registerMethod(setter);
     }
   }
 }