From 9b1239e5f9fc60ac14cba6b809afb4c98b0c12a9 Mon Sep 17 00:00:00 2001 From: Bernd Dutkowski Date: Thu, 15 Jul 2021 15:38:19 +0200 Subject: [PATCH] WIP --- .../java/org/xmolecules/ide/intellij/All.java | 21 +++++ .../org/xmolecules/ide/intellij/Concept.java | 22 +++-- .../ide/intellij/ConceptImplementation.java | 44 +++++++++ .../ide/intellij/ConceptViaImplements.java | 9 ++ .../intellij/ConceptViaMethodAnnotation.java | 11 +++ .../intellij/ConceptViaTypeAnnotation.java | 9 ++ .../org/xmolecules/ide/intellij/Concepts.java | 43 ++++++--- .../xmolecules/ide/intellij/JMolecules.java | 78 ++++++++++++++++ .../java/org/xmolecules/ide/intellij/JPA.java | 15 +++ .../org/xmolecules/ide/intellij/Library.java | 22 +++++ .../org/xmolecules/ide/intellij/Spring.java | 24 +++++ .../org/xmolecules/ide/intellij/Types.java | 92 +++++++++++++++++++ .../kotlin/nexos/intellij/ddd/DDDGroup.kt | 4 +- .../nexos/intellij/ddd/DDDLibraryResolver.kt | 13 ++- .../nexos/intellij/ddd/FrameworkType.kt | 5 +- src/main/kotlin/nexos/intellij/ddd/Info.kt | 3 - .../kotlin/nexos/intellij/ddd/Provider.kt | 2 + src/main/kotlin/nexos/intellij/ddd/all.kt | 7 -- .../kotlin/nexos/intellij/ddd/concepts.kt | 23 ----- .../intellij/ddd/jddd/ArchitectureLayered.kt | 5 +- .../kotlin/nexos/intellij/ddd/jddd/Support.kt | 5 +- .../kotlin/nexos/intellij/ddd/jddd/core.kt | 6 +- .../nexos/intellij/ddd/jddd/domainEvent.kt | 6 +- .../kotlin/nexos/intellij/ddd/jddd/facet.kt | 6 +- .../kotlin/nexos/intellij/ddd/jddd/jddd.kt | 3 +- .../intellij/ddd/jmolecules/jmolecules.kt | 64 ------------- src/main/kotlin/nexos/intellij/ddd/jpa.kt | 17 ---- src/main/kotlin/nexos/intellij/ddd/psijava.kt | 29 ------ src/main/kotlin/nexos/intellij/ddd/scope.kt | 16 ++-- src/main/resources/META-INF/gradle.xml | 6 +- src/main/resources/META-INF/plugin.xml | 14 +-- src/test/kotlin/nexos/intellij/ddd/PSITest.kt | 7 +- 32 files changed, 426 insertions(+), 205 deletions(-) create mode 100644 src/main/java/org/xmolecules/ide/intellij/All.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/ConceptImplementation.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/ConceptViaImplements.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/ConceptViaMethodAnnotation.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/ConceptViaTypeAnnotation.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/JMolecules.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/JPA.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/Library.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/Spring.java create mode 100644 src/main/java/org/xmolecules/ide/intellij/Types.java delete mode 100644 src/main/kotlin/nexos/intellij/ddd/Info.kt delete mode 100644 src/main/kotlin/nexos/intellij/ddd/all.kt delete mode 100644 src/main/kotlin/nexos/intellij/ddd/concepts.kt delete mode 100644 src/main/kotlin/nexos/intellij/ddd/jmolecules/jmolecules.kt delete mode 100644 src/main/kotlin/nexos/intellij/ddd/jpa.kt delete mode 100644 src/main/kotlin/nexos/intellij/ddd/psijava.kt diff --git a/src/main/java/org/xmolecules/ide/intellij/All.java b/src/main/java/org/xmolecules/ide/intellij/All.java new file mode 100644 index 0000000..ba01a7d --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/All.java @@ -0,0 +1,21 @@ +package org.xmolecules.ide.intellij; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class All { + public static final List ALL = concat(JMolecules.ALL , Spring.ALL, JPA.ALL); + + private static List concat(List ... list) { + var size = 0; + for( var l : list) { + size += l.size(); + } + var buffer = new ArrayList(size); + for( var l : list) { + buffer.addAll(l); + } + return Collections.unmodifiableList(buffer); + } +} diff --git a/src/main/java/org/xmolecules/ide/intellij/Concept.java b/src/main/java/org/xmolecules/ide/intellij/Concept.java index 58b8b87..2b70b67 100644 --- a/src/main/java/org/xmolecules/ide/intellij/Concept.java +++ b/src/main/java/org/xmolecules/ide/intellij/Concept.java @@ -1,38 +1,44 @@ package org.xmolecules.ide.intellij; -import java.util.function.Predicate; - import com.intellij.psi.PsiJavaFile; import org.jetbrains.annotations.NotNull; -class Concept implements Predicate, Comparable { - private final String name, plural; +import java.util.function.Predicate; + +public class Concept implements Predicate, Comparable { + private final String name, plural, defaultColorName; private final Predicate condition; Concept( @NotNull final String name, @NotNull final String plural, + @NotNull final String defaultColorName, @NotNull final Predicate condition) { this.name = name; this.plural = plural; + this.defaultColorName = defaultColorName; this.condition = condition; } - @NotNull String getName() { + public @NotNull String getName() { return name; } - @NotNull String getPlural() { + public @NotNull String getPlural() { return plural; } + public @NotNull String getDefaultColorName() { + return defaultColorName; + } + @Override public boolean test(@NotNull final PsiJavaFile psiJavaFile) { return condition.test(psiJavaFile); } @Override - public int compareTo(Concept o) { + public int compareTo(final Concept o) { return getName().compareTo(o.getName()); - } + } //TODO Compare by instance } diff --git a/src/main/java/org/xmolecules/ide/intellij/ConceptImplementation.java b/src/main/java/org/xmolecules/ide/intellij/ConceptImplementation.java new file mode 100644 index 0000000..0f2ae61 --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/ConceptImplementation.java @@ -0,0 +1,44 @@ +package org.xmolecules.ide.intellij; + +import com.intellij.psi.PsiJavaFile; + +import java.util.function.Predicate; + +public abstract class ConceptImplementation implements Predicate { + private final Concept concept; + private final Library library; + private final Predicate condition; + private final String fqName; + + public ConceptImplementation(final Concept concept, final Library library, final String fqName, final Predicate condition) { + this.concept = concept; + this.library = library; + this.condition = condition; + this.fqName = fqName; + } + + public Concept getConcept() { + return concept; + } + + public Library getLibrary() { + return library; + } + + /** + * @see com.intellij.codeInsight.daemon.quickFix.ExternalLibraryResolver + * @see nexos.intellij.ddd.DDDLibraryResolver + */ + public String getFqName() { + return fqName; + } + + /* + * (non-Javadoc) + * @see java.util.function.Predicate#test(java.lang.Object) + */ + @Override + public boolean test(final PsiJavaFile psiJavaFile) { + return condition.test(psiJavaFile); + } +} diff --git a/src/main/java/org/xmolecules/ide/intellij/ConceptViaImplements.java b/src/main/java/org/xmolecules/ide/intellij/ConceptViaImplements.java new file mode 100644 index 0000000..6b7781d --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/ConceptViaImplements.java @@ -0,0 +1,9 @@ +package org.xmolecules.ide.intellij; + +import static org.xmolecules.ide.intellij.Types.implementsType; + +public class ConceptViaImplements extends ConceptImplementation { + public ConceptViaImplements(final Concept concept, final Library library, final String fqName) { + super(concept, library, fqName, it -> implementsType(fqName, it)); + } +} diff --git a/src/main/java/org/xmolecules/ide/intellij/ConceptViaMethodAnnotation.java b/src/main/java/org/xmolecules/ide/intellij/ConceptViaMethodAnnotation.java new file mode 100644 index 0000000..56ee530 --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/ConceptViaMethodAnnotation.java @@ -0,0 +1,11 @@ +package org.xmolecules.ide.intellij; + +import java.util.List; + +import static org.xmolecules.ide.intellij.Types.hasMethodAnnotatedWith; + +public class ConceptViaMethodAnnotation extends ConceptImplementation { + public ConceptViaMethodAnnotation(final Concept concept, final Library library, final String fqName) { + super(concept, library, fqName, it -> hasMethodAnnotatedWith(it, fqName)); + } +} diff --git a/src/main/java/org/xmolecules/ide/intellij/ConceptViaTypeAnnotation.java b/src/main/java/org/xmolecules/ide/intellij/ConceptViaTypeAnnotation.java new file mode 100644 index 0000000..f76cc5b --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/ConceptViaTypeAnnotation.java @@ -0,0 +1,9 @@ +package org.xmolecules.ide.intellij; + +import static org.xmolecules.ide.intellij.Types.isTypeAnnotatedWith; + +public class ConceptViaTypeAnnotation extends ConceptImplementation { + public ConceptViaTypeAnnotation(final Concept concept, final Library library, final String fqName) { + super(concept, library, fqName, it -> isTypeAnnotatedWith(fqName, it)); + } +} diff --git a/src/main/java/org/xmolecules/ide/intellij/Concepts.java b/src/main/java/org/xmolecules/ide/intellij/Concepts.java index 4640fc5..f6c35cf 100644 --- a/src/main/java/org/xmolecules/ide/intellij/Concepts.java +++ b/src/main/java/org/xmolecules/ide/intellij/Concepts.java @@ -15,6 +15,10 @@ */ package org.xmolecules.ide.intellij; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiJavaFile; +import com.intellij.psi.util.CachedValueProvider; +import com.intellij.psi.util.CachedValuesManager; import com.intellij.lang.jvm.JvmModifier; import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiClass; @@ -46,21 +50,29 @@ /** * @author Oliver Drotbohm */ -class Concepts { - private static final Set CONCEPTS; +public class Concepts { + public static final Concept FACTORY = new Concept("Factory", "Factories", "black", JMolecules::isFactory); + public static final Concept SERVICE = new Concept("Service", "Services", "black", JMolecules::isService); + public static final Concept REPOSITORY = new Concept("Repository", "Repositories", "black", any(JMolecules::isRepository, Spring::isRepository)); + public static final Concept IDENTIFIER = new Concept("Identifier", "Identifiers", "black", JMolecules::isIdentifier); + public static final Concept VALUE_OBJECT = new Concept("Value Object", "Value objects", "black", it -> JMolecules.isValueObject(it) && !JMolecules.isIdentifier(it)); + public static final Concept ENTITY = new Concept("Entity", "Entities", "black", it -> JMolecules.isEntity(it) && !JMolecules.isAggregateRoot(it)); + public static final Concept AGGREGATE_ROOT = new Concept("Aggregate Root", "Aggregate roots", "black", JMolecules::isAggregateRoot); + public static final Concept EVENT = new Concept("Event", "Events", "black", JMolecules::isEvent); + public static final Concept EVENT_LISTENER = new Concept("Event listener", "Event listeners", "black", + any(JMolecules::isEventListener, Spring::isEventListener)); static { - CONCEPTS = Set.of( - new Concept("Factory", "Factories", JMolecules::isFactory), - new Concept("Service", "Services", JMolecules::isService), - new Concept("Repository", "Repositories", any(JMolecules::isRepository, Spring::isRepository)), - new Concept("Identifier", "Identifiers", JMolecules::isIdentifier), - new Concept("Value Object", "Value objects", it -> JMolecules.isValueObject(it) && !JMolecules.isIdentifier(it)), - new Concept("Entity", "Entities", it -> JMolecules.isEntity(it) && !JMolecules.isAggregateRoot(it)), - new Concept("Aggregate Root", "Aggregate roots", JMolecules::isAggregateRoot), - new Concept("Event", "Events", JMolecules::isEvent), - new Concept("Event listener", "Event listeners", - any(JMolecules::isEventListener, Spring::isEventListener)) + var CONCEPTS = Set.of( + FACTORY, + SERVICE, + REPOSITORY, + IDENTIFIER, + VALUE_OBJECT, + ENTITY, + AGGREGATE_ROOT, + EVENT, + EVENT_LISTENER ); } @@ -80,9 +92,10 @@ class Concepts { return Collections.emptyList(); } - return CachedValuesManager.getCachedValue(file, () -> - new CachedValueProvider.Result<>(CONCEPTS.stream() + return CachedValuesManager.getCachedValue(file, + () -> new CachedValueProvider.Result<>(All.ALL.stream() .filter(it -> it.test((PsiJavaFile) file)) + .map(ConceptImplementation::getConcept) .collect(Collectors.toList()), file) ); } diff --git a/src/main/java/org/xmolecules/ide/intellij/JMolecules.java b/src/main/java/org/xmolecules/ide/intellij/JMolecules.java new file mode 100644 index 0000000..ac38918 --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/JMolecules.java @@ -0,0 +1,78 @@ +package org.xmolecules.ide.intellij; + +import com.intellij.openapi.roots.ExternalLibraryDescriptor; +import com.intellij.psi.PsiJavaFile; +import nexos.intellij.ddd.Framework; + +import java.util.List; + +import static org.xmolecules.ide.intellij.Types.implementsType; +import static org.xmolecules.ide.intellij.Types.isTypeAnnotatedWith; + +public class JMolecules { + + public static final Framework FRAMEWORK = new Framework("JMolecules"); + public static final Library DDDLib = new Library(FRAMEWORK, new ExternalLibraryDescriptor("org.jmolecules","jmolecules-ddd")); + public static final Library EventsLib = new Library(FRAMEWORK, new ExternalLibraryDescriptor("org.jmolecules","jmolecules-events")); + public static final Library LayeredArchitectureLib = new Library(FRAMEWORK, new ExternalLibraryDescriptor("org.jmolecules","jmolecules-layered-architecture")); + public static final Library OnionArchitectureLib = new Library(FRAMEWORK, new ExternalLibraryDescriptor("org.jmolecules","jmolecules-onion-architecture")); + + private static final String BASE_PACKAGE = "org.jmolecules"; + private static final String DDD_BASE_PACKAGE = BASE_PACKAGE + ".ddd"; + private static final String EVENT_BASE_PACKAGE = BASE_PACKAGE + ".event"; + + public static final ConceptImplementation FACTORY = new ConceptViaTypeAnnotation(Concepts.FACTORY, DDDLib, DDD_BASE_PACKAGE + ".annotation.Factory"); + public static final ConceptImplementation SERVICE = new ConceptViaTypeAnnotation(Concepts.SERVICE, DDDLib, DDD_BASE_PACKAGE + ".annotation.Service"); + public static final ConceptImplementation REPOSITORY_VIA_IMPLEMENTS = new ConceptViaImplements(Concepts.REPOSITORY,DDDLib, DDD_BASE_PACKAGE + ".types.Repository"); + public static final ConceptImplementation REPOSITORY_VIA_TYPE_ANNOTATION = new ConceptViaTypeAnnotation(Concepts.REPOSITORY,DDDLib, DDD_BASE_PACKAGE + ".annotation.Repository"); + public static final ConceptImplementation IDENTIFIER = new ConceptViaImplements(Concepts.IDENTIFIER, DDDLib, DDD_BASE_PACKAGE + ".types.Identifier"); + + //FIXME public static final ConceptImplementation VALUE_OBJECT = new ConceptImplementation(Concepts.VALUE_OBJECT, DDDLib, it -> JMolecules.isValueObject(it) && !JMolecules.isIdentifier(it), fqName); + //FIXME public static final ConceptImplementation ENTITY = new ConceptImplementation(Concepts.ENTITY, DDDLib, it -> JMolecules.isEntity(it) && !JMolecules.isAggregateRoot(it), fqName); + + public static final ConceptImplementation AGGREGATE_ROOT_VIA_IMPLEMENTS = new ConceptViaImplements(Concepts.AGGREGATE_ROOT, DDDLib, DDD_BASE_PACKAGE + ".types.AggregateRoot"); + public static final ConceptImplementation AGGREGATE_ROOT_VIA_TYPE_ANNOTATION = new ConceptViaTypeAnnotation(Concepts.AGGREGATE_ROOT, DDDLib, DDD_BASE_PACKAGE + ".annotation.AggregateRoot"); + public static final ConceptImplementation EVENT_VIA_IMPLEMENTS = new ConceptViaImplements(Concepts.EVENT,EventsLib, EVENT_BASE_PACKAGE + ".types.DomainEvent"); + public static final ConceptImplementation EVENT_VIA_TYPE_ANNOTATION = new ConceptViaTypeAnnotation(Concepts.EVENT,EventsLib, EVENT_BASE_PACKAGE + ".annotation.DomainEvent"); + public static final ConceptImplementation EVENT_LISTENER = new ConceptViaTypeAnnotation(Concepts.EVENT_LISTENER, EventsLib,EVENT_BASE_PACKAGE + ".types.DomainEventHandler"); + + public static final List ALL = List.of(FACTORY, SERVICE, REPOSITORY_VIA_IMPLEMENTS, + REPOSITORY_VIA_TYPE_ANNOTATION, IDENTIFIER, /* VALUE_OBJECT, ENTITY, */ AGGREGATE_ROOT_VIA_IMPLEMENTS, + AGGREGATE_ROOT_VIA_TYPE_ANNOTATION, EVENT_VIA_IMPLEMENTS, EVENT_VIA_TYPE_ANNOTATION, EVENT_LISTENER); + + static boolean isIdentifier(final PsiJavaFile file) { + return implementsType(DDD_BASE_PACKAGE + ".types.Identifier", file); + } + + static boolean isEntity(final PsiJavaFile file) { + return implementsType(DDD_BASE_PACKAGE + ".types." + "Entity", file) || + isTypeAnnotatedWith(DDD_BASE_PACKAGE + ".annotation." + "Entity", file); + } + + static boolean isAggregateRoot(final PsiJavaFile file) { + return implementsType(DDD_BASE_PACKAGE + ".types." + "AggregateRoot", file) || + isTypeAnnotatedWith(DDD_BASE_PACKAGE + ".annotation." + "AggregateRoot", file); + } + + static boolean isValueObject(final PsiJavaFile file) { + return isTypeAnnotatedWith(DDD_BASE_PACKAGE + ".annotation.ValueObject", file); + } +} + +/* +val DomainEvent = Info("org.jmolecules.event.annotation.DomainEvent", ddd_DomainEvent, EventsLib) + +val ApplicationLayer = Info("org.jmolecules.architecture.layered.ApplicationLayer", ddd_ApplicationLayer, LayeredArchitectureLib) +val DomainLayer = Info("org.jmolecules.architecture.layered.DomainLayer", ddd_DomainLayer, LayeredArchitectureLib) +val InfrastructureLayer = Info("org.jmolecules.architecture.layered.InfrastructureLayer", ddd_InfrastructureLayer, LayeredArchitectureLib) +val InterfaceLayer = Info("org.jmolecules.architecture.layered.InterfaceLayer", ddd_InterfaceLayer, LayeredArchitectureLib) + +val ClassicApplicationServiceRing = Info("org.jmolecules.architecture.onion.classical.ApplicationServiceRing", ddd_ClassicApplicationServiceRing, OnionArchitectureLib) +val ClassicDomainModelRing = Info("org.jmolecules.architecture.onion.classical.DomainModelRing", ddd_ClassicDomainModelRing, OnionArchitectureLib) +val ClassicInfrastructureRing = Info("org.jmolecules.architecture.onion.classical.InfrastructureRing", ddd_ClassicInfrastructureRing, OnionArchitectureLib) + +val SimplifiedApplicationRing = Info("org.jmolecules.architecture.onion.simplified.ApplicationRing", ddd_SimplifiedApplicationRing, OnionArchitectureLib) +val SimplifiedDomainRing = Info("org.jmolecules.architecture.onion.simplified.DomainRing", ddd_SimplifiedDomainRing, OnionArchitectureLib) +val SimplifiedInfrastructureRing = Info("org.jmolecules.architecture.onion.simplified.InfrastructureRing", ddd_SimplifiedInfrastructureRing, OnionArchitectureLib) + + */ diff --git a/src/main/java/org/xmolecules/ide/intellij/JPA.java b/src/main/java/org/xmolecules/ide/intellij/JPA.java new file mode 100644 index 0000000..a21d46f --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/JPA.java @@ -0,0 +1,15 @@ +package org.xmolecules.ide.intellij; + +import com.intellij.openapi.roots.ExternalLibraryDescriptor; +import nexos.intellij.ddd.Framework; + +import java.util.List; + +public class JPA { + public static final Framework JPA = new Framework("JPA"); + public static final Library LIB = new Library(JPA, new ExternalLibraryDescriptor("javax.persistence", "javax.persistence-api")); + + public static final ConceptImplementation Entity = new ConceptViaTypeAnnotation(Concepts.ENTITY, LIB, "javax.persistence.Entity"); + public static final ConceptImplementation Embeddable = new ConceptViaTypeAnnotation(Concepts.VALUE_OBJECT, LIB, "javax.persistence.Embeddable"); + public static final List ALL = List.of(Entity, Embeddable); +} diff --git a/src/main/java/org/xmolecules/ide/intellij/Library.java b/src/main/java/org/xmolecules/ide/intellij/Library.java new file mode 100644 index 0000000..e3cbb7e --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/Library.java @@ -0,0 +1,22 @@ +package org.xmolecules.ide.intellij; + +import com.intellij.openapi.roots.ExternalLibraryDescriptor; +import nexos.intellij.ddd.Framework; + +public class Library { + private final Framework framework; + private final ExternalLibraryDescriptor externalLibrary; + + public Library(final Framework framework, final ExternalLibraryDescriptor externalLibrary) { + this.framework = framework; + this.externalLibrary = externalLibrary; + } + + public Framework getFramework() { + return framework; + } + + public ExternalLibraryDescriptor getExternalLibrary() { + return externalLibrary; + } +} diff --git a/src/main/java/org/xmolecules/ide/intellij/Spring.java b/src/main/java/org/xmolecules/ide/intellij/Spring.java new file mode 100644 index 0000000..e283595 --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/Spring.java @@ -0,0 +1,24 @@ +package org.xmolecules.ide.intellij; + +import com.intellij.openapi.roots.ExternalLibraryDescriptor; +import com.intellij.psi.PsiJavaFile; +import nexos.intellij.ddd.Framework; + +import java.util.List; + +import static org.xmolecules.ide.intellij.Types.hasMethodAnnotatedWith; +import static org.xmolecules.ide.intellij.Types.implementsType; +import static org.xmolecules.ide.intellij.Types.isTypeAnnotatedWith; + +public class Spring { + private static final String BASE_PACKAGE = "org.springframework.data"; + + private static final Framework FRAMEWORK = new Framework("Spring"); + private static final Library LIB = new Library(FRAMEWORK, new ExternalLibraryDescriptor("org.springframework", "")); + public static final ConceptImplementation REPOSITORY_VIA_IMPLEMENTS = new ConceptViaImplements(Concepts.REPOSITORY,LIB, BASE_PACKAGE + ".repository.Repository"); + public static final ConceptImplementation REPOSITORY_VIA_TYPE_ANNOTATION = new ConceptViaTypeAnnotation(Concepts.REPOSITORY,LIB, "org.springframework.stereotype.Repository"); + public static final ConceptImplementation EVENT_LISTENER = new ConceptViaMethodAnnotation(Concepts.EVENT_LISTENER, LIB, "org.springframework.context.event.EventListener"); + public static final ConceptImplementation EVENT_LISTENER_TRANSACTIONAL = new ConceptViaMethodAnnotation(Concepts.EVENT_LISTENER, LIB,"org.springframework.transaction.event.TransactionalEventListener"); + + public static final List ALL = List.of(REPOSITORY_VIA_IMPLEMENTS, REPOSITORY_VIA_TYPE_ANNOTATION, EVENT_LISTENER, EVENT_LISTENER_TRANSACTIONAL); +} diff --git a/src/main/java/org/xmolecules/ide/intellij/Types.java b/src/main/java/org/xmolecules/ide/intellij/Types.java new file mode 100644 index 0000000..c503ef8 --- /dev/null +++ b/src/main/java/org/xmolecules/ide/intellij/Types.java @@ -0,0 +1,92 @@ +package org.xmolecules.ide.intellij; + +import com.intellij.lang.jvm.JvmModifier; +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiJavaFile; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +class Types { + + static boolean isTypeAnnotatedWith(final String annotation, final PsiJavaFile file) { + return Arrays.stream(file.getClasses()) + .filter(it -> !it.isAnnotationType()) // exclude top-level annotations + .flatMap(Types::getAllAnnotations) + .anyMatch(it -> it.getQualifiedName().equals(annotation)); + } + + static boolean implementsType(final String name, final PsiJavaFile file) { + return Arrays.stream(file.getClasses()) + .filter(it -> !it.hasModifier(JvmModifier.ABSTRACT) || it.isInterface()) + .flatMap(Types::getAllSuperTypes) + .flatMap(Types::getAllInterfaces) + .peek(System.out::println) //TODO remove + .anyMatch(it -> it.getQualifiedName().equals(name)); + } + + static boolean hasMethodAnnotatedWith(final PsiJavaFile file, final String... name) { + + final Predicate nameMatches = it -> Arrays.asList(name).contains(it.getQualifiedName()); + + final List annotations = Arrays.stream(file.getClasses()) + .flatMap(it -> Arrays.stream(it.getMethods())) + .flatMap(it -> Arrays.stream(it.getAnnotations())) + .distinct() + .collect(Collectors.toList()); + + if (annotations.stream().anyMatch(nameMatches)) { + return true; + } + + return annotations.stream() + .map(PsiAnnotation::resolveAnnotationType) + .flatMap(Types::getAllAnnotations) + .distinct() + .anyMatch(nameMatches); + } + + private static Stream getAllAnnotations(final PsiClass type) { + if (type == null) { + return Stream.empty(); + } + + final List annotations = Arrays.stream(type.getAnnotations()) + .filter(it -> !it.getQualifiedName().startsWith("java")) + .collect(Collectors.toList()); + + final Stream metaAnnotations = annotations.stream() + .map(PsiAnnotation::resolveAnnotationType) + .flatMap(Types::getAllAnnotations); + + return Stream.concat(annotations.stream(), metaAnnotations).distinct(); + } + + private static Stream getAllInterfaces(final PsiClass type) { + + Stream interfaces = Arrays.stream(type.getInterfaces()); + Stream self = type.isInterface() ? Stream.of(type) : Stream.empty(); + + return Stream.concat(self, interfaces.flatMap(Types::getAllInterfaces)); + } + + private static Stream getAllSuperTypes(final PsiClass type) { + + var thisType = Stream.of(type); + + if (type.isInterface()) { + return thisType; + } + + var superClass = type.getSuperClass(); + + return superClass == null || superClass.getQualifiedName().equals("java.lang.Object") + ? thisType + : Stream.concat(thisType, getAllSuperTypes(superClass)); + + } +} diff --git a/src/main/kotlin/nexos/intellij/ddd/DDDGroup.kt b/src/main/kotlin/nexos/intellij/ddd/DDDGroup.kt index 66bd498..91d61ab 100644 --- a/src/main/kotlin/nexos/intellij/ddd/DDDGroup.kt +++ b/src/main/kotlin/nexos/intellij/ddd/DDDGroup.kt @@ -1,5 +1,6 @@ package nexos.intellij.ddd +/* import com.intellij.framework.FrameworkGroup import com.intellij.icons.AllIcons import nexos.intellij.ddd.jddd.jDDD @@ -13,4 +14,5 @@ class DDDGroup(val framework: Framework, val versions: List): Framew override fun getIcon() = AllIcons.Ide.LocalScope override fun getGroupVersions(): MutableList = versions.toMutableList() -} \ No newline at end of file +} +*/ diff --git a/src/main/kotlin/nexos/intellij/ddd/DDDLibraryResolver.kt b/src/main/kotlin/nexos/intellij/ddd/DDDLibraryResolver.kt index c11b56f..99eac2c 100644 --- a/src/main/kotlin/nexos/intellij/ddd/DDDLibraryResolver.kt +++ b/src/main/kotlin/nexos/intellij/ddd/DDDLibraryResolver.kt @@ -5,6 +5,9 @@ import com.intellij.openapi.module.Module import com.intellij.util.ThreeState import com.intellij.util.ThreeState.NO import java.util.* +import org.xmolecules.ide.intellij.All +import org.xmolecules.ide.intellij.ConceptImplementation +import java.util.* /** * Text autocompletion on annotation names. @@ -15,16 +18,12 @@ import java.util.* */ class DDDLibraryResolver : ExternalLibraryResolver() { companion object { - //FIXME create fqName.typename => Info - val names by lazy { all.associateBy { it.concept.name.lowercase(Locale.getDefault()) } } + val names by lazy { All.ALL.associateBy { it.concept.name.lowercase(Locale.getDefault()) } } //TODO Locale from IDEA environment } override fun resolveClass(shortClassName: String, isAnnotation: ThreeState, contextModule: Module): ExternalClassResolveResult? { - if (isAnnotation != NO) { - return names[shortClassName.lowercase(Locale.getDefault())]?.let { result(it) } - } - return null + return names[shortClassName.lowercase(Locale.getDefault())]?.let { result(it) } //TODO find Locale } - private fun result(info: Info) = ExternalClassResolveResult(info.fqName, info.library.externalLibrary) + private fun result(info: ConceptImplementation) = ExternalClassResolveResult(info.fqName, info.library.externalLibrary) } diff --git a/src/main/kotlin/nexos/intellij/ddd/FrameworkType.kt b/src/main/kotlin/nexos/intellij/ddd/FrameworkType.kt index f874bf9..e633df7 100644 --- a/src/main/kotlin/nexos/intellij/ddd/FrameworkType.kt +++ b/src/main/kotlin/nexos/intellij/ddd/FrameworkType.kt @@ -1,5 +1,6 @@ package nexos.intellij.ddd +/* import com.intellij.framework.FrameworkTypeEx import com.intellij.icons.AllIcons @@ -12,4 +13,6 @@ abstract class FrameworkType( override fun getIcon() = AllIcons.Ide.LocalScope override fun getParentGroup():DDDGroup = parent -} \ No newline at end of file +} + + */ diff --git a/src/main/kotlin/nexos/intellij/ddd/Info.kt b/src/main/kotlin/nexos/intellij/ddd/Info.kt deleted file mode 100644 index 658049d..0000000 --- a/src/main/kotlin/nexos/intellij/ddd/Info.kt +++ /dev/null @@ -1,3 +0,0 @@ -package nexos.intellij.ddd - -data class Info(val fqName: String, val concept: Concept, val library: Library) \ No newline at end of file diff --git a/src/main/kotlin/nexos/intellij/ddd/Provider.kt b/src/main/kotlin/nexos/intellij/ddd/Provider.kt index 12a8495..b4b17a3 100644 --- a/src/main/kotlin/nexos/intellij/ddd/Provider.kt +++ b/src/main/kotlin/nexos/intellij/ddd/Provider.kt @@ -1,5 +1,6 @@ package nexos.intellij.ddd +/* import com.intellij.openapi.externalSystem.model.project.ProjectId import com.intellij.openapi.module.JavaModuleType import com.intellij.openapi.module.Module @@ -23,3 +24,4 @@ abstract class Provider(private val library: Library): GradleFrameworkSupportPro abstract override fun getFrameworkType(): FrameworkType } +*/ diff --git a/src/main/kotlin/nexos/intellij/ddd/all.kt b/src/main/kotlin/nexos/intellij/ddd/all.kt deleted file mode 100644 index 1667d85..0000000 --- a/src/main/kotlin/nexos/intellij/ddd/all.kt +++ /dev/null @@ -1,7 +0,0 @@ -package nexos.intellij.ddd - -import nexos.intellij.ddd.jddd.jDDD -import nexos.intellij.ddd.jmolecules.jMolecules -import nexos.intellij.ddd.jpa.JPA - -val all by lazy { jDDD.all + jMolecules.all + JPA.all} \ No newline at end of file diff --git a/src/main/kotlin/nexos/intellij/ddd/concepts.kt b/src/main/kotlin/nexos/intellij/ddd/concepts.kt deleted file mode 100644 index 5912bcf..0000000 --- a/src/main/kotlin/nexos/intellij/ddd/concepts.kt +++ /dev/null @@ -1,23 +0,0 @@ -package nexos.intellij.ddd - -open class Concept(val name: String, val defaultColorName:String? = null) - -object Entity: Concept("Entity") -object AggregateRoot: Concept("AggregateRoot") -object BoundedContext: Concept("BoundedContext") -object Factory: Concept("Factory") -object Module: Concept("Module") -object Repository: Concept("Repository") -object Service: Concept("Service") -object ValueObject: Concept("ValueObject") -object DomainEvent: Concept("DomainEvent") -object ApplicationLayer: Concept("ApplicationLayer") -object DomainLayer: Concept("DomainLayer") -object InfrastructureLayer: Concept("InfrastructureLayer") -object InterfaceLayer: Concept("InterfaceLayer") -object ClassicApplicationServiceRing: Concept("ClassicApplicationServiceRing") -object ClassicDomainModelRing: Concept("ClassicDomainModelRing") -object ClassicInfrastructureRing: Concept("ClassicInfrastructureRing") -object SimplifiedApplicationRing: Concept("SimplifiedApplicationRing") -object SimplifiedDomainRing: Concept("SimplifiedDomainRing") -object SimplifiedInfrastructureRing: Concept("SimplifiedInfrastructureRing") \ No newline at end of file diff --git a/src/main/kotlin/nexos/intellij/ddd/jddd/ArchitectureLayered.kt b/src/main/kotlin/nexos/intellij/ddd/jddd/ArchitectureLayered.kt index b247006..5b93e19 100644 --- a/src/main/kotlin/nexos/intellij/ddd/jddd/ArchitectureLayered.kt +++ b/src/main/kotlin/nexos/intellij/ddd/jddd/ArchitectureLayered.kt @@ -1,5 +1,6 @@ package nexos.intellij.ddd.jddd +/* import nexos.intellij.ddd.DDDGroup import nexos.intellij.ddd.FrameworkType import nexos.intellij.ddd.Provider @@ -18,4 +19,6 @@ class ArchitectureLayeredFramework : FrameworkType(ArchitectureLayeredLib, DDDGr } override fun createProvider() = ArchitectureLayeredProvider.INSTANCE -} \ No newline at end of file +} + + */ diff --git a/src/main/kotlin/nexos/intellij/ddd/jddd/Support.kt b/src/main/kotlin/nexos/intellij/ddd/jddd/Support.kt index 82eef09..9faef4c 100644 --- a/src/main/kotlin/nexos/intellij/ddd/jddd/Support.kt +++ b/src/main/kotlin/nexos/intellij/ddd/jddd/Support.kt @@ -1,5 +1,6 @@ package nexos.intellij.ddd.jddd +/* import com.intellij.facet.ui.FacetBasedFrameworkSupportProvider import com.intellij.ide.util.frameworkSupport.FrameworkVersion import com.intellij.openapi.roots.JavaProjectModelModificationService @@ -13,4 +14,6 @@ class Support: FacetBasedFrameworkSupportProvider(RootFacetType.INSTAN .addDependency(rootModel.module, facet.library.externalLibrary) } } -} \ No newline at end of file +} + + */ diff --git a/src/main/kotlin/nexos/intellij/ddd/jddd/core.kt b/src/main/kotlin/nexos/intellij/ddd/jddd/core.kt index 3fbfa16..3df392c 100644 --- a/src/main/kotlin/nexos/intellij/ddd/jddd/core.kt +++ b/src/main/kotlin/nexos/intellij/ddd/jddd/core.kt @@ -1,5 +1,5 @@ package nexos.intellij.ddd.jddd - +/* import nexos.intellij.ddd.DDDGroup import nexos.intellij.ddd.FrameworkType import nexos.intellij.ddd.Provider @@ -18,4 +18,6 @@ class CoreFramework: FrameworkType(CoreLib, DDDGroup.INSTANCE) { } override fun createProvider() = CoreProvider.INSTANCE -} \ No newline at end of file +} + + */ diff --git a/src/main/kotlin/nexos/intellij/ddd/jddd/domainEvent.kt b/src/main/kotlin/nexos/intellij/ddd/jddd/domainEvent.kt index 9dbd537..5d90ac2 100644 --- a/src/main/kotlin/nexos/intellij/ddd/jddd/domainEvent.kt +++ b/src/main/kotlin/nexos/intellij/ddd/jddd/domainEvent.kt @@ -1,5 +1,5 @@ package nexos.intellij.ddd.jddd - +/* import nexos.intellij.ddd.DDDGroup import nexos.intellij.ddd.FrameworkType import nexos.intellij.ddd.Provider @@ -18,4 +18,6 @@ class DomainEventFramework: FrameworkType(DomainEventLib, DDDGroup.INSTANCE) { } override fun createProvider() = DomainEventProvider.INSTANCE -} \ No newline at end of file +} + + */ diff --git a/src/main/kotlin/nexos/intellij/ddd/jddd/facet.kt b/src/main/kotlin/nexos/intellij/ddd/jddd/facet.kt index 2307479..5a59d90 100644 --- a/src/main/kotlin/nexos/intellij/ddd/jddd/facet.kt +++ b/src/main/kotlin/nexos/intellij/ddd/jddd/facet.kt @@ -1,5 +1,5 @@ package nexos.intellij.ddd.jddd - +/* import com.intellij.facet.Facet import com.intellij.facet.FacetType import com.intellij.facet.FacetTypeId @@ -40,4 +40,6 @@ class RootFacetType: FacetType(ID, "jDDD", "jDDD") = null override fun isSuitableModuleType(moduleType: ModuleType<*>?) = moduleType is JavaModuleType -} \ No newline at end of file +} + + */ diff --git a/src/main/kotlin/nexos/intellij/ddd/jddd/jddd.kt b/src/main/kotlin/nexos/intellij/ddd/jddd/jddd.kt index cab5d61..cfb2907 100644 --- a/src/main/kotlin/nexos/intellij/ddd/jddd/jddd.kt +++ b/src/main/kotlin/nexos/intellij/ddd/jddd/jddd.kt @@ -1,5 +1,6 @@ package nexos.intellij.ddd.jddd +/* import com.intellij.openapi.roots.ExternalLibraryDescriptor import nexos.intellij.ddd.Framework import nexos.intellij.ddd.Info @@ -35,4 +36,4 @@ val DomainLayer = Info("org.jddd.architecture.layered.DomainLayer", ddd_DomainLa val InfrastructureLayer = Info("org.jddd.architecture.layered.InfrastructureLayer", ddd_InfrastructureLayer, ArchitectureLayeredLib) val InterfaceLayer = Info("org.jddd.architecture.layered.InterfaceLayer",ddd_InterfaceLayer, ArchitectureLayeredLib) val DomainEvent = Info("org.jddd.event.annotation.DomainEvent", ddd_DomainEvent, DomainEventLib) - +*/ diff --git a/src/main/kotlin/nexos/intellij/ddd/jmolecules/jmolecules.kt b/src/main/kotlin/nexos/intellij/ddd/jmolecules/jmolecules.kt deleted file mode 100644 index ef0fff4..0000000 --- a/src/main/kotlin/nexos/intellij/ddd/jmolecules/jmolecules.kt +++ /dev/null @@ -1,64 +0,0 @@ -package nexos.intellij.ddd.jmolecules - -import com.intellij.openapi.roots.ExternalLibraryDescriptor -import nexos.intellij.ddd.Framework -import nexos.intellij.ddd.Info -import nexos.intellij.ddd.Library -import nexos.intellij.ddd.Repository as ddd_Repository -import nexos.intellij.ddd.AggregateRoot as ddd_AggregateRoot -import nexos.intellij.ddd.Entity as ddd_Entity -import nexos.intellij.ddd.Factory as ddd_Factory -import nexos.intellij.ddd.Service as ddd_Service -import nexos.intellij.ddd.ValueObject as ddd_ValueObject -import nexos.intellij.ddd.ApplicationLayer as ddd_ApplicationLayer -import nexos.intellij.ddd.DomainLayer as ddd_DomainLayer -import nexos.intellij.ddd.InfrastructureLayer as ddd_InfrastructureLayer -import nexos.intellij.ddd.InterfaceLayer as ddd_InterfaceLayer -import nexos.intellij.ddd.DomainEvent as ddd_DomainEvent -import nexos.intellij.ddd.BoundedContext as ddd_BoundedContext -import nexos.intellij.ddd.Module as ddd_Module -import nexos.intellij.ddd.ClassicApplicationServiceRing as ddd_ClassicApplicationServiceRing -import nexos.intellij.ddd.ClassicDomainModelRing as ddd_ClassicDomainModelRing -import nexos.intellij.ddd.ClassicInfrastructureRing as ddd_ClassicInfrastructureRing -import nexos.intellij.ddd.SimplifiedApplicationRing as ddd_SimplifiedApplicationRing -import nexos.intellij.ddd.SimplifiedDomainRing as ddd_SimplifiedDomainRing -import nexos.intellij.ddd.SimplifiedInfrastructureRing as ddd_SimplifiedInfrastructureRing - -object jMolecules: Framework("jMolecules") { - val all by lazy { listOf( - Entity, AggregateRoot, BoundedContext, Factory, Module, Repository, Service, ValueObject, - DomainEvent, - ApplicationLayer, DomainLayer, InfrastructureLayer, InterfaceLayer, - ClassicApplicationServiceRing, ClassicDomainModelRing, ClassicInfrastructureRing, - SimplifiedApplicationRing, SimplifiedDomainRing, SimplifiedInfrastructureRing - )} -} - -val DDDLib = Library(jMolecules, ExternalLibraryDescriptor("org.jmolecules","jmolecules-ddd")) -val EventsLib = Library(jMolecules, ExternalLibraryDescriptor("org.jmolecules","jmolecules-events")) -val LayeredArchitectureLib = Library(jMolecules, ExternalLibraryDescriptor("org.jmolecules","jmolecules-layered-architecture")) -val OnionArchitectureLib = Library(jMolecules, ExternalLibraryDescriptor("org.jmolecules","jmolecules-onion-architecture")) - -val Entity = Info("org.jmolecules.ddd.annotation.Entity", ddd_Entity, DDDLib) -val AggregateRoot = Info("org.jmolecules.ddd.annotation.AggregateRoot", ddd_AggregateRoot, DDDLib) -val BoundedContext = Info("org.jmolecules.ddd.annotation.BoundedContext", ddd_BoundedContext, DDDLib) -val Factory = Info("org.jmolecules.ddd.annotation.Factory", ddd_Factory, DDDLib) -val Module = Info("org.jmolecules.ddd.annotation.Module", ddd_Module, DDDLib) -val Repository = Info("org.jmolecules.ddd.annotation.Repository", ddd_Repository, DDDLib) -val Service = Info("org.jmolecules.ddd.annotation.Service", ddd_Service, DDDLib) -val ValueObject = Info("org.jmolecules.ddd.annotation.ValueObject", ddd_ValueObject, DDDLib) - -val DomainEvent = Info("org.jmolecules.event.annotation.DomainEvent", ddd_DomainEvent, EventsLib) - -val ApplicationLayer = Info("org.jmolecules.architecture.layered.ApplicationLayer", ddd_ApplicationLayer, LayeredArchitectureLib) -val DomainLayer = Info("org.jmolecules.architecture.layered.DomainLayer", ddd_DomainLayer, LayeredArchitectureLib) -val InfrastructureLayer = Info("org.jmolecules.architecture.layered.InfrastructureLayer", ddd_InfrastructureLayer, LayeredArchitectureLib) -val InterfaceLayer = Info("org.jmolecules.architecture.layered.InterfaceLayer", ddd_InterfaceLayer, LayeredArchitectureLib) - -val ClassicApplicationServiceRing = Info("org.jmolecules.architecture.onion.classical.ApplicationServiceRing", ddd_ClassicApplicationServiceRing, OnionArchitectureLib) -val ClassicDomainModelRing = Info("org.jmolecules.architecture.onion.classical.DomainModelRing", ddd_ClassicDomainModelRing, OnionArchitectureLib) -val ClassicInfrastructureRing = Info("org.jmolecules.architecture.onion.classical.InfrastructureRing", ddd_ClassicInfrastructureRing, OnionArchitectureLib) - -val SimplifiedApplicationRing = Info("org.jmolecules.architecture.onion.simplified.ApplicationRing", ddd_SimplifiedApplicationRing, OnionArchitectureLib) -val SimplifiedDomainRing = Info("org.jmolecules.architecture.onion.simplified.DomainRing", ddd_SimplifiedDomainRing, OnionArchitectureLib) -val SimplifiedInfrastructureRing = Info("org.jmolecules.architecture.onion.simplified.InfrastructureRing", ddd_SimplifiedInfrastructureRing, OnionArchitectureLib) diff --git a/src/main/kotlin/nexos/intellij/ddd/jpa.kt b/src/main/kotlin/nexos/intellij/ddd/jpa.kt deleted file mode 100644 index e387c19..0000000 --- a/src/main/kotlin/nexos/intellij/ddd/jpa.kt +++ /dev/null @@ -1,17 +0,0 @@ -package nexos.intellij.ddd.jpa - -import com.intellij.openapi.roots.ExternalLibraryDescriptor -import nexos.intellij.ddd.Framework -import nexos.intellij.ddd.Info -import nexos.intellij.ddd.Library -import nexos.intellij.ddd.Entity as ddd_Entity -import nexos.intellij.ddd.ValueObject as ddd_ValueObject - -object JPA: Framework("JPA") { - //Version 2.2, 2.3-SNAPSHOT - val all by lazy { listOf(Entity, Embeddable) } -} -val lib = Library(JPA, ExternalLibraryDescriptor("javax.persistence", "javax.persistence-api")) - -val Entity = Info("javax.persistence.Entity", ddd_Entity, lib) -val Embeddable = Info("javax.persistence.Embeddable", ddd_ValueObject, lib) \ No newline at end of file diff --git a/src/main/kotlin/nexos/intellij/ddd/psijava.kt b/src/main/kotlin/nexos/intellij/ddd/psijava.kt deleted file mode 100644 index 0677b17..0000000 --- a/src/main/kotlin/nexos/intellij/ddd/psijava.kt +++ /dev/null @@ -1,29 +0,0 @@ -package nexos.intellij.ddd - -import com.intellij.psi.PsiJavaFile -import com.intellij.psi.util.CachedValueProvider -import com.intellij.psi.util.CachedValueProvider.Result -import com.intellij.psi.util.CachedValuesManager - -fun findPackageAnnotations(psiFile: PsiJavaFile, annotationsByFQName: Map) = - psiFile.packageStatement - ?.annotationList - ?.annotations - ?.mapNotNull { annotationsByFQName[it.qualifiedName] } - ?: listOf() - -fun findTopLevelClassAnnotations(psiFile: PsiJavaFile, annotationsByFQName: Map) - = psiFile.classes.map { it.annotations.mapNotNull { annotationsByFQName[it.qualifiedName] }}.flatten() - -class Cached(private val file: PsiJavaFile): CachedValueProvider> { - companion object { - val annotationsByFQName by lazy { all.associateBy { it.fqName }} - } - - override fun compute() = Result( - findPackageAnnotations(file, annotationsByFQName) - + findTopLevelClassAnnotations(file, annotationsByFQName) - , file) -} - -fun cached(file: PsiJavaFile): List = CachedValuesManager.getCachedValue(file, Cached(file)) \ No newline at end of file diff --git a/src/main/kotlin/nexos/intellij/ddd/scope.kt b/src/main/kotlin/nexos/intellij/ddd/scope.kt index 4201803..b11dc86 100644 --- a/src/main/kotlin/nexos/intellij/ddd/scope.kt +++ b/src/main/kotlin/nexos/intellij/ddd/scope.kt @@ -1,6 +1,7 @@ package nexos.intellij.ddd import com.intellij.icons.AllIcons +import org.xmolecules.ide.intellij.Concept import com.intellij.ide.highlighter.JavaFileType import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project @@ -10,6 +11,8 @@ import com.intellij.psi.search.scope.packageSet.AbstractPackageSet import com.intellij.psi.search.scope.packageSet.CustomScopesProvider import com.intellij.psi.search.scope.packageSet.NamedScope import com.intellij.psi.search.scope.packageSet.NamedScopesHolder +import org.xmolecules.ide.intellij.All +import org.xmolecules.ide.intellij.Concepts private class DDDPackageSet(private val concept: Concept): AbstractPackageSet(concept.name, 1) { @@ -17,7 +20,7 @@ private class DDDPackageSet(private val concept: Concept): AbstractPackageSet(co if (holder != null && file.fileType == JavaFileType.INSTANCE) { val psi = getPsiFile(file, holder.project) if (psi is PsiJavaFile) { - return cached(psi).any {it.concept == concept} + return Concepts.getConcepts(psi).any {it == concept} } } return false @@ -25,7 +28,7 @@ private class DDDPackageSet(private val concept: Concept): AbstractPackageSet(co override fun createCopy() = this - override fun getText() = concept.name + override fun getText(): String = concept.name override fun equals(other: Any?): Boolean { if(other is DDDPackageSet) { @@ -35,14 +38,11 @@ private class DDDPackageSet(private val concept: Concept): AbstractPackageSet(co } override fun hashCode() = concept.hashCode() - - @Deprecated("see com.intellij.psi.search.scope.packageSet.PackageSetBase", ReplaceWith("false")) - override fun contains(file: VirtualFile, holder: NamedScopesHolder?) = false } private class DDDNamedScope(private val concept: Concept): NamedScope(concept.name, AllIcons.Ide.LocalScope, DDDPackageSet(concept)) { - override fun getDefaultColorName() = concept.defaultColorName + override fun getDefaultColorName(): String = concept.defaultColorName override fun createCopy() = this @@ -58,8 +58,8 @@ private class DDDNamedScope(private val concept: Concept): class Scopes : CustomScopesProvider, DumbAware { companion object { - private val scopes: MutableList by lazy { all.groupBy {it.concept}.map { DDDNamedScope(it.key) }.toMutableList() } + private val scopes: MutableList by lazy { All.ALL.groupBy { it.concept }.map { DDDNamedScope(it.key) }.toMutableList() } } override fun getCustomScopes() = scopes -} \ No newline at end of file +} diff --git a/src/main/resources/META-INF/gradle.xml b/src/main/resources/META-INF/gradle.xml index 334b884..bacf796 100644 --- a/src/main/resources/META-INF/gradle.xml +++ b/src/main/resources/META-INF/gradle.xml @@ -1,6 +1,6 @@ - - + + - \ No newline at end of file + diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 9ec064e..2fd6a42 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -31,16 +31,16 @@ - - - - + + + + - - - + + + diff --git a/src/test/kotlin/nexos/intellij/ddd/PSITest.kt b/src/test/kotlin/nexos/intellij/ddd/PSITest.kt index b8fb98c..c468bab 100644 --- a/src/test/kotlin/nexos/intellij/ddd/PSITest.kt +++ b/src/test/kotlin/nexos/intellij/ddd/PSITest.kt @@ -7,6 +7,7 @@ import com.intellij.testFramework.fixtures.BasePlatformTestCase import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.xmolecules.ide.intellij.Concepts class PSITest : BasePlatformTestCase() { @BeforeEach @@ -25,12 +26,12 @@ class PSITest : BasePlatformTestCase() { .createFileFromText( findLanguageByID("JAVA")!!, """ - @org.jmolecules.ddd.annotation.Entity + @org.jmolecules.ddd.types.Entity class EntityTest {} """.trimIndent() ) if (psiFile is PsiJavaFile) { - val result = findTopLevelClassAnnotations(psiFile, Cached.annotationsByFQName) + val result = Concepts.getConcepts(psiFile) assertTrue(result.isNotEmpty()) } else { throw IllegalStateException() @@ -38,4 +39,4 @@ class PSITest : BasePlatformTestCase() { } override fun isWriteActionRequired() = true -} \ No newline at end of file +}