ing
This commit is contained in:
parent
61fb53a49c
commit
f0247ea2bd
|
@ -9,6 +9,11 @@ import {
|
|||
AnnotationUtils,
|
||||
} from '@overflow/commons/core/util';
|
||||
|
||||
import {
|
||||
InjectableAnnotation,
|
||||
QualifierAnnotation,
|
||||
} from '@overflow/commons/di/decorators';
|
||||
|
||||
import {
|
||||
InstanceDefinition,
|
||||
InstanceDefinitionRegistry,
|
||||
|
@ -21,8 +26,6 @@ import {
|
|||
} from '@overflow/commons/di/type';
|
||||
|
||||
import { ScopeMetadataResolver } from './scope_metadata_resolver';
|
||||
import { InjectableAnnotation, QualifierAnnotation } from '@overflow/commons/di/decorators';
|
||||
|
||||
|
||||
export class InstanceDefinitionReader {
|
||||
private instanceDefinitionRegistry: InstanceDefinitionRegistry;
|
||||
|
@ -40,9 +43,10 @@ export class InstanceDefinitionReader {
|
|||
});
|
||||
}
|
||||
|
||||
public registerInjectable(injectable: ClassType, name: InstanceNameType | undefined, ...qualifiers: QualifierAnnotation[]): void {
|
||||
public registerInjectable<QT extends Annotation>
|
||||
(injectable: ClassType, name: InstanceNameType | undefined, ...qualifierTypes: ClassType<QT>[]): void {
|
||||
if (!AnnotationUtils.hasAnnotation(injectable, InjectableAnnotation)) {
|
||||
throw new NotInjectableError();
|
||||
throw new NotInjectableError(`Class[${injectable.name}] does not contains @Injectable`);
|
||||
}
|
||||
|
||||
let definition: InstanceDefinition = new InstanceDefinition(injectable);
|
||||
|
|
|
@ -31,6 +31,23 @@ export abstract class AccessibleObject implements AnnotatedElement {
|
|||
return this._annotations;
|
||||
}
|
||||
|
||||
public getOwnAnnotationsByType<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>)
|
||||
: AnnotationType[] | undefined {
|
||||
if (0 === this._annotations.size) {
|
||||
return undefined;
|
||||
}
|
||||
let results: AnnotationType[] = [];
|
||||
for (const classType of Array.from(this._annotations.keys())) {
|
||||
if (classType === annotationClass) {
|
||||
results.push(<AnnotationType>this._annotations.get(classType));
|
||||
}
|
||||
}
|
||||
if (0 === results.length) {
|
||||
return undefined;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public getAnnotation<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>): AnnotationType | undefined {
|
||||
return this.getOwnAnnotation(annotationClass);
|
||||
}
|
||||
|
@ -39,4 +56,8 @@ export abstract class AccessibleObject implements AnnotatedElement {
|
|||
return this.getOwnAnnotations();
|
||||
}
|
||||
|
||||
public getAnnotationsByType<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>)
|
||||
: AnnotationType[] | undefined {
|
||||
return this.getOwnAnnotationsByType(annotationClass);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ export interface AnnotatedElement {
|
|||
isAnnotationPresent<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>): boolean;
|
||||
getOwnAnnotation<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>): AnnotationType | undefined;
|
||||
getOwnAnnotations(): Map<ClassType, Annotation>;
|
||||
getOwnAnnotationsByType<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>): AnnotationType[] | undefined;
|
||||
getAnnotation<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>): AnnotationType | undefined;
|
||||
getAnnotations(): Map<ClassType, Annotation>;
|
||||
getAnnotationsByType<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>): AnnotationType[] | undefined;
|
||||
}
|
||||
|
|
|
@ -201,6 +201,23 @@ export class Class extends AccessibleObject {
|
|||
return annotations;
|
||||
}
|
||||
|
||||
public getAnnotationsByType<AnnotationType extends Annotation>(annotationClass: ClassType<AnnotationType>)
|
||||
: AnnotationType[] | undefined {
|
||||
let annotations = this.getAnnotations();
|
||||
if (0 === annotations.size) {
|
||||
return undefined;
|
||||
}
|
||||
let results: AnnotationType[] = [];
|
||||
for (const classType of Array.from(annotations.keys())) {
|
||||
if (classType === annotationClass) {
|
||||
results.push(<AnnotationType>annotations.get(classType));
|
||||
}
|
||||
}
|
||||
if (0 === results.length) {
|
||||
return undefined;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public getName(): string {
|
||||
return this._clazzType.name;
|
||||
|
|
|
@ -33,4 +33,7 @@ export abstract class AnnotationUtils {
|
|||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user