Skip to content

Attempt to use new persistance namespaces without breaking BC #1407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public class SymfonyPhpReferenceContributor extends PsiReferenceContributor {
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ManagerRegistry", "getRepository"),
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ObjectManager", "getRepository"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ManagerRegistry", "getRepository"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ObjectManager", "getRepository"),
new MethodMatcher.CallToSignature("\\Doctrine\\ORM\\EntityManager", "getReference"),
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ManagerRegistry", "getManagerForClass"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ManagerRegistry", "getManagerForClass"),
new MethodMatcher.CallToSignature("\\Doctrine\\ORM\\QueryBuilder", "update"),
new MethodMatcher.CallToSignature("\\Doctrine\\ORM\\QueryBuilder", "delete"),
new MethodMatcher.CallToSignature("\\Doctrine\\ORM\\QueryBuilder", "from"),
Expand Down Expand Up @@ -161,6 +163,7 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @No

MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(psiElement, 0)
.withSignature("\\Doctrine\\Common\\Persistence\\ObjectManager", "find")
.withSignature("\\Doctrine\\Persistence\\ObjectManager", "find")
.match();

if(methodMatchParameter == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ public static Collection<DoctrineModel> getModelClasses(Project project, Map<Str

PhpClass repositoryInterface = PhpElementsUtil.getInterface(PhpIndex.getInstance(project), DoctrineTypes.REPOSITORY_INTERFACE);

if(repositoryInterface == null) {
repositoryInterface = PhpElementsUtil.getInterface(PhpIndex.getInstance(project), "\\Doctrine\\Persistence\\ObjectRepository");
}

Collection<DoctrineModel> models = new ArrayList<>();
for (Map.Entry<String, String> entry : shortcutNames.entrySet()) {
for(PhpClass phpClass: PhpIndexUtil.getPhpClassInsideNamespace(project, entry.getValue())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public Collection<? extends PhpNamedElement> getBySignature(String expression, S
return Collections.emptySet();
}

if (!PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Doctrine\\Common\\Persistence\\ObjectManager", "find")) {
if (!(
PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Doctrine\\Common\\Persistence\\ObjectManager", "find") ||
PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Doctrine\\Persistence\\ObjectManager", "find")
)) {
return Collections.emptySet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class ObjectRepositoryResultTypeProvider implements PhpTypeProvider3 {
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findOneBy"),
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findAll"),
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findBy"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ObjectRepository", "find"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ObjectRepository", "findOneBy"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ObjectRepository", "findAll"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ObjectRepository", "findBy"),
};

final static char TRIM_KEY = '\u0184';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ObjectRepositoryTypeProvider implements PhpTypeProvider3 {
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ManagerRegistry", "getRepository"),
new MethodMatcher.CallToSignature("\\Doctrine\\Common\\Persistence\\ObjectManager", "getRepository"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ManagerRegistry", "getRepository"),
new MethodMatcher.CallToSignature("\\Doctrine\\Persistence\\ObjectManager", "getRepository"),
};

final public static char TRIM_KEY = '\u0185';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters
if(!(
PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Doctrine\\Common\\Persistence\\ObjectManager", "getRepository") ||
PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Doctrine\\Common\\Persistence\\ManagerRegistry", "getRepository") ||
PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Doctrine\\Persistence\\ObjectManager", "getRepository") ||
PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "Doctrine\\Persistence\\ManagerRegistry", "getRepository")
)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull Psi

return null != new MethodMatcher.StringParameterMatcher(parent, 0)
.withSignature(SymfonyPhpReferenceContributor.REPOSITORY_SIGNATURES)
.withSignature("Doctrine\\Persistence\\ObjectManager", "find")
.withSignature("Doctrine\\Common\\Persistence\\ObjectManager", "find") // @TODO: missing somewhere
.match();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.ArrayParameterMatcher(context, 0)
.withSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findOneBy")
.withSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findBy")
.withSignature("\\Doctrine\\Persistence\\ObjectRepository", "findOneBy")
.withSignature("\\Doctrine\\Persistence\\ObjectRepository", "findBy")
.match();

if(methodMatchParameter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ public class DoctrineMetadataUtil {

@NotNull
public static Collection<LookupElement> getObjectRepositoryLookupElements(@NotNull Project project) {
return new ArrayList<>(DoctrineRepositoryLookupElement.create(PhpIndex.getInstance(project).getAllSubclasses("\\Doctrine\\Common\\Persistence\\ObjectRepository")));
PhpIndex index = PhpIndex.getInstance(project);
Collection<PhpClass> collection = index.getAllSubclasses("\\Doctrine\\Common\\Persistence\\ObjectRepository");
collection.addAll(index.getAllSubclasses("\\Doctrine\\Persistence\\ObjectRepository"));

return new ArrayList<>(DoctrineRepositoryLookupElement.create(collection));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ private Map<String, String> findRootDefinition(Collection<MethodReference> metho
if(rootAlias != null && repository == null) {
MethodReference methodReference = methodReferences.iterator().next();
PhpClass phpClass = PsiTreeUtil.getParentOfType(methodReference, PhpClass.class);
if(phpClass != null && PhpElementsUtil.isInstanceOf(phpClass, "\\Doctrine\\Common\\Persistence\\ObjectRepository")) {
if(
phpClass != null &&
(
PhpElementsUtil.isInstanceOf(phpClass, "\\Doctrine\\Common\\Persistence\\ObjectRepository") ||
PhpElementsUtil.isInstanceOf(phpClass, "\\Doctrine\\Persistence\\ObjectRepository")
)
) {
for(DoctrineModel model: EntityHelper.getModelClasses(project)) {
String className = model.getPhpClass().getPresentableFQN();
PhpClass resolvedRepoName = EntityHelper.getEntityRepositoryClass(project, className);
Expand Down