Java Code Examples for org.eclipse.xtend.lib.macro.declaration.FieldDeclaration#getSimpleName()

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.FieldDeclaration#getSimpleName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessorsProcessor.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
public List<String> getPossibleGetterNames(final FieldDeclaration it) {
  final ArrayList<String> names = CollectionLiterals.<String>newArrayList();
  if ((((this.isBooleanType(this.orObject(it.getType())) && it.getSimpleName().startsWith("is")) && (it.getSimpleName().length() > 2)) && Character.isUpperCase(it.getSimpleName().charAt(2)))) {
    String _simpleName = it.getSimpleName();
    names.add(_simpleName);
  }
  List<String> _xifexpression = null;
  boolean _isBooleanType = this.isBooleanType(this.orObject(it.getType()));
  if (_isBooleanType) {
    _xifexpression = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("is", "get"));
  } else {
    _xifexpression = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("get"));
  }
  final Function1<String, String> _function = (String prefix) -> {
    String _firstUpper = StringExtensions.toFirstUpper(it.getSimpleName());
    return (prefix + _firstUpper);
  };
  names.addAll(ListExtensions.<String, String>map(_xifexpression, _function));
  return names;
}
 
Example 2
Source File: ExternalizedProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doGenerateCode(final List<? extends ClassDeclaration> annotatedSourceElements, @Extension final CodeGenerationContext context) {
  for (final ClassDeclaration clazz : annotatedSourceElements) {
    {
      final Path filePath = clazz.getCompilationUnit().getFilePath();
      Path _targetFolder = context.getTargetFolder(filePath);
      String _replace = clazz.getQualifiedName().replace(".", "/");
      String _plus = (_replace + ".properties");
      final Path file = _targetFolder.append(_plus);
      StringConcatenation _builder = new StringConcatenation();
      {
        Iterable<? extends FieldDeclaration> _declaredFields = clazz.getDeclaredFields();
        for(final FieldDeclaration field : _declaredFields) {
          String _simpleName = field.getSimpleName();
          _builder.append(_simpleName);
          _builder.append(" = ");
          String _initializerAsString = this.getInitializerAsString(field);
          _builder.append(_initializerAsString);
          _builder.newLineIfNotEmpty();
        }
      }
      context.setContents(file, _builder);
    }
  }
}
 
Example 3
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence _delegateAccess(final FieldDeclaration it, final MethodDeclaration method) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("this.");
  String _simpleName = it.getSimpleName();
  _builder.append(_simpleName);
  return _builder;
}
 
Example 4
Source File: JvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public FieldDeclaration findDeclaredField(final String name) {
  final Function1<FieldDeclaration, Boolean> _function = (FieldDeclaration it) -> {
    String _simpleName = it.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  return IterableExtensions.<FieldDeclaration>findFirst(Iterables.<FieldDeclaration>filter(this.getDeclaredMembers(), FieldDeclaration.class), _function);
}
 
Example 5
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public FieldDeclaration findDeclaredField(final String name) {
  final Function1<FieldDeclaration, Boolean> _function = (FieldDeclaration field) -> {
    String _simpleName = field.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  return IterableExtensions.findFirst(this.getDeclaredFields(), _function);
}
 
Example 6
Source File: XtendTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public FieldDeclaration findDeclaredField(final String name) {
  final Function1<FieldDeclaration, Boolean> _function = (FieldDeclaration field) -> {
    String _simpleName = field.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  return IterableExtensions.findFirst(this.getDeclaredFields(), _function);
}
 
Example 7
Source File: ToStringProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public void addToString(final MutableClassDeclaration cls, final Iterable<? extends FieldDeclaration> fields, final ToStringConfiguration config) {
  final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
    this.context.setPrimarySourceElement(it, this.context.getPrimarySourceElement(cls));
    it.setReturnType(this.context.getString());
    it.addAnnotation(this.context.newAnnotationReference(Override.class));
    it.addAnnotation(this.context.newAnnotationReference(Pure.class));
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append(ToStringBuilder.class);
        _builder.append(" b = new ");
        _builder.append(ToStringBuilder.class);
        _builder.append("(this);");
        _builder.newLineIfNotEmpty();
        {
          boolean _isSkipNulls = config.isSkipNulls();
          if (_isSkipNulls) {
            _builder.append("b.skipNulls();");
          }
        }
        _builder.newLineIfNotEmpty();
        {
          boolean _isSingleLine = config.isSingleLine();
          if (_isSingleLine) {
            _builder.append("b.singleLine();");
          }
        }
        _builder.newLineIfNotEmpty();
        {
          boolean _isHideFieldNames = config.isHideFieldNames();
          if (_isHideFieldNames) {
            _builder.append("b.hideFieldNames();");
          }
        }
        _builder.newLineIfNotEmpty();
        {
          boolean _isVerbatimValues = config.isVerbatimValues();
          if (_isVerbatimValues) {
            _builder.append("b.verbatimValues();");
          }
        }
        _builder.newLineIfNotEmpty();
        {
          for(final FieldDeclaration field : fields) {
            _builder.append("b.add(\"");
            String _simpleName = field.getSimpleName();
            _builder.append(_simpleName);
            _builder.append("\", this.");
            String _simpleName_1 = field.getSimpleName();
            _builder.append(_simpleName_1);
            _builder.append(");");
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.append("return b.toString();");
        _builder.newLine();
      }
    };
    it.setBody(_client);
  };
  cls.addMethod("toString", _function);
}
 
Example 8
Source File: JsonRpcDataProcessor.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
protected MutableMethodDeclaration generateToString(final MutableClassDeclaration impl, @Extension final TransformationContext context) {
  MutableMethodDeclaration _xblockexpression = null;
  {
    final ArrayList<FieldDeclaration> toStringFields = CollectionLiterals.<FieldDeclaration>newArrayList();
    ClassDeclaration c = impl;
    do {
      {
        Iterable<? extends FieldDeclaration> _declaredFields = c.getDeclaredFields();
        Iterables.<FieldDeclaration>addAll(toStringFields, _declaredFields);
        TypeReference _extendedClass = c.getExtendedClass();
        Type _type = null;
        if (_extendedClass!=null) {
          _type=_extendedClass.getType();
        }
        c = ((ClassDeclaration) _type);
      }
    } while(((c != null) && (!Objects.equal(c, context.getObject()))));
    final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
      it.setReturnType(context.getString());
      it.addAnnotation(context.newAnnotationReference(Override.class));
      it.addAnnotation(context.newAnnotationReference(Pure.class));
      final AccessorsProcessor.Util accessorsUtil = new AccessorsProcessor.Util(context);
      StringConcatenationClient _client = new StringConcatenationClient() {
        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
          _builder.append(ToStringBuilder.class);
          _builder.append(" b = new ");
          _builder.append(ToStringBuilder.class);
          _builder.append("(this);");
          _builder.newLineIfNotEmpty();
          {
            for(final FieldDeclaration field : toStringFields) {
              _builder.append("b.add(\"");
              String _simpleName = field.getSimpleName();
              _builder.append(_simpleName);
              _builder.append("\", ");
              {
                TypeDeclaration _declaringType = field.getDeclaringType();
                boolean _equals = Objects.equal(_declaringType, impl);
                if (_equals) {
                  _builder.append("this.");
                  String _simpleName_1 = field.getSimpleName();
                  _builder.append(_simpleName_1);
                } else {
                  String _getterName = accessorsUtil.getGetterName(field);
                  _builder.append(_getterName);
                  _builder.append("()");
                }
              }
              _builder.append(");");
              _builder.newLineIfNotEmpty();
            }
          }
          _builder.append("return b.toString();");
          _builder.newLine();
        }
      };
      it.setBody(_client);
    };
    _xblockexpression = impl.addMethod("toString", _function);
  }
  return _xblockexpression;
}