org.eclipse.xtend.lib.macro.declaration.MutableConstructorDeclaration Java Examples

The following examples show how to use org.eclipse.xtend.lib.macro.declaration.MutableConstructorDeclaration. 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: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 6 votes vote down vote up
public void addFinalFieldsConstructor(final MutableClassDeclaration it) {
  boolean _isEmpty = this.getFinalFieldsConstructorArgumentTypes(it).isEmpty();
  if (_isEmpty) {
    final AnnotationReference anno = it.findAnnotation(this.context.findTypeGlobally(FinalFieldsConstructor.class));
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("There are no final fields, this annotation has no effect");
    this.context.addWarning(anno, _builder.toString());
    return;
  }
  boolean _hasFinalFieldsConstructor = this.hasFinalFieldsConstructor(it);
  if (_hasFinalFieldsConstructor) {
    this.context.addError(it, this.getConstructorAlreadyExistsMessage(it));
    return;
  }
  final Procedure1<MutableConstructorDeclaration> _function = (MutableConstructorDeclaration it_1) -> {
    this.context.setPrimarySourceElement(it_1, this.context.getPrimarySourceElement(it_1.getDeclaringType()));
    this.makeFinalFieldsConstructor(it_1);
  };
  it.addConstructor(_function);
}
 
Example #2
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public MutableConstructorDeclaration addConstructor(final Procedure1<MutableConstructorDeclaration> initializer) {
  this.checkMutable();
  Preconditions.checkArgument((initializer != null), "initializer cannot be null");
  final Function1<JvmConstructor, Boolean> _function = (JvmConstructor it) -> {
    return Boolean.valueOf(this.getCompilationUnit().getTypeExtensions().isSingleSyntheticDefaultConstructor(it));
  };
  final JvmConstructor constructor = IterableExtensions.<JvmConstructor>findFirst(Iterables.<JvmConstructor>filter(this.getDelegate().getMembers(), JvmConstructor.class), _function);
  if ((constructor != null)) {
    EcoreUtil.remove(constructor);
  }
  final JvmConstructor newConstructor = TypesFactory.eINSTANCE.createJvmConstructor();
  newConstructor.setVisibility(JvmVisibility.PUBLIC);
  newConstructor.setSimpleName(this.getSimpleName());
  this.getDelegate().getMembers().add(newConstructor);
  MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newConstructor);
  final MutableConstructorDeclaration mutableConstructorDeclaration = ((MutableConstructorDeclaration) _memberDeclaration);
  initializer.apply(mutableConstructorDeclaration);
  return mutableConstructorDeclaration;
}
 
Example #3
Source File: JvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MutableConstructorDeclaration addConstructor(final Procedure1<MutableConstructorDeclaration> initializer) {
  String _simpleName = this.getSimpleName();
  String _plus = ("The interface \'" + _simpleName);
  String _plus_1 = (_plus + "\' cannot declare any constructors.");
  throw new UnsupportedOperationException(_plus_1);
}
 
Example #4
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public boolean hasFinalFieldsConstructor(final MutableTypeDeclaration cls) {
  boolean _xblockexpression = false;
  {
    final ArrayList<TypeReference> expectedTypes = this.getFinalFieldsConstructorArgumentTypes(cls);
    final Function1<MutableConstructorDeclaration, Boolean> _function = (MutableConstructorDeclaration it) -> {
      final Function1<MutableParameterDeclaration, TypeReference> _function_1 = (MutableParameterDeclaration it_1) -> {
        return it_1.getType();
      };
      List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(it.getParameters(), _function_1));
      return Boolean.valueOf(Objects.equal(_list, expectedTypes));
    };
    _xblockexpression = IterableExtensions.exists(cls.getDeclaredConstructors(), _function);
  }
  return _xblockexpression;
}
 
Example #5
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
public void transform(final MutableTypeParameterDeclarator it, final TransformationContext context) {
  if (it instanceof MutableConstructorDeclaration) {
    _transform((MutableConstructorDeclaration)it, context);
    return;
  } else if (it instanceof MutableClassDeclaration) {
    _transform((MutableClassDeclaration)it, context);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, context).toString());
  }
}
 
Example #6
Source File: JvmAnnotationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MutableConstructorDeclaration addConstructor(final Procedure1<MutableConstructorDeclaration> initializer) {
  String _simpleName = this.getSimpleName();
  String _plus = ("The annotation \'" + _simpleName);
  String _plus_1 = (_plus + "\' cannot declare any constructors.");
  throw new UnsupportedOperationException(_plus_1);
}
 
Example #7
Source File: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
  ConstructorDeclaration _findDeclaredConstructor = super.findDeclaredConstructor(parameterTypes);
  return ((MutableConstructorDeclaration) _findDeclaredConstructor);
}
 
Example #8
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableConstructorDeclaration> getDeclaredConstructors() {
  Iterable<? extends ConstructorDeclaration> _declaredConstructors = super.getDeclaredConstructors();
  return ((Iterable<? extends MutableConstructorDeclaration>) _declaredConstructors);
}
 
Example #9
Source File: MutableJvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
  ConstructorDeclaration _findDeclaredConstructor = super.findDeclaredConstructor(parameterTypes);
  return ((MutableConstructorDeclaration) _findDeclaredConstructor);
}
 
Example #10
Source File: MutableJvmEnumerationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableConstructorDeclaration> getDeclaredConstructors() {
  Iterable<? extends ConstructorDeclaration> _declaredConstructors = super.getDeclaredConstructors();
  return ((Iterable<? extends MutableConstructorDeclaration>) _declaredConstructors);
}
 
Example #11
Source File: MutableJvmEnumerationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
  ConstructorDeclaration _findDeclaredConstructor = super.findDeclaredConstructor(parameterTypes);
  return ((MutableConstructorDeclaration) _findDeclaredConstructor);
}
 
Example #12
Source File: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableConstructorDeclaration> getDeclaredConstructors() {
  Iterable<? extends ConstructorDeclaration> _declaredConstructors = super.getDeclaredConstructors();
  return ((Iterable<? extends MutableConstructorDeclaration>) _declaredConstructors);
}
 
Example #13
Source File: AbstractConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public void doTransform(List<? extends MutableConstructorDeclaration> annotatedConstructors, @Extension TransformationContext context) {
	for (MutableConstructorDeclaration annotatedConstructor : annotatedConstructors) {
		doTransform(annotatedConstructor, context);
	}
}
 
Example #14
Source File: MutableJvmAnnotationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends MutableConstructorDeclaration> getDeclaredConstructors() {
  Iterable<? extends ConstructorDeclaration> _declaredConstructors = super.getDeclaredConstructors();
  return ((Iterable<? extends MutableConstructorDeclaration>) _declaredConstructors);
}
 
Example #15
Source File: MutableJvmAnnotationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MutableConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
  ConstructorDeclaration _findDeclaredConstructor = super.findDeclaredConstructor(parameterTypes);
  return ((MutableConstructorDeclaration) _findDeclaredConstructor);
}
 
Example #16
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
protected void _transform(final MutableConstructorDeclaration it, @Extension final TransformationContext context) {
  @Extension
  final FinalFieldsConstructorProcessor.Util util = new FinalFieldsConstructorProcessor.Util(context);
  util.makeFinalFieldsConstructor(it);
}
 
Example #17
Source File: AbstractConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @param annotatedConstructor a mutable method representation annotated with the annotation this processor is responsible for.
 * @param context
 */
public void doTransform(MutableConstructorDeclaration annotatedConstructor, @Extension TransformationContext context) {}