Skip to content

Commit

Permalink
Merge pull request #1 from mohamed-ashraf-bayor/feature/JIS01-jisel-v…
Browse files Browse the repository at this point in the history
…ersion1

Feature/jis01 jisel version1
  • Loading branch information
mohamed-ashraf-bayor authored Dec 28, 2021
2 parents e75444f + 8b6fe6f commit e42ca4a
Show file tree
Hide file tree
Showing 24 changed files with 2,268 additions and 195 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Mohamed Ashraf Bayor
Copyright (c) 2022 Mohamed Ashraf Bayor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
102 changes: 82 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
## JISEL: Java Interface Segregation Library
Interface Segregation Library for Java 17
# JISEL: Java Interface Segregation Library
Minimum Java 17 Required

Pitch Video:
...
Pitch Video: https://youtu.be/nkbu6zxV3R0

### How to Install ?
## Installation

If you are running a Maven project, add the latest release dependency to your pom.xml
```xml
Expand All @@ -14,35 +13,98 @@ If you are running a Maven project, add the latest release dependency to your po
<version>1.0</version>
</dependency>
```
You will also need to include the same dependency as an additional annotation processor in the Maven Compiler plugin of your project
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>17</release>
<compilerArgs>-Xlint:unchecked</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.jisel</groupId>
<artifactId>jisel</artifactId>
<version>1.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
```

For other build tools, please check: [Maven Central](https://search.maven.org/artifact/org.jisel/jisel/1.0/jar).

### Use on your declared bloated interfaces methods
## Provided Annotations

### @SealForProfile / @SealForProfiles
To be used only on abstract methods of the large interfaces you need to segregate
```java
import SealForProfile;
public interface Sociable {

String STUDENT = "Student";
String WORKER = "Worker";
String ACTIVE_WORKER = "ActiveWorker";

@SealForProfiles({STUDENT, WORKER, ACTIVE_WORKER})
String startConversation();

@SealForProfile(STUDENT)
boolean attendClass(String fieldOfStudy);

@SealForProfile(STUDENT)
void askForHelpWhenNeeded();

@SealForProfile(WORKER)
@SealForProfile(ACTIVE_WORKER)
// both annotations above can be replaced with: @SealForProfiles({WORKER, ACTIVE_WORKER})
boolean[] joinOfficeSocialGroups(String[] groups, int maximum);

public interface InterfaceA {
@SealForProfile
void something();
@SealForProfile(ACTIVE_WORKER)
void leadOfficeSocialGroup(String groupName);

@SealForProfile(ACTIVE_WORKER)
double createNewOfficeSocialGroup(String groupName, List<String> starters);
}
```

### Use on your declared child classes implementing generated sealed interfaces

### @AddToProfile / @AddToProfiles
To be used only on classes (or interfaces) implementing (or extending) any of the sealed interfaces generated by the use of @SealForProfile(s)
```java
import AddToProfile;
@AddToProfiles(profiles = {STUDENT, WORKER}, largeInterface = "com.bayor.jisel.annotation.client.hierarchicalinheritance.Sociable")
// the above line can be replaced with the following 2:
// @AddToProfile(profile = STUDENT, largeInterface = "com.bayor.jisel.annotation.client.hierarchicalinheritance.Sociable")
// @AddToProfile(profile = WORKER, largeInterface = "com.bayor.jisel.annotation.client.hierarchicalinheritance.Sociable")
public final class StudentWorkerHybrid implements SealedStudentSociable, SealedWorkerSociable {
@Override
public String startConversation() throws IllegalStateException {
return null;
}

@Override
public void askForHelpWhenNeeded() {

}

@AddToProfile("PROFILE_NAME")
public final class ClientA implements SealedInterfaceA {
// ...
@Override
public boolean attendClass(String param0) throws IllegalArgumentException {
return false;
}

@Override
public boolean[] joinOfficeSocialGroups(String[] param0, int param1) {
return new boolean[0];
}
}

```

### Sample classes for testing
### Sample interfaces and classes for testing
[https://github.com/mohamed-ashraf-bayor/jisel-annotation-client](https://github.com/mohamed-ashraf-bayor/jisel-annotation-client)

### Invalid Uses of Jisel
The annotation should be used ONLY on interfaces created in your own project.

### Issues, Bugs, Suggestions
Contribute to the project's growth by reporting issues or making improvement suggestions [here](https://github.com/mohamed-ashraf-bayor/jisel/issues/new/choose)
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<name>Jisel</name>
<description>Interface Segregation Library for Java 17</description>
<url>http://jisel.org</url>
<description>Java Interface Segregation Library</description>
<url>https://jisel.org/</url>

<licenses>
<license>
Expand All @@ -21,7 +21,7 @@
</licenses>

<scm>
<connection>scm:git:git://github.com/mohamed-ashraf-bayor/froporec.git</connection>
<connection>scm:git:git://github.com/mohamed-ashraf-bayor/jisel.git</connection>
<developerConnection>scm:git:git@github.com:mohamed-ashraf-bayor/mohamed-ashraf-bayor.git</developerConnection>
<url>https://github.com/mohamed-ashraf-bayor/jisel</url>
<tag>HEAD</tag>
Expand Down Expand Up @@ -52,7 +52,7 @@
<dependencies>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<artifactId>auto-service-annotations</artifactId>
<version>${auto-service.version}</version>
</dependency>
</dependencies>
Expand All @@ -66,6 +66,13 @@
<configuration>
<release>17</release>
<compilerArgs>-Xlint:unchecked</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${auto-service.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2022 Mohamed Ashraf Bayor
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
module jisel {
exports org.jisel;
requires java.compiler;
requires java.logging;
requires com.google.auto.service;
}
59 changes: 56 additions & 3 deletions src/main/java/org/jisel/AddToProfile.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/**
* Copyright (c) 2022 Mohamed Ashraf Bayor
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.jisel;

import java.lang.annotation.ElementType;
Expand All @@ -6,16 +27,48 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static org.jisel.generator.StringGenerator.EMPTY_STRING;

/**
* Annotation to be applied on top of a class, an interface or a record which is implementing or extending a sealed interface generated by Jisel.<br><br>
* All sealed interfaces generated by Jisel follow the naming convention: <b>Sealed&#60;ProfileName&#62;&#60;LargeInterfaceSimpleName&#62;</b><br>
* See &#64;{@link AddToProfile} attributes documentation.<br><br>
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE})
@Repeatable(AddToProfile.AddToProfiless.class)
@Repeatable(AddToProfile.AddToProfilez.class)
public @interface AddToProfile {

String value();
/**
* <i>Not Required</i> - specifies the name of one of the profiles used with the &#64;SealForProfile annotations in the large interface definition.
* Also corresponds to the <b>&#60;ProfileName&#62;</b> from the sealed interfaces naming convention.<br>
* If not provided or empty, the annotated class, interface or record will be added to the permits list of the generated parent sealed interface.<br>
* Also, the provided profile attribute value MUST be one of the profiles defined in the large interface definition using &#64;SealForProfile. If not,
* the specified profile will be ignored and an informational message regarding provided incorrect profiles will be printed during the compilation.<br>
*
* @return the profile name
*/
String profile() default EMPTY_STRING;

/**
* <i>Required</i> - MUST be the Fully Qualified Name of the large interface. That would be the <b>&#60;LargeInterfaceSimpleName&#62;</b> as seen in
* the sealed interface name convention, preceded by the package name.<br>
*
* @return the large interface fully qualified name
*/
String largeInterface();

/**
* Internal annotation allowing &#64;AddToProfile to be repeatable
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@interface AddToProfiless {
@interface AddToProfilez {
/**
* array attribute allowing &#64;{@link AddToProfile} to be repeatable
*
* @return array of &#64;AddToProfile instances
*/
AddToProfile[] value();
}
}
64 changes: 63 additions & 1 deletion src/main/java/org/jisel/AddToProfiles.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
/**
* Copyright (c) 2022 Mohamed Ashraf Bayor
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.jisel;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static org.jisel.generator.StringGenerator.EMPTY_STRING;

/**
* Annotation to be applied on top of a class, an interface or a record which is implementing or extending a sealed interface generated by Jisel.<br><br>
* All sealed interfaces generated by Jisel follow the naming convention: <b>Sealed&#60;ProfileName&#62;&#60;LargeInterfaceSimpleName&#62;</b><br>
* See &#64;{@link AddToProfiles} attributes documentation.<br><br>
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE})
@Repeatable(AddToProfiles.AddToProfilezz.class)
public @interface AddToProfiles {
String[] value();

/**
* <i>Not Required</i> - specifies an array containing the names of any of the profiles used with the &#64;{@link SealForProfile} annotations in the large interface definition.
* Each one of the profiles names corresponds to the <b>&#60;ProfileName&#62;</b> from the sealed interfaces naming convention.<br>
* If not provided or empty, the annotated class, interface or record will be added to the permits list of the generated parent sealed interface.<br>
* Also, each one of the provided profiles names MUST be one of the profiles defined in the large interface definition using &#64;SealForProfile. If not,
* the specified profile will be ignored and an informational message regarding provided incorrect profiles will be printed during the compilation.<br>
*
* @return an array of the profiles names
*/
String[] profiles() default EMPTY_STRING;

/**
* <i>Required</i> - MUST be the Fully Qualified Name of the large interface. That would be the <b>&#60;LargeInterfaceSimpleName&#62;</b> as seen
* in the sealed interface name convention, preceded by the package name.<br>
*
* @return the large interface fully qualified name
*/
String largeInterface();

/**
* Internal annotation allowing &#64;{@link AddToProfiles} to be repeatable
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@interface AddToProfilezz {
/**
* array attribute allowing &#64;{@link AddToProfiles} to be repeatable
*
* @return array of &#64;AddToProfiles instances
*/
AddToProfiles[] value();
}
}
Loading

0 comments on commit e42ca4a

Please sign in to comment.