-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- throw an exception instead of NOT_FOUND, resolves #14872 - sort beans and observers, application components go first - use FQCN where possible
- Loading branch information
Showing
19 changed files
with
420 additions
and
190 deletions.
There are no files selected for viewing
29 changes: 0 additions & 29 deletions
29
extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/devconsole/ClassName.java
This file was deleted.
Oops, something went wrong.
139 changes: 93 additions & 46 deletions
139
...nsions/arc/deployment/src/main/java/io/quarkus/arc/deployment/devconsole/DevBeanInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,127 @@ | ||
package io.quarkus.arc.deployment.devconsole; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class DevBeanInfo implements Comparable<DevBeanInfo> { | ||
|
||
private ClassName name; | ||
private String methodName; | ||
private DevBeanKind kind; | ||
private ClassName type; | ||
private List<ClassName> qualifiers = new ArrayList<>(); | ||
private ClassName scope; | ||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.AnnotationTarget; | ||
import org.jboss.jandex.AnnotationTarget.Kind; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.FieldInfo; | ||
import org.jboss.jandex.MethodInfo; | ||
import org.jboss.jandex.Type; | ||
|
||
public DevBeanInfo() { | ||
} | ||
import io.quarkus.arc.deployment.CompletedApplicationClassPredicateBuildItem; | ||
import io.quarkus.arc.processor.BeanInfo; | ||
import io.quarkus.arc.processor.DotNames; | ||
|
||
public DevBeanInfo(ClassName name, String methodName, ClassName type, List<ClassName> qualifiers, ClassName scope, | ||
DevBeanKind kind) { | ||
this.name = name; | ||
this.methodName = methodName; | ||
this.type = type; | ||
this.qualifiers = qualifiers; | ||
this.scope = scope; | ||
this.kind = kind; | ||
} | ||
public class DevBeanInfo implements Comparable<DevBeanInfo> { | ||
|
||
public void setKind(DevBeanKind kind) { | ||
this.kind = kind; | ||
private final DevBeanKind kind; | ||
private final boolean isApplicationBean; | ||
private final Name providerType; | ||
private final String memberName; | ||
private final Set<Name> types; | ||
private final Set<Name> qualifiers; | ||
private final Name scope; | ||
private final Name declaringClass; | ||
|
||
public DevBeanInfo(BeanInfo bean, CompletedApplicationClassPredicateBuildItem predicate) { | ||
qualifiers = new HashSet<>(); | ||
for (AnnotationInstance qualifier : bean.getQualifiers()) { | ||
qualifiers.add(Name.from(qualifier)); | ||
} | ||
scope = Name.from(bean.getScope().getDotName()); | ||
types = new HashSet<>(); | ||
for (Type beanType : bean.getTypes()) { | ||
types.add(Name.from(beanType)); | ||
} | ||
|
||
providerType = Name.from(bean.getProviderType()); | ||
|
||
if (bean.getTarget().isPresent()) { | ||
AnnotationTarget target = bean.getTarget().get(); | ||
if (target.kind() == Kind.METHOD) { | ||
MethodInfo method = target.asMethod(); | ||
memberName = method.name(); | ||
this.kind = DevBeanKind.METHOD; | ||
this.isApplicationBean = predicate.test(bean.getDeclaringBean().getBeanClass()); | ||
this.declaringClass = Name.from(bean.getDeclaringBean().getBeanClass()); | ||
} else if (target.kind() == Kind.FIELD) { | ||
FieldInfo field = target.asField(); | ||
this.memberName = field.name(); | ||
this.kind = DevBeanKind.FIELD; | ||
this.isApplicationBean = predicate.test(bean.getDeclaringBean().getBeanClass()); | ||
this.declaringClass = Name.from(bean.getDeclaringBean().getBeanClass()); | ||
} else if (target.kind() == Kind.CLASS) { | ||
ClassInfo clazz = target.asClass(); | ||
this.kind = DevBeanKind.CLASS; | ||
this.memberName = null; | ||
this.isApplicationBean = predicate.test(clazz.name()); | ||
this.declaringClass = null; | ||
} else { | ||
throw new IllegalArgumentException("Invalid annotation target: " + target); | ||
} | ||
} else { | ||
// Synthetic bean | ||
this.kind = DevBeanKind.SYNTHETIC; | ||
this.isApplicationBean = false; | ||
this.declaringClass = null; | ||
this.memberName = null; | ||
} | ||
} | ||
|
||
public DevBeanKind getKind() { | ||
return kind; | ||
} | ||
|
||
public void setScope(ClassName scope) { | ||
this.scope = scope; | ||
} | ||
|
||
public ClassName getScope() { | ||
public Name getScope() { | ||
return scope; | ||
} | ||
|
||
public List<ClassName> getQualifiers() { | ||
public Set<Name> getQualifiers() { | ||
return qualifiers; | ||
} | ||
|
||
public void setQualifiers(List<ClassName> qualifiers) { | ||
this.qualifiers = qualifiers; | ||
} | ||
|
||
public void setType(ClassName type) { | ||
this.type = type; | ||
public Set<Name> getNonDefaultQualifiers() { | ||
Set<Name> nonDefault = new HashSet<>(); | ||
String atDefault = DotNames.DEFAULT.toString(); | ||
String atAny = DotNames.ANY.toString(); | ||
for (Name qualifier : qualifiers) { | ||
if (qualifier.toString().endsWith(atDefault) || qualifier.toString().endsWith(atAny)) { | ||
continue; | ||
} | ||
nonDefault.add(qualifier); | ||
} | ||
return nonDefault; | ||
} | ||
|
||
public ClassName getType() { | ||
return type; | ||
public Set<Name> getTypes() { | ||
return types; | ||
} | ||
|
||
public String getMethodName() { | ||
return methodName; | ||
public Name getProviderType() { | ||
return providerType; | ||
} | ||
|
||
public void setMethodName(String methodName) { | ||
this.methodName = methodName; | ||
public String getMemberName() { | ||
return memberName; | ||
} | ||
|
||
public void setName(ClassName name) { | ||
this.name = name; | ||
public boolean isApplicationBean() { | ||
return isApplicationBean; | ||
} | ||
|
||
public ClassName getName() { | ||
return name; | ||
public Name getDeclaringClass() { | ||
return declaringClass; | ||
} | ||
|
||
@Override | ||
public int compareTo(DevBeanInfo o) { | ||
return type.getLocalName().compareTo(o.type.getLocalName()); | ||
// Application beans should go first | ||
if (isApplicationBean == o.isApplicationBean) { | ||
return providerType.compareTo(o.providerType); | ||
} | ||
return isApplicationBean ? -1 : 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.