Skip to content

Commit

Permalink
Merge pull request #2 from agentgt/prism
Browse files Browse the repository at this point in the history
Merge prism changes
  • Loading branch information
SentryMan committed Feb 7, 2023
2 parents 8258618 + a121495 commit 2ee8553
Show file tree
Hide file tree
Showing 23 changed files with 330 additions and 191 deletions.
59 changes: 55 additions & 4 deletions inject-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
<artifactId>avaje-inject-generator</artifactId>
<name>avaje inject generator</name>
<description>annotation processor generating di as source code</description>

<properties>
<prism.directory>${project.build.directory}/generated-sources/prims</prism.directory>
</properties>
<dependencies>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject</artifactId>
<version>8.12-RC4</version>
<artifactId>avaje-inject-prism</artifactId>
<version>${project.version}</version>
</dependency>


<!-- test dependencies -->
<dependency>
Expand All @@ -40,7 +43,6 @@
<configuration>
<source>11</source>
<target>11</target>
<!-- Turn off annotation processing for building -->
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
Expand All @@ -55,6 +57,55 @@
</configuration>
</plugin>


<!--
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.0-rc1</version>
<configuration>
<defaultOutputDirectory>${prism.directory}</defaultOutputDirectory>
<processors>
<processor>net.java.dev.hickory.prism.internal.PrismGenerator</processor>
</processors>
</configuration>
<executions>
<execution>
<id>process</id>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.jolira</groupId>
<artifactId>hickory</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${prism.directory}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.avaje.inject.generator;

import io.avaje.inject.InjectModule;
import io.avaje.inject.prism.InjectModulePrism;

import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.Element;
Expand Down Expand Up @@ -59,7 +59,7 @@ void readModules(List<String> customScopeModules) {
for (String customScopeModule : customScopeModules) {
final TypeElement module = context.element(customScopeModule);
if (module != null) {
final InjectModule injectModule = module.getAnnotation(InjectModule.class);
InjectModulePrism injectModule = InjectModulePrism.getInstanceOn(module);
if (injectModule != null) {
final String customScopeType = injectModule.customScopeType();
final TypeElement scopeType = context.element(customScopeType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.avaje.inject.generator;

import io.avaje.inject.aop.Aspect;

import javax.lang.model.element.*;

import io.avaje.inject.prism.AspectPrism;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -27,7 +29,7 @@ List<AspectPair> read() {
List<AspectPair> aspects = new ArrayList<>();
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
Element anElement = annotationMirror.getAnnotationType().asElement();
Aspect aspect = anElement.getAnnotation(Aspect.class);
AspectPrism aspect = AspectPrism.getInstanceOn(anElement);
if (aspect != null) {
Meta meta = readTarget(anElement);
if (meta != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package io.avaje.inject.generator;

import io.avaje.inject.Primary;
import io.avaje.inject.Prototype;
import io.avaje.inject.Secondary;
import io.avaje.inject.spi.Proxy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import java.util.*;

import io.avaje.inject.prism.PrimaryPrism;
import io.avaje.inject.prism.PrototypePrism;
import io.avaje.inject.prism.ProxyPrism;
import io.avaje.inject.prism.SecondaryPrism;

final class BeanReader {

Expand Down Expand Up @@ -40,10 +45,12 @@ final class BeanReader {
this.beanType = beanType;
this.type = beanType.getQualifiedName().toString();
this.shortName = shortName(beanType);
this.prototype = (beanType.getAnnotation(Prototype.class) != null);
this.primary = (beanType.getAnnotation(Primary.class) != null);
this.secondary = !primary && (beanType.getAnnotation(Secondary.class) != null);
this.proxy = (beanType.getAnnotation(Proxy.class) != null);
//this.prototype = (beanType.getAnnotation(Prototype.class) != null);
this.prototype = (PrototypePrism.getInstanceOn(beanType) != null);

this.primary = (PrimaryPrism.getInstanceOn(beanType) != null);
this.secondary = !primary && (SecondaryPrism.getInstanceOn(beanType) != null);
this.proxy = (ProxyPrism.getInstanceOn(beanType) != null);
this.typeReader = new TypeReader(GenericType.parse(type), beanType, context, importTypes, factory);
typeReader.process();
this.requestParams = new BeanRequestParams(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Constants {

static final String REFLECT_METHOD = "java.lang.reflect.Method";
static final String ASPECT = "io.avaje.inject.aop.Aspect";
static final String ASPECT_PROVIDER ="io.avaje.inject.aop.AspectProvider";
static final String ASPECT_PROVIDER = "io.avaje.inject.aop.AspectProvider";
static final String INVOCATION = "io.avaje.inject.aop.Invocation";
static final String INVOCATION_EXCEPTION = "io.avaje.inject.aop.InvocationException";
static final String METHOD_INTERCEPTOR = "io.avaje.inject.aop.MethodInterceptor";
Expand All @@ -47,4 +47,11 @@ final class Constants {
static final String MODULE = "io.avaje.inject.spi.Module";
static final String GENERICTYPE = "io.avaje.inject.spi.GenericType";

static final String COMPONENT = "io.avaje.inject.Component";

static final String PROTOTYPE = "io.avaje.inject.Prototype";

static final String SCOPE = "jakarta.inject.Scope";

static final String INJECT_FACTORY = "io.avaje.inject.Factory";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.avaje.inject.generator;

import io.avaje.inject.spi.Module;

import java.util.*;

Expand All @@ -15,24 +14,24 @@ final class ExternalProvider {

void init(Set<String> moduleFileProvided) {
providedTypes.addAll(moduleFileProvided);
ServiceLoader<Module> load = ServiceLoader.load(Module.class, ExternalProvider.class.getClassLoader());
Iterator<Module> iterator = load.iterator();
while (iterator.hasNext()) {
try {
Module module = iterator.next();
for (final Class<?> provide : module.provides()) {
providedTypes.add(provide.getCanonicalName());
}
for (final Class<?> provide : module.autoProvides()) {
providedTypes.add(provide.getCanonicalName());
}
for (final Class<?> provide : module.autoProvidesAspects()) {
providedTypes.add(Util.wrapAspect(provide.getCanonicalName()));
}
} catch (final ServiceConfigurationError expected) {
// ignore expected error reading the module that we are also writing
}
}
// ServiceLoader<Module> load = ServiceLoader.load(Module.class, ExternalProvider.class.getClassLoader());
// Iterator<Module> iterator = load.iterator();
// while (iterator.hasNext()) {
// try {
// Module module = iterator.next();
// for (final Class<?> provide : module.provides()) {
// providedTypes.add(provide.getCanonicalName());
// }
// for (final Class<?> provide : module.autoProvides()) {
// providedTypes.add(provide.getCanonicalName());
// }
// for (final Class<?> provide : module.autoProvidesAspects()) {
// providedTypes.add(Util.wrapAspect(provide.getCanonicalName()));
// }
// } catch (final ServiceConfigurationError expected) {
// // ignore expected error reading the module that we are also writing
// }
// }
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.avaje.inject.generator;

import io.avaje.inject.spi.DependencyMeta;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.avaje.inject.prism.DependencyMetaPrism;

/**
* Holds the data as per <code>@DependencyMeta</code>
Expand Down Expand Up @@ -41,14 +40,14 @@ final class MetaData {
private boolean usesExternalDependency;
private String externalDependency;

MetaData(DependencyMeta meta) {
MetaData(DependencyMetaPrism meta) {
this.type = meta.type();
this.name = trimName(meta.name());
this.shortType = Util.shortName(type);
this.method = meta.method();
this.providesAspect = meta.providesAspect();
this.provides = asList(meta.provides());
this.dependsOn = Stream.of(meta.dependsOn()).map(Dependency::new).collect(Collectors.toList());
this.provides = meta.provides();
this.dependsOn = meta.dependsOn().stream().map(Dependency::new).collect(Collectors.toList());
this.autoProvides = meta.autoProvides();
}

Expand Down Expand Up @@ -113,13 +112,6 @@ void setWired() {
this.wired = true;
}

private List<String> asList(String[] content) {
if (content == null || content.length == 0) {
return new ArrayList<>();
}
return Arrays.asList(content);
}

void update(BeanReader beanReader) {
this.provides = beanReader.provides();
this.dependsOn = beanReader.dependsOn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package io.avaje.inject.generator;

import io.avaje.inject.Bean;
import io.avaje.inject.Primary;
import io.avaje.inject.Prototype;
import io.avaje.inject.Secondary;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import io.avaje.inject.prism.BeanPrism;
import io.avaje.inject.prism.PrimaryPrism;
import io.avaje.inject.prism.PrototypePrism;
import io.avaje.inject.prism.SecondaryPrism;

final class MethodReader {

Expand Down Expand Up @@ -42,13 +43,13 @@ final class MethodReader {
this(context, element, beanType, null, null, importTypes);
}

MethodReader(ProcessingContext context, ExecutableElement element, TypeElement beanType, Bean bean, String qualifierName, ImportTypeMap importTypes) {
MethodReader(ProcessingContext context, ExecutableElement element, TypeElement beanType, BeanPrism bean, String qualifierName, ImportTypeMap importTypes) {
this.isFactory = bean != null;
this.element = element;
if (isFactory) {
prototype = element.getAnnotation(Prototype.class) != null;
primary = element.getAnnotation(Primary.class) != null;
secondary = element.getAnnotation(Secondary.class) != null;
prototype = PrototypePrism.getInstanceOn(element) != null;
primary = PrimaryPrism.getInstanceOn(element) != null;
secondary = SecondaryPrism.getInstanceOn(element) != null;
} else {
prototype = false;
primary = false;
Expand Down
Loading

0 comments on commit 2ee8553

Please sign in to comment.