Skip to content

Commit

Permalink
fix: 🚑 Sonar findings needs to be resolved (#111)
Browse files Browse the repository at this point in the history
fix: Resolved Sonar findings

---------

Co-authored-by: pawellabaj <pawellabaj@users.noreply.github.com>
Co-authored-by: pawellabaj <pawel_labaj@epam.com>
  • Loading branch information
3 people authored Aug 3, 2023
1 parent 0272a02 commit e72f39b
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 181 deletions.
3 changes: 2 additions & 1 deletion .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
titleAndCommits: true
titleAndCommits: true
anyCommit: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Java record newContext generator
[![javadoc](https://javadoc.io/badge2/pl.com.labaj.autorecord/auto-record-project/javadoc.svg)](https://javadoc.io/doc/pl.com.labaj.autorecord/auto-record-project)

[![CI Verify Status](https://github.com/pawellabaj/auto-record/actions/workflows/verify.yml/badge.svg?branch=main)](https://github.com/pawellabaj/auto-record/actions/workflows/verify.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pl.com.labaj%3Aauto-record-project&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=pl.com.labaj%3Aauto-record-project)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pl.com.labaj.autorecord%3Aauto-record-project&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=pl.com.labaj.autorecord%3Aauto-record-project)
[![Sonatype Lift Status](https://lift.sonatype.com/api/badge/github.com/pawellabaj/auto-record)](https://lift.sonatype.com/results/github.com/pawellabaj/auto-record)
[![Reproducible Builds](https://img.shields.io/badge/Reproducible_Builds-ok-success?labelColor=1e5b96)](https://github.com/jvm-repo-rebuild/reproducible-central#pl.com.labaj.autorecord:auto-record)
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7700/badge)](https://bestpractices.coreinfrastructure.org/projects/7700)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ List<MethodSpec> generateMethods(TypesStructure structure) {

private static MethodGenerator builderFor(InterfaceType iType) {
return (extContext, structure, staticImports, logger) -> {
var methodBuilder = getMethodBuilder(extContext, iType, logger);
var methodBuilder = getMethodBuilder(extContext, iType);

immutableTypesBlock(structure, iType)
.ifPresent(methodBuilder::addCode);
subTypesBlocks(extContext, iType, structure, logger)
subTypesBlocks(extContext, iType, structure)
.forEach(methodBuilder::addCode);

var returnStatement = isNull(iType.factoryClassName())
Expand All @@ -87,7 +87,7 @@ private static MethodGenerator builderFor(InterfaceType iType) {
};
}

private static MethodSpec.Builder getMethodBuilder(ExtensionContext extContext, InterfaceType iType, Logger logger) {
private static MethodSpec.Builder getMethodBuilder(ExtensionContext extContext, InterfaceType iType) {
var builder = MethodSpec.methodBuilder("immutable")
.addModifiers(PUBLIC, STATIC);

Expand Down Expand Up @@ -117,7 +117,7 @@ private static TypeName getTypeName(ExtensionContext extContext, InterfaceType i
return TypeName.get(mirrorType);
}

var className = (ClassName) ClassName.get(mirrorType);
var className = (ClassName) TypeName.get(mirrorType);
var typeVariableNames = iType.genericNames().stream()
.map(name -> full ? name : substringBefore(name, " "))
.map(TypeVariableName::get)
Expand Down Expand Up @@ -165,7 +165,7 @@ private static Optional<CodeBlock> immutableTypesBlock(TypesStructure structure,
return Optional.of(block);
}

private static List<CodeBlock> subTypesBlocks(ExtensionContext extContext, InterfaceType iType, TypesStructure structure, Logger logger) {
private static List<CodeBlock> subTypesBlocks(ExtensionContext extContext, InterfaceType iType, TypesStructure structure) {
return iType.directSubTypes().stream()
.filter(structure::needsAdditionalMethod)
.sorted(reverseOrder())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package pl.com.labaj.autorecord.collections;

/*-
* Copyright © 2023 Auto Record
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.util.Collection;

abstract class AbstractImmutableCollection<E> implements Collection<E> {
/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated(since = "1.0.0")
public final boolean add(E e) {
throw new UnsupportedOperationException("add");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated(since = "1.0.0")
public final boolean remove(Object o) {
throw new UnsupportedOperationException("remove");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated(since = "1.0.0")
public final boolean addAll(Collection<? extends E> c) {
throw new UnsupportedOperationException("addAll");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated(since = "1.0.0")
public final boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException("removeAll");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated(since = "1.0.0")
public final boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException("retainAll");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/

@Override
@Deprecated(since = "1.0.0")
public final void clear() {
throw new UnsupportedOperationException("clear");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @param <E> the type of elements in the collection
*/
@API(status = STABLE)
public class ImmutableCollection<E> implements Collection<E> {
public class ImmutableCollection<E> extends AbstractImmutableCollection<E> {

private final com.google.common.collect.ImmutableCollection<E> delegate;

Expand Down Expand Up @@ -121,84 +121,11 @@ public <T> T[] toArray(T[] a) {
return delegate.toArray(a);
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated
public final boolean add(E e) {
throw new UnsupportedOperationException("add");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated
public final boolean remove(Object o) {
throw new UnsupportedOperationException("remove");
}

/**
* {@inheritDoc}
*/
@Override
public final boolean containsAll(Collection<?> c) {
return delegate.containsAll(c);
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated
public final boolean addAll(Collection<? extends E> c) {
throw new UnsupportedOperationException("addAll");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated
public final boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException("removeAll");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Override
@Deprecated
public final boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException("retainAll");
}

/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/

@Override
@Deprecated
public final void clear() {
throw new UnsupportedOperationException("clear");
}
}
Loading

0 comments on commit e72f39b

Please sign in to comment.