public CharSequence delegateAccess(final MemberDeclaration it, final MethodDeclaration method) { if (it instanceof MethodDeclaration) { return _delegateAccess((MethodDeclaration)it, method); } else if (it instanceof FieldDeclaration) { return _delegateAccess((FieldDeclaration)it, method); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, method).toString()); } } }
public TypeReference getType(final MemberDeclaration it) { if (it instanceof MethodDeclaration) { return _getType((MethodDeclaration)it); } else if (it instanceof FieldDeclaration) { return _getType((FieldDeclaration)it); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it).toString()); } }
public boolean isValidDelegate(final MemberDeclaration it) { if (it instanceof MethodDeclaration) { return _isValidDelegate((MethodDeclaration)it); } else if (it instanceof FieldDeclaration) { return _isValidDelegate((FieldDeclaration)it); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it).toString()); } }
final Set<TypeReference> interfacesOfDeclaringType = this.getImplementedInterfaces(declaringType); final Set<TypeReference> availableInterfaces = this.getImplementedInterfaces(this.getType(delegate)); final Set<TypeReference> listedInterfaces = this.listedInterfaces(delegate); boolean valid = true; for (final TypeReference iface : listedInterfaces) { if (_not) { StringConcatenation _builder = new StringConcatenation(); String _simpleName = this.getType(delegate).getSimpleName(); _builder.append(_simpleName); _builder.append(" does not implement "); String _simpleName = this.getType(delegate).getSimpleName(); _builder.append(_simpleName); _builder.append(" and ");
public boolean hasDelegationConflicts(final MemberDeclaration delegate) { boolean _xblockexpression = false; { boolean conflict = false; Iterable<? extends MemberDeclaration> _otherDelegates = this.otherDelegates(delegate); for (final MemberDeclaration other : _otherDelegates) { { final Set<TypeReference> otherInterfaces = this.getDelegatedInterfaces(other); Set<TypeReference> _delegatedInterfaces = this.getDelegatedInterfaces(delegate); for (final TypeReference iface : _delegatedInterfaces) { boolean _contains = otherInterfaces.contains(iface); if (_contains) { conflict = true; StringConcatenation _builder = new StringConcatenation(); _builder.append("The interface "); String _simpleName = iface.getSimpleName(); _builder.append(_simpleName); _builder.append(" is also implemented by the delegate "); String _simpleName_1 = other.getSimpleName(); _builder.append(_simpleName_1); this.context.addError(delegate, _builder.toString()); } } } } _xblockexpression = conflict; } return _xblockexpression; }
public Set<ResolvedMethod> getMethodsToImplement(final MemberDeclaration delegate) { final Function1<TypeReference, Iterable<? extends ResolvedMethod>> _function = (TypeReference it) -> { return it.getDeclaredResolvedMethods(); }; final Function1<ResolvedMethod, Boolean> _function_1 = (ResolvedMethod it) -> { final Function1<ResolvedParameter, TypeReference> _function_2 = (ResolvedParameter it_1) -> { return it_1.getResolvedType(); }; MethodDeclaration _findDeclaredMethod = delegate.getDeclaringType().findDeclaredMethod(it.getDeclaration().getSimpleName(), ((TypeReference[])Conversions.unwrapArray(IterableExtensions.map(it.getResolvedParameters(), _function_2), TypeReference.class))); return Boolean.valueOf((_findDeclaredMethod == null)); }; final Function1<ResolvedMethod, Boolean> _function_2 = (ResolvedMethod it) -> { boolean _isObjectMethod = this.isObjectMethod(it); return Boolean.valueOf((!_isObjectMethod)); }; final Function1<ResolvedMethod, String> _function_3 = (ResolvedMethod it) -> { return it.getSimpleSignature(); }; final Function1<List<ResolvedMethod>, ResolvedMethod> _function_4 = (List<ResolvedMethod> it) -> { return IterableExtensions.<ResolvedMethod>head(it); }; return IterableExtensions.<ResolvedMethod>toSet(IterableExtensions.<List<ResolvedMethod>, ResolvedMethod>map(IterableExtensions.<String, ResolvedMethod>groupBy(IterableExtensions.<ResolvedMethod>filter(IterableExtensions.<ResolvedMethod>filter(Iterables.<ResolvedMethod>concat(IterableExtensions.<TypeReference, Iterable<? extends ResolvedMethod>>map(this.getDelegatedInterfaces(delegate), _function)), _function_1), _function_2), _function_3).values(), _function_4)); }
@Override public void doTransform(final List<? extends MutableMemberDeclaration> elements, @Extension final TransformationContext context) { @Extension final DelegateProcessor.Util util = new DelegateProcessor.Util(context); final Consumer<MutableMemberDeclaration> _function = (MutableMemberDeclaration it) -> { boolean _isValidDelegate = util.isValidDelegate(it); if (_isValidDelegate) { final Consumer<ResolvedMethod> _function_1 = (ResolvedMethod method) -> { util.implementMethod(it, method); }; util.getMethodsToImplement(it).forEach(_function_1); } }; elements.forEach(_function); } }
public Set<TypeReference> getDelegatedInterfaces(final MemberDeclaration delegate) { Set<TypeReference> _xblockexpression = null; { final Set<TypeReference> interfacesOfDeclaringType = this.getImplementedInterfaces(this.context.newSelfTypeReference(delegate.getDeclaringType())); final Set<TypeReference> listedInterfaces = this.listedInterfaces(delegate); final Set<TypeReference> availableInterfaces = this.getImplementedInterfaces(this.getType(delegate)); final Function1<TypeReference, Boolean> _function = (TypeReference iface) -> { return Boolean.valueOf((interfacesOfDeclaringType.contains(iface) && (listedInterfaces.isEmpty() || IterableExtensions.<TypeReference>exists(listedInterfaces, ((Function1<TypeReference, Boolean>) (TypeReference it) -> { return Boolean.valueOf(iface.isAssignableFrom(it)); }))))); }; _xblockexpression = IterableExtensions.<TypeReference>toSet(IterableExtensions.<TypeReference>filter(availableInterfaces, _function)); } return _xblockexpression; }
protected boolean _isValidDelegate(final MethodDeclaration it) { return (((this.hasValidType(it) && this.hasValidSignature(it)) && (!this.hasDelegationConflicts(it))) && this.areListedInterfacesValid(it)); }
protected boolean _isValidDelegate(final FieldDeclaration it) { return ((this.hasValidType(it) && (!this.hasDelegationConflicts(it))) && this.areListedInterfacesValid(it)); }
public Set<TypeReference> getImplementedInterfaces(final TypeReference it) { Set<TypeReference> _xblockexpression = null; { final LinkedHashSet<TypeReference> seen = CollectionLiterals.<TypeReference>newLinkedHashSet(); this.collectAllSuperTypes(it, seen); final Function1<TypeReference, Boolean> _function = (TypeReference it_1) -> { Type _type = it_1.getType(); return Boolean.valueOf((_type instanceof InterfaceDeclaration)); }; _xblockexpression = IterableExtensions.<TypeReference>toSet(IterableExtensions.<TypeReference>filter(seen, _function)); } return _xblockexpression; }
public Iterable<? extends MemberDeclaration> otherDelegates(final MemberDeclaration delegate) { final Function1<MemberDeclaration, Boolean> _function = (MemberDeclaration it) -> { return Boolean.valueOf((!Objects.equal(it, delegate))); }; return IterableExtensions.filter(this.getDelegates(delegate.getDeclaringType()), _function); }
private void collectAllSuperTypes(final TypeReference it, final Set<TypeReference> seen) { boolean _add = seen.add(it); final boolean cycle = (!_add); if (cycle) { return; } final Consumer<TypeReference> _function = (TypeReference it_1) -> { this.collectAllSuperTypes(it_1, seen); }; it.getDeclaredSuperTypes().forEach(_function); }