org.eclipse.xtend.lib.annotations.AccessorsProcessor Java Examples

The following examples show how to use org.eclipse.xtend.lib.annotations.AccessorsProcessor. 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: PropertyProcessor.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doTransform(final MutableFieldDeclaration it, @Extension final TransformationContext context) {
  @Extension
  final AccessorsProcessor.Util util = new AccessorsProcessor.Util(context);
  boolean _hasGetter = util.hasGetter(it);
  boolean _not = (!_hasGetter);
  if (_not) {
    util.addGetter(it, Visibility.PUBLIC);
  }
  if (((!it.isFinal()) && (!util.hasSetter(it)))) {
    util.addSetter(it, Visibility.PUBLIC);
  }
  String _firstLower = StringExtensions.toFirstLower(it.getSimpleName());
  String _plus = ("_" + _firstLower);
  it.setSimpleName(_plus);
}
 
Example #2
Source File: SarlProcessorInstanceForJvmTypeProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Filter the type in order to create the correct processor.
 *
 * @param type the type of the processor specified into the {@code @Active} annotation.
 * @param services the type services of the framework.
 * @return the real type of the processor to instance.
 */
public static JvmType filterActiveProcessorType(JvmType type, CommonTypeComputationServices services) {
	if (AccessorsProcessor.class.getName().equals(type.getQualifiedName())) {
		final JvmType filteredType = services.getTypeReferences().findDeclaredType(SarlAccessorsProcessor.class, type);
		if (filteredType != null) {
			return filteredType;
		}
	}
	return type;
}
 
Example #3
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;
}