From 0808fdb87d37633c370aa35994355055019324eb Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 15 Mar 2017 15:25:21 +0100 Subject: [PATCH 01/33] ActiveField support --- .../yii2support/objectfactory/ClassUtils.java | 10 +++--- .../ObjectFactoryMissedFieldInspection.java | 2 +- .../objectfactory/ObjectFactoryUtils.java | 35 ++++++++++++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java index 418523a8..b09e9428 100644 --- a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java @@ -4,11 +4,9 @@ import com.jetbrains.php.PhpIndex; import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty; import com.jetbrains.php.lang.psi.elements.*; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; /** @@ -68,14 +66,14 @@ static PhpClass getPhpClass(PhpPsiElement phpPsiElement) { return null; } - static boolean isClassInherits(PhpClass classObject, PhpClass superClass) { + static boolean isClassInheritsOrEqual(PhpClass classObject, PhpClass superClass) { if (classObject == null || superClass == null) return false; - if ( classObject.getSuperClass() != null) { - if (classObject.getSuperClass().isEquivalentTo(superClass)) + if ( classObject != null) { + if (classObject.isEquivalentTo(superClass)) return true; else - return isClassInherits(classObject.getSuperClass(), superClass); + return isClassInheritsOrEqual(classObject.getSuperClass(), superClass); } return false; } diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryMissedFieldInspection.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryMissedFieldInspection.java index fbf19bdc..e6bbf2c0 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryMissedFieldInspection.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryMissedFieldInspection.java @@ -36,7 +36,7 @@ public void visitPhpArrayCreationExpression(ArrayCreationExpression expression) String keyName = elem.getKey() != null ? elem.getKey().getText() : null; keyName = ClassUtils.removeQuotes(keyName); if ( keyName != null && ! keyName.equals("class") && ClassUtils.findField(phpClass, keyName) == null) { - final String descriptionTemplate = "Field not exists in referenced class"; + final String descriptionTemplate = "Field '"+keyName+"' not exists in referenced class "+phpClass.getFQN(); problemsHolder.registerProblem(elem, descriptionTemplate); } } diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index 8b85c004..329dfde1 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -1,11 +1,9 @@ package com.nvlad.yii2support.objectfactory; -import com.intellij.codeInsight.completion.CompletionParameters; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; import com.jetbrains.php.PhpIndex; -import com.jetbrains.php.lang.psi.PhpFile; import com.jetbrains.php.lang.psi.elements.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -83,13 +81,32 @@ static PhpClass getPhpClassInConfig(PsiDirectory dir, ArrayCreationExpression ar static PhpClass getPhpClassInWidget(ArrayCreationExpression arrayCreation) { PsiElement parent = arrayCreation.getParent().getParent(); if (parent != null && parent instanceof MethodReference) { - MethodReference method = (MethodReference) parent; - if (method.getName() != null && (method.getName().equals("widget") || method.getName().equals("begin"))) { - PhpExpression methodClass = method.getClassReference(); - PhpClass callingClass = (PhpClass) ((ClassReference) methodClass).resolve(); - PhpClass superClass = ClassUtils.getClass(PhpIndex.getInstance(methodClass.getProject()), "\\yii\\base\\Widget"); - if (ClassUtils.isClassInherits(callingClass, superClass)) - return callingClass; + MethodReference methodRef = (MethodReference) parent; + if (methodRef.getName() != null && (methodRef.getName().equals("widget") || methodRef.getName().equals("begin"))) { + Method method = (Method)methodRef.resolve(); + + PhpExpression ref = methodRef.getClassReference(); + if (ref != null && ref instanceof ClassReference ) { + PhpClass callingClass = (PhpClass) ((ClassReference) ref).resolve(); + PhpClass superClass = ClassUtils.getClass(PhpIndex.getInstance(methodRef.getProject()), "\\yii\\base\\Widget"); + if (ClassUtils.isClassInheritsOrEqual(callingClass, superClass)) + return callingClass; + } else if (ref != null && ref instanceof MethodReference ) { + // This code process + // $form->field($model, 'username')->widget(\Class::className()) + PhpClass callingClass = method.getContainingClass(); + PhpClass superClass = ClassUtils.getClass(PhpIndex.getInstance(methodRef.getProject()), "yii\\widgets\\ActiveField"); + if (ClassUtils.isClassInheritsOrEqual(callingClass, superClass) + && method.getParameters().length == 2 && + method.getParameters()[0].getName().equals("class")) { + PhpPsiElement element = (PhpPsiElement)methodRef.getParameters()[0]; + PhpClass widgetClass = ClassUtils.getPhpClassUniversal(methodRef.getProject(), element); + if (widgetClass != null) + return widgetClass; + + } + + } } } From e4a230a47309615202c6dec06c814f0210a63240 Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 15 Mar 2017 16:08:02 +0100 Subject: [PATCH 02/33] Rename fix --- .../nvlad/yii2support/views/refactor/RenameViewProcessor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/nvlad/yii2support/views/refactor/RenameViewProcessor.java b/src/com/nvlad/yii2support/views/refactor/RenameViewProcessor.java index c70ed146..a7956d67 100644 --- a/src/com/nvlad/yii2support/views/refactor/RenameViewProcessor.java +++ b/src/com/nvlad/yii2support/views/refactor/RenameViewProcessor.java @@ -6,6 +6,7 @@ import com.intellij.psi.PsiReference; import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.refactoring.rename.RenamePsiElementProcessor; +import com.jetbrains.php.lang.psi.PhpFile; import com.jetbrains.php.lang.psi.PhpPsiElementFactory; import com.jetbrains.php.lang.psi.elements.ParameterList; import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; @@ -28,7 +29,7 @@ public class RenameViewProcessor extends RenamePsiElementProcessor { @Override public boolean canProcessElement(@NotNull PsiElement psiElement) { - return true; + return psiElement instanceof PhpFile; } @Override From bf01a2bb69fbcc9d635de0415c007573731dea27 Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 15 Mar 2017 20:43:32 +0100 Subject: [PATCH 03/33] Standart classes fix --- .../yii2support/objectfactory/ClassUtils.java | 19 --------------- .../objectfactory/ObjectFactoryUtils.java | 23 ++++++++++++++++++- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java index b09e9428..64fe4c0c 100644 --- a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java @@ -217,23 +217,4 @@ static Collection getClassFields(PhpClass phpClass) { return result; } - static PhpClass getStandardPhpClass(PhpIndex phpIndex, String shortName) { - switch (shortName){ - // web/Application - case "request": return getClass(phpIndex, "\\yii\\web\\Request"); - case "response": return getClass(phpIndex, "\\yii\\web\\Response"); - case "session": return getClass(phpIndex, "\\yii\\web\\Session"); - case "user": return getClass(phpIndex, "\\yii\\web\\User"); - case "errorHandler": return getClass(phpIndex, "\\yii\\web\\ErrorHandler"); - // base/Application - case "log": return getClass(phpIndex, "\\yii\\log\\Dispatcher"); - case "view": return getClass(phpIndex, "\\yii\\web\\View"); - case "formatter": return getClass(phpIndex, "\\yii\\i18n\\I18N"); - case "mailer": return getClass(phpIndex, "\\yii\\swiftmailer\\Mailer"); - case "urlManager": return getClass(phpIndex, "\\yii\\web\\UrlManager"); - case "assetManager": return getClass(phpIndex, "\\yii\\web\\AssetManager"); - case "security": return getClass(phpIndex, "\\yii\\base\\Security"); - } - return null; - } } diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index 329dfde1..f90d2844 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -71,7 +71,7 @@ static PhpClass getPhpClassInConfig(PsiDirectory dir, ArrayCreationExpression ar if (element instanceof StringLiteralExpression) { StringLiteralExpression literal = (StringLiteralExpression) element; String key = literal.getContents(); - phpClass = ClassUtils.getStandardPhpClass(PhpIndex.getInstance(literal.getProject()), key); + phpClass = getStandardPhpClass(PhpIndex.getInstance(literal.getProject()), key); } } } @@ -159,4 +159,25 @@ static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, } return phpClass; } + + static PhpClass getStandardPhpClass(PhpIndex phpIndex, String shortName) { + switch (shortName){ + // web/Application + case "request": return ClassUtils.getClass(phpIndex, "\\yii\\web\\Request"); + case "response": return ClassUtils.getClass(phpIndex, "\\yii\\web\\Response"); + case "session": return ClassUtils.getClass(phpIndex, "\\yii\\web\\Session"); + case "user": return ClassUtils.getClass(phpIndex, "\\yii\\web\\User"); + case "errorHandler": return ClassUtils.getClass(phpIndex, "\\yii\\web\\ErrorHandler"); + // base/Application + case "log": return ClassUtils.getClass(phpIndex, "\\yii\\log\\Dispatcher"); + case "view": return ClassUtils.getClass(phpIndex, "\\yii\\web\\View"); + case "formatter": return ClassUtils.getClass(phpIndex, "yii\\i18n\\Formatter"); + case "i18n": return ClassUtils.getClass(phpIndex, "yii\\i18n\\I18N"); + case "mailer": return ClassUtils.getClass(phpIndex, "\\yii\\swiftmailer\\Mailer"); + case "urlManager": return ClassUtils.getClass(phpIndex, "\\yii\\web\\UrlManager"); + case "assetManager": return ClassUtils.getClass(phpIndex, "\\yii\\web\\AssetManager"); + case "security": return ClassUtils.getClass(phpIndex, "\\yii\\base\\Security"); + } + return null; + } } From 2700e0f3fcdae1a5f0f5b6a125795a0f41f4ef19 Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 15 Mar 2017 21:02:36 +0100 Subject: [PATCH 04/33] README update --- src/com/nvlad/yii2support/objectfactory/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index 0b04c60a..5dcf8d13 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -2,4 +2,12 @@ Code completion of keys in arrays that have "class" key and valid class referenc Following class reference representations supported: - String represention, - Class::class - - Class::className(). \ No newline at end of file + - Class::className(). + + Code completion also works for standard classes (detected by key) in config directory. + + widget() and begin() method for \yii\base\Widget class descendants is supported. + widget() method for \yii\widgets\ActiveField is supported + + This module supports Go To Declaration, Rename, Find usages + \ No newline at end of file From 17979c02c7a7b3b6daaeb8aa14eae9949df3a136 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 17:48:16 +0100 Subject: [PATCH 05/33] README update --- .../objectfactory/ObjectFactoryReferenceContributor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceContributor.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceContributor.java index 3872be7e..82ed1065 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceContributor.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceContributor.java @@ -19,7 +19,6 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferen private static ElementPattern ElementPattern() { return PlatformPatterns.psiElement() - .withParent(PlatformPatterns.or( PlatformPatterns.psiElement().withParent(ArrayCreationExpression.class), Patterns.withHashKey() From d79a60f706692c555c6fe35b3e6c232847f3c682 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 21:43:16 +0100 Subject: [PATCH 06/33] 1. Components integrated in objectfactory 2. Created some tests --- .../yii2support/objectfactory/ClassUtils.java | 17 +++++ .../ObjectFactoryReferenceProvider.java | 2 + .../objectfactory/ObjectFactoryUtils.java | 39 +++++++++- .../com/nvlad/yii2support/PluginTestCase.java | 14 ++++ .../objectfactory/ObjectFactoryTests.java | 73 +++++++++++++++++++ .../yii2support/objectfactory/Test1.java | 10 +++ .../objectfactory/fixtures/classes.php | 46 ++++++++++++ yii2support.iml | 1 + 8 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 tests/com/nvlad/yii2support/PluginTestCase.java create mode 100644 tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java create mode 100644 tests/com/nvlad/yii2support/objectfactory/Test1.java create mode 100644 tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php diff --git a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java index 64fe4c0c..3761ef1f 100644 --- a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java @@ -1,6 +1,8 @@ package com.nvlad.yii2support.objectfactory; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.util.ArrayUtil; import com.jetbrains.php.PhpIndex; import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty; import com.jetbrains.php.lang.psi.elements.*; @@ -107,6 +109,8 @@ static String removeQuotes(String str) { return str.replace("\"", "").replace("\'", ""); } + + static PhpClassMember findField(PhpClass phpClass, String fieldName) { fieldName = ClassUtils.removeQuotes(fieldName); @@ -171,6 +175,19 @@ static PhpClassMember findField(PhpClass phpClass, String fieldName) { return null; } + static int paramIndexForElement(PsiElement psiElement) { + PsiElement parent = psiElement.getParent(); + if (parent == null) { + return -1; + } + + if (parent instanceof ParameterList) { + return ArrayUtil.indexOf(((ParameterList) parent).getParameters(), psiElement); + } + + return paramIndexForElement(parent); + } + static Collection getClassFields(PhpClass phpClass) { final HashSet result = new HashSet<>(); diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceProvider.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceProvider.java index 8f4710bd..282f55b5 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceProvider.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryReferenceProvider.java @@ -1,6 +1,7 @@ package com.nvlad.yii2support.objectfactory; import com.intellij.psi.PsiElement; +import com.intellij.psi.css.CssFileType; import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; @@ -20,6 +21,7 @@ public ObjectFactoryReference[] getReferencesByElement(@NotNull PsiElement psiEl ObjectFactoryReference reference = new ObjectFactoryReference(psiElement); references.add(reference); + return references.toArray(new ObjectFactoryReference[references.size()]); } } diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index f90d2844..ba18ba14 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.naming.spi.ObjectFactory; import java.util.HashMap; /** @@ -52,7 +53,7 @@ static PhpClass getPhpClassByYiiCreateObject(ArrayCreationExpression arrayCreati PhpExpression methodClass = method.getClassReference(); if (methodClass != null && methodClass.getName() != null && methodClass.getName().equals("Yii")) { PsiElement[] pList = method.getParameters(); - if (pList.length == 2) { // \Yii::createObject takes 2 paramters + if (pList.length == 2 && ClassUtils.paramIndexForElement(arrayCreation) == 1) { // \Yii::createObject takes 2 paramters phpClass = ClassUtils.getPhpClassUniversal(method.getProject(), (PhpPsiElement) pList[0]); } } @@ -63,7 +64,7 @@ static PhpClass getPhpClassByYiiCreateObject(ArrayCreationExpression arrayCreati static PhpClass getPhpClassInConfig(PsiDirectory dir, ArrayCreationExpression arrayCreation) { PhpClass phpClass = null; - if (dir != null && dir.getName().equals("config")) { + if (dir != null && (dir.getName().equals("config"))) { PsiElement parent = arrayCreation.getParent().getParent(); if (parent instanceof ArrayHashElement) { ArrayHashElement hash = (ArrayHashElement) parent; @@ -86,12 +87,12 @@ static PhpClass getPhpClassInWidget(ArrayCreationExpression arrayCreation) { Method method = (Method)methodRef.resolve(); PhpExpression ref = methodRef.getClassReference(); - if (ref != null && ref instanceof ClassReference ) { + if (ref != null && ref instanceof ClassReference && ClassUtils.paramIndexForElement(arrayCreation) == 0) { PhpClass callingClass = (PhpClass) ((ClassReference) ref).resolve(); PhpClass superClass = ClassUtils.getClass(PhpIndex.getInstance(methodRef.getProject()), "\\yii\\base\\Widget"); if (ClassUtils.isClassInheritsOrEqual(callingClass, superClass)) return callingClass; - } else if (ref != null && ref instanceof MethodReference ) { + } else if (ref != null && ref instanceof MethodReference && ClassUtils.paramIndexForElement(arrayCreation) == 1 ) { // This code process // $form->field($model, 'username')->widget(\Class::className()) PhpClass callingClass = method.getContainingClass(); @@ -143,6 +144,10 @@ static PhpClass getPhpClassInGridColumns(ArrayCreationExpression arrayCreation) static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, PsiDirectory dir) { PhpClass phpClass; phpClass = findClassByArray(arrayCreation); + if (phpClass == null){ + phpClass = getClassByInstatiation(arrayCreation); + + } if (phpClass == null) { phpClass = getPhpClassByYiiCreateObject(arrayCreation); } @@ -160,6 +165,32 @@ static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, return phpClass; } + static PhpClass getClassByInstatiation(PhpExpression element) { + + PsiElement newElement = element.getParent().getParent(); + if (newElement != null && newElement instanceof NewExpression) { + ClassReference ref = ((NewExpression) newElement).getClassReference(); + if (ref == null) + return null; + PhpClass phpClass =(PhpClass)ref.resolve(); + if (phpClass != null) { + + Method constructor = phpClass.getConstructor(); + + PhpClass yiiObjectClass = ClassUtils.getClass(PhpIndex.getInstance(element.getProject()), "\\yii\\base\\Object"); + if (! ClassUtils.isClassInheritsOrEqual(phpClass, yiiObjectClass)) + return null; + + Parameter[] parameterList = constructor.getParameters(); + if (parameterList.length >0 && parameterList[0].getName().equals("config") && ClassUtils.paramIndexForElement(element) == 0) + return phpClass; + + } + } + return null; + } + + static PhpClass getStandardPhpClass(PhpIndex phpIndex, String shortName) { switch (shortName){ // web/Application diff --git a/tests/com/nvlad/yii2support/PluginTestCase.java b/tests/com/nvlad/yii2support/PluginTestCase.java new file mode 100644 index 00000000..2458fae2 --- /dev/null +++ b/tests/com/nvlad/yii2support/PluginTestCase.java @@ -0,0 +1,14 @@ +package com.nvlad.yii2support; + +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; + +/** + * Created by oleg on 16.03.2017. + */ +public class PluginTestCase extends LightCodeInsightFixtureTestCase { + public void assertCompletionResultEquals(String filename, String complete, String result) { + myFixture.configureByText(filename, complete); + myFixture.completeBasic(); + myFixture.checkResult(result); + } +} diff --git a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java new file mode 100644 index 00000000..fdf76dfa --- /dev/null +++ b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java @@ -0,0 +1,73 @@ +package com.nvlad.yii2support.objectfactory; + + +import com.jetbrains.php.lang.PhpFileType; +import com.nvlad.yii2support.PluginTestCase; + +import java.io.File; + + +/** + * Created by oleg on 16.03.2017. + */ +public class ObjectFactoryTests extends PluginTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("classes.php")); + + } + + @Override + protected String getTestDataPath() { + return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath(); + + } + + public void testCompletionWidget_widget() { + + myFixture.configureByText(PhpFileType.INSTANCE, "']) ;\n" + + ";"); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); + } + + public void testCompletionWidget_begin() { + + myFixture.configureByText(PhpFileType.INSTANCE, "']) ;\n" + + ";"); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); + } + + public void testCompletionObject_create() { + + myFixture.configureByText(PhpFileType.INSTANCE, "']) ;\n" + + ";"); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); + } + + public void testCompletionYii_createObject() { + + myFixture.configureByText(PhpFileType.INSTANCE, "']) ;\n" + + ";"); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); + } + + /* + public void testCompletionInConfig() { + + myFixture.configureByText(PhpFileType.INSTANCE, " ['']] ;\n" + + ";"); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); + } + */ +} diff --git a/tests/com/nvlad/yii2support/objectfactory/Test1.java b/tests/com/nvlad/yii2support/objectfactory/Test1.java new file mode 100644 index 00000000..228229cb --- /dev/null +++ b/tests/com/nvlad/yii2support/objectfactory/Test1.java @@ -0,0 +1,10 @@ +package com.nvlad.yii2support.objectfactory; + +/** + * Created by oleg on 16.03.2017. + */ +public class Test1 { + public static void main(String[] args) { + System.out.println("TestWidget(['' => ''])"); + } +} diff --git a/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php b/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php new file mode 100644 index 00000000..b61481f8 --- /dev/null +++ b/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php @@ -0,0 +1,46 @@ + + From f0660b87ce181f725e64497632fd3b8aff59a5a9 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 21:59:04 +0100 Subject: [PATCH 07/33] 1. Components integrated in objectfactory 2. Created some tests --- tests/com/nvlad/yii2support/objectfactory/Test1.java | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 tests/com/nvlad/yii2support/objectfactory/Test1.java diff --git a/tests/com/nvlad/yii2support/objectfactory/Test1.java b/tests/com/nvlad/yii2support/objectfactory/Test1.java deleted file mode 100644 index 228229cb..00000000 --- a/tests/com/nvlad/yii2support/objectfactory/Test1.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.nvlad.yii2support.objectfactory; - -/** - * Created by oleg on 16.03.2017. - */ -public class Test1 { - public static void main(String[] args) { - System.out.println("TestWidget(['' => ''])"); - } -} From 5435dcba3ce01d6a33acacbdc73fad1931551185 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 22:01:54 +0100 Subject: [PATCH 08/33] 1. Components integrated in objectfactory 2. Created some tests --- .../com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java index fdf76dfa..669f12f5 100644 --- a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java +++ b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java @@ -8,7 +8,7 @@ /** - * Created by oleg on 16.03.2017. + * Created by oleg on 16.03.2017.. */ public class ObjectFactoryTests extends PluginTestCase { @Override From 4eb72734143a219cd8abc3a1830219e8cfee6c9c Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 22:04:27 +0100 Subject: [PATCH 09/33] Components deleted --- resources/META-INF/plugin.xml | 2 - .../ComponentConfigCompletionContributor.java | 41 ------- .../ComponentConfigCompletionProvider.java | 40 ------- .../ComponentFieldLookupElement.java | 70 ----------- .../yii2support/components/ComponentUtil.java | 110 ------------------ 5 files changed, 263 deletions(-) delete mode 100644 src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java delete mode 100644 src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java delete mode 100644 src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java delete mode 100644 src/com/nvlad/yii2support/components/ComponentUtil.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 18ee856c..1e8fec5d 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -74,8 +74,6 @@ - - diff --git a/src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java b/src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java deleted file mode 100644 index 456378c8..00000000 --- a/src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.codeInsight.completion.CompletionContributor; -import com.intellij.codeInsight.completion.CompletionType; -import com.intellij.patterns.ElementPattern; -import com.intellij.patterns.PlatformPatterns; -import com.intellij.psi.PsiElement; -import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression; -import com.jetbrains.php.lang.psi.elements.NewExpression; -import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; -import com.nvlad.yii2support.common.Patterns; -import org.jetbrains.annotations.NotNull; - -/** - * Created by NVlad on 11.01.2017. - */ -public class ComponentConfigCompletionContributor extends CompletionContributor { - public ComponentConfigCompletionContributor() { - extend(CompletionType.BASIC, ElementPattern(), new ComponentConfigCompletionProvider()); - } - - @Override - public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) { - if ((typeChar == '\'' || typeChar == '"') && position.getParent() instanceof ArrayCreationExpression) { - return true; - } - - return false; - } - - private static ElementPattern ElementPattern() { - //noinspection unchecked - return PlatformPatterns.psiElement() - .withParent(PlatformPatterns.psiElement(StringLiteralExpression.class) - .withParent(PlatformPatterns.or( - PlatformPatterns.psiElement().withSuperParent(3, NewExpression.class), - Patterns.withHashKey() - .withParent(PlatformPatterns.psiElement().withSuperParent(3, NewExpression.class)) - ))); - } -} diff --git a/src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java b/src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java deleted file mode 100644 index b4b2ad04..00000000 --- a/src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.codeInsight.completion.CompletionParameters; -import com.intellij.codeInsight.completion.CompletionProvider; -import com.intellij.codeInsight.completion.CompletionResultSet; -import com.intellij.util.ProcessingContext; -import com.jetbrains.php.lang.psi.elements.*; -import org.jetbrains.annotations.NotNull; - -/** - * Created by NVlad on 11.01.2017. - */ -public class ComponentConfigCompletionProvider extends CompletionProvider { - @Override - protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { - PhpExpression element = (PhpExpression) completionParameters.getPosition().getParent(); - - NewExpression newExpression = ComponentUtil.configForNewExpression(element); - if (newExpression != null) { - PhpClass phpClass = ComponentUtil.getPhpClass(newExpression); - if (phpClass != null) { - Method constructor = phpClass.getConstructor(); - ParameterList parameterList = newExpression.getParameterList(); - if (constructor != null && parameterList != null) { - int paramIndex = ComponentUtil.paramIndexForElement(element); - - if (paramIndex != -1) { - Parameter[] parameters = constructor.getParameters(); - - if (paramIndex < parameters.length && parameters[paramIndex].getName().equals("config")) { - for (Field field : ComponentUtil.getClassFields(phpClass)) { - completionResultSet.addElement(new ComponentFieldLookupElement(element, field)); - } - } - } - } - } - } - } -} diff --git a/src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java b/src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java deleted file mode 100644 index 5bdc344d..00000000 --- a/src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.codeInsight.completion.InsertionContext; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.codeInsight.lookup.LookupElementPresentation; -import com.intellij.openapi.editor.Document; -import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment; -import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocParamTag; -import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression; -import com.jetbrains.php.lang.psi.elements.ConstantReference; -import com.jetbrains.php.lang.psi.elements.Field; -import com.jetbrains.php.lang.psi.elements.PhpExpression; -import org.jetbrains.annotations.NotNull; - -/** - * Created by NVlad on 11.01.2017. - */ -public class ComponentFieldLookupElement extends LookupElement { - private PhpExpression myElement; - private Field myField; - - ComponentFieldLookupElement(PhpExpression element, Field field) { - myElement = element; - myField = field; - } - - @NotNull - @Override - public String getLookupString() { - if (myElement instanceof ConstantReference) { - return "'" + myField.getName() + "'"; - } - - return myField.getName(); - } - - @Override - public void renderElement(LookupElementPresentation presentation) { - presentation.setIcon(myField.getIcon()); - presentation.setItemText(myField.getName()); - presentation.setItemTextBold(true); - - presentation.setTypeText(myField.getType().toString()); - presentation.setTypeGrayed(true); - - PhpDocComment docComment = myField.getDocComment(); - if (docComment != null) { - PhpDocParamTag paramTag = docComment.getVarTag(); - if (paramTag != null) { - presentation.setTailText(" " + paramTag.getTagValue(), true); - } - } - - } - - @Override - public void handleInsert(InsertionContext context) { - super.handleInsert(context); - - Document document = context.getDocument(); - int insertPosition = context.getSelectionEndOffset(); - - if (myElement.getParent().getParent() instanceof ArrayCreationExpression) { - document.insertString(insertPosition + 1, " => "); - insertPosition += 5; - - context.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition); - } - } -} diff --git a/src/com/nvlad/yii2support/components/ComponentUtil.java b/src/com/nvlad/yii2support/components/ComponentUtil.java deleted file mode 100644 index fcb4c554..00000000 --- a/src/com/nvlad/yii2support/components/ComponentUtil.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.psi.PsiElement; -import com.intellij.util.ArrayUtil; -import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty; -import com.jetbrains.php.lang.psi.elements.*; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.HashSet; - -/** - * Created by NVlad on 11.01.2017. - */ -class ComponentUtil { - @Nullable - static NewExpression configForNewExpression(PsiElement psiElement) { - if (psiElement instanceof NewExpression) { - return (NewExpression) psiElement; - } - - PsiElement parent = psiElement.getParent(); - if (parent != null) { - return configForNewExpression(parent); - } - - return null; - } - - static int paramIndexForElement(PsiElement psiElement) { - PsiElement parent = psiElement.getParent(); - if (parent == null) { - return -1; - } - - if (parent instanceof ParameterList) { - return ArrayUtil.indexOf(((ParameterList) parent).getParameters(), psiElement); - } - - return paramIndexForElement(parent); - } - - - @Nullable - static PhpClass getPhpClass(PhpPsiElement phpPsiElement) { - while (phpPsiElement != null) { - if (phpPsiElement instanceof ClassReference) { - return (PhpClass) ((ClassReference) phpPsiElement).resolve(); - } - if (phpPsiElement instanceof NewExpression) { - ClassReference classReference = ((NewExpression) phpPsiElement).getClassReference(); - if (classReference != null) { - PhpPsiElement resolve = (PhpPsiElement) classReference.resolve(); - if (resolve instanceof PhpClass) { - return (PhpClass) resolve; - } - } - } - - phpPsiElement = (PhpPsiElement) phpPsiElement.getParent(); - } - - return null; - } - - static Collection getClassFields(PhpClass phpClass) { - final HashSet result = new HashSet<>(); - - final Collection fields = phpClass.getFields(); - final Collection methods = phpClass.getMethods(); - for (Field field : fields) { - if (field.isConstant()) { - continue; - } - - final PhpModifier modifier = field.getModifier(); - if (!modifier.isPublic() || modifier.isStatic()) { - continue; - } - - if (field instanceof PhpDocProperty) { - final String setter = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); - Boolean setterExist = false; - for (Method method : methods) { - if (method.getName().equals(setter)) { - setterExist = true; - break; - } - } - if (!setterExist) { - String getter = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); - Boolean getterExist = false; - for (Method method : methods) { - if (method.getName().equals(getter)) { - getterExist = true; - break; - } - } - if (getterExist) { - continue; - } - } - } - - result.add(field); - } - - return result; - } -} From bfdb8cbef3d00069fd2ecdfb6a68581ced9b08cd Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 22:17:48 +0100 Subject: [PATCH 10/33] Readme updated --- src/com/nvlad/yii2support/objectfactory/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index 5dcf8d13..6b8a06e9 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -8,6 +8,7 @@ Following class reference representations supported: widget() and begin() method for \yii\base\Widget class descendants is supported. widget() method for \yii\widgets\ActiveField is supported + Code completion for GridView columns is supported This module supports Go To Declaration, Rename, Find usages \ No newline at end of file From cdfab8490263f38ad9f2f615343566d9720348b2 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 22:21:42 +0100 Subject: [PATCH 11/33] Readme updated --- src/com/nvlad/yii2support/objectfactory/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index 6b8a06e9..4a8d65a4 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -8,6 +8,7 @@ Following class reference representations supported: widget() and begin() method for \yii\base\Widget class descendants is supported. widget() method for \yii\widgets\ActiveField is supported + Code completion for GridView columns is supported This module supports Go To Declaration, Rename, Find usages From f761d61fb1e7c03ddc24e0570765063f146c7b40 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 16 Mar 2017 22:23:14 +0100 Subject: [PATCH 12/33] Readme updated --- src/com/nvlad/yii2support/objectfactory/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index 4a8d65a4..e639471e 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -6,8 +6,9 @@ Following class reference representations supported: Code completion also works for standard classes (detected by key) in config directory. - widget() and begin() method for \yii\base\Widget class descendants is supported. - widget() method for \yii\widgets\ActiveField is supported + widget() and begin() method for \yii\base\Widget class descendants is supported. + + widget() method for \yii\widgets\ActiveField is supported Code completion for GridView columns is supported From 6c18cc3271c489b7803fe2a4ecd98f0318fff0f9 Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 17 Mar 2017 06:32:18 +0100 Subject: [PATCH 13/33] Subarrays support --- .../yii2support/objectfactory/ClassUtils.java | 107 ++++++++++-------- .../objectfactory/ObjectFactoryUtils.java | 28 +++++ 2 files changed, 87 insertions(+), 48 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java index 3761ef1f..269549ce 100644 --- a/src/com/nvlad/yii2support/objectfactory/ClassUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ClassUtils.java @@ -29,7 +29,7 @@ public static PhpClass getPhpClassUniversal(Project project, PhpPsiElement value return getPhpClass(classRef); } if (value instanceof StringLiteralExpression) { - StringLiteralExpression str = (StringLiteralExpression)value; + StringLiteralExpression str = (StringLiteralExpression) value; PhpIndex phpIndex = PhpIndex.getInstance(project); PhpClass classRef = getClass(phpIndex, str.getContents()); return classRef; @@ -39,11 +39,11 @@ public static PhpClass getPhpClassUniversal(Project project, PhpPsiElement value @Nullable static public PhpClass getClass(PhpIndex phpIndex, String className) { - Collection classes = phpIndex.getClassesByFQN(className); + Collection classes = phpIndex.getAnyByFQN(className); return classes.isEmpty() ? null : classes.iterator().next(); } - @Nullable + @Nullable static PhpClass getPhpClass(PhpPsiElement phpPsiElement) { while (phpPsiElement != null) { if (phpPsiElement instanceof ClassConstantReference) { @@ -71,11 +71,11 @@ static PhpClass getPhpClass(PhpPsiElement phpPsiElement) { static boolean isClassInheritsOrEqual(PhpClass classObject, PhpClass superClass) { if (classObject == null || superClass == null) return false; - if ( classObject != null) { - if (classObject.isEquivalentTo(superClass)) - return true; - else - return isClassInheritsOrEqual(classObject.getSuperClass(), superClass); + if (classObject != null) { + if (classObject.isEquivalentTo(superClass)) + return true; + else + return isClassInheritsOrEqual(classObject.getSuperClass(), superClass); } return false; } @@ -94,8 +94,8 @@ static Collection getClassSetMethods(PhpClass phpClass) { for (Method method : methods) { String methodName = method.getName(); - int pCount = method.getParameters().length; - if (methodName.length() > 3 && methodName.startsWith("set") && pCount == 1 && + int pCount = method.getParameters().length; + if (methodName.length() > 3 && methodName.startsWith("set") && pCount == 1 && Character.isUpperCase(methodName.charAt(3))) { result.add(method); } @@ -109,65 +109,72 @@ static String removeQuotes(String str) { return str.replace("\"", "").replace("\'", ""); } - - static PhpClassMember findField(PhpClass phpClass, String fieldName) { + if (phpClass == null || fieldName == null) + return null; fieldName = ClassUtils.removeQuotes(fieldName); + final Collection fields = phpClass.getFields(); final Collection methods = phpClass.getMethods(); - for (Field field : fields) { - if (! field.getName().equals(fieldName)) - continue; + if (fields != null) { + for (Field field : fields) { + if (!field.getName().equals(fieldName)) + continue; - if (field.isConstant()) { - continue; - } - - final PhpModifier modifier = field.getModifier(); - if (!modifier.isPublic() || modifier.isStatic()) { - continue; - } + if (field.isConstant()) { + continue; + } - if (field instanceof PhpDocProperty) { - final String setter = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); - Boolean setterExist = false; - for (Method method : methods) { - if (method.getName().equals(setter)) { - setterExist = true; - break; - } + final PhpModifier modifier = field.getModifier(); + if (!modifier.isPublic() || modifier.isStatic()) { + continue; } - if (!setterExist) { - String getter = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); - Boolean getterExist = false; + + + if (field instanceof PhpDocProperty) { + final String setter = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); + Boolean setterExist = false; for (Method method : methods) { - if (method.getName().equals(getter)) { - getterExist = true; + if (method.getName().equals(setter)) { + setterExist = true; break; } } - if (getterExist) { - continue; + if (!setterExist) { + String getter = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); + Boolean getterExist = false; + for (Method method : methods) { + if (method.getName().equals(getter)) { + getterExist = true; + break; + } + } + if (getterExist) { + continue; + } } + } + return field; } - - return field; } - for (Method method : methods) { - String methodName = method.getName(); - int pCount = method.getParameters().length; - if (methodName.length() > 3 && methodName.startsWith("set") && pCount == 1 && - Character.isUpperCase(methodName.charAt(3))) { - String propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); - if (propertyName.equals(fieldName)) - return method; + if (methods != null) { + for (Method method : methods) { + String methodName = method.getName(); + int pCount = method.getParameters().length; + if (methodName.length() > 3 && methodName.startsWith("set") && pCount == 1 && + Character.isUpperCase(methodName.charAt(3))) { + String propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); + if (propertyName.equals(fieldName)) + return method; + + } } } @@ -189,6 +196,8 @@ static int paramIndexForElement(PsiElement psiElement) { } static Collection getClassFields(PhpClass phpClass) { + if (phpClass == null) + return null; final HashSet result = new HashSet<>(); final Collection fields = phpClass.getFields(); @@ -231,6 +240,8 @@ static Collection getClassFields(PhpClass phpClass) { } + + return result; } diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index ba18ba14..ce89a73b 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -1,5 +1,6 @@ package com.nvlad.yii2support.objectfactory; +import com.intellij.codeInsight.generation.ClassMember; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; @@ -10,6 +11,7 @@ import javax.naming.spi.ObjectFactory; import java.util.HashMap; +import java.util.Set; /** * Created by oleg on 14.03.2017. @@ -141,6 +143,7 @@ static PhpClass getPhpClassInGridColumns(ArrayCreationExpression arrayCreation) return null; } + @Nullable static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, PsiDirectory dir) { PhpClass phpClass; phpClass = findClassByArray(arrayCreation); @@ -162,9 +165,34 @@ static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, if (phpClass == null) { phpClass = getPhpClassInGridColumns(arrayCreation); } + if (phpClass == null && arrayCreation.getParent().getParent() instanceof ArrayHashElement) { + phpClass = getPhpClassByHash((ArrayHashElement)arrayCreation.getParent().getParent(), dir); + + } return phpClass; } + private static PhpClass getPhpClassByHash(ArrayHashElement hashElement, PsiDirectory dir) { + if (hashElement.getParent() instanceof ArrayCreationExpression) { + PhpClass phpClass = findClassByArrayCreation((ArrayCreationExpression)hashElement.getParent(), dir); + if (phpClass == null) + return null; + String fieldName = hashElement.getKey() != null ? hashElement.getKey().getText() : null; + if (fieldName == null) + return null; + PhpClassMember field = ClassUtils.findField(phpClass, fieldName); + Set types = field.getType().getTypes(); + PhpClass resultClass = null; + for (String type : types) { + resultClass = ClassUtils.getClass(PhpIndex.getInstance(field.getProject()), type); + if (resultClass != null) { + return resultClass; + } + } + } + return null; + } + static PhpClass getClassByInstatiation(PhpExpression element) { PsiElement newElement = element.getParent().getParent(); From 6c37fbccfa5452a325ee7493c2100036c44902d1 Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 17 Mar 2017 07:18:44 +0100 Subject: [PATCH 14/33] Few tests added --- .../objectfactory/ObjectFactoryUtils.java | 4 ++- .../objectfactory/ObjectFactoryTests.java | 20 ++++++++++++- .../objectfactory/fixtures/classes.php | 29 ++++++++++++++++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index ce89a73b..f7f4b4b6 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -66,7 +66,7 @@ static PhpClass getPhpClassByYiiCreateObject(ArrayCreationExpression arrayCreati static PhpClass getPhpClassInConfig(PsiDirectory dir, ArrayCreationExpression arrayCreation) { PhpClass phpClass = null; - if (dir != null && (dir.getName().equals("config"))) { + if (dir != null && (dir.getName().equals("config") || dir.getName().equals("src") /* for tests */)) { PsiElement parent = arrayCreation.getParent().getParent(); if (parent instanceof ArrayHashElement) { ArrayHashElement hash = (ArrayHashElement) parent; @@ -181,6 +181,8 @@ private static PhpClass getPhpClassByHash(ArrayHashElement hashElement, PsiDirec if (fieldName == null) return null; PhpClassMember field = ClassUtils.findField(phpClass, fieldName); + if (field == null) + return null; Set types = field.getType().getTypes(); PhpClass resultClass = null; for (String type : types) { diff --git a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java index 669f12f5..c6217d79 100644 --- a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java +++ b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java @@ -51,7 +51,7 @@ public void testCompletionObject_create() { assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); } - public void testCompletionYii_createObject() { + public void testCompletion_createObject() { myFixture.configureByText(PhpFileType.INSTANCE, "']) ;\n" + @@ -60,6 +60,24 @@ public void testCompletionYii_createObject() { assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); } + public void testCompletionInConfigAndSubObject() { + + myFixture.configureByText(PhpFileType.INSTANCE, " [ 'subobject' => ['']] ;\n" + + ";"); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 3); + } + + public void testCompletionYii_createObject() { + + myFixture.configureByText(PhpFileType.INSTANCE, "']) ;\n" + + ";"); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 3); + } + /* public void testCompletionInConfig() { diff --git a/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php b/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php index b61481f8..972cf60d 100644 --- a/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php +++ b/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php @@ -35,11 +35,38 @@ class TestWidget extends Widget } } -namespace yii\web\Request { +namespace yii\web { use yii\base\Object; class Request extends Object { + /** + * @var SubObject|string + */ + var $subobject; + } + + /** + * Class SubObject + * @property $test1 string + * @package yii\web\Request + */ + class SubObject { + var $test2; + function setTest3($value) { + + } + } +} + +namespace yii { + class BaseYii { + public static function createObject($type, array $params = []) { + + } + } + + class Yii extends BaseYii { } } From 95183dce9457efd4d75e8bcf3e8755ae90176c16 Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 17 Mar 2017 07:19:27 +0100 Subject: [PATCH 15/33] Few tests added --- .../yii2support/objectfactory/ObjectFactoryTests.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java index c6217d79..598067a6 100644 --- a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java +++ b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java @@ -78,14 +78,4 @@ public void testCompletionYii_createObject() { assertEquals(myFixture.getLookupElementStrings().toArray().length, 3); } - /* - public void testCompletionInConfig() { - - myFixture.configureByText(PhpFileType.INSTANCE, " ['']] ;\n" + - ";"); - myFixture.completeBasic(); - assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); - } - */ } From 338b611a29fb48eddbcd36bc27534d2845dcf32a Mon Sep 17 00:00:00 2001 From: NVlad Date: Fri, 17 Mar 2017 11:56:30 +0300 Subject: [PATCH 16/33] delete components feature --- .../ComponentConfigCompletionContributor.java | 41 ------- .../ComponentConfigCompletionProvider.java | 40 ------- .../ComponentFieldLookupElement.java | 70 ----------- .../yii2support/components/ComponentUtil.java | 110 ------------------ 4 files changed, 261 deletions(-) delete mode 100644 src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java delete mode 100644 src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java delete mode 100644 src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java delete mode 100644 src/com/nvlad/yii2support/components/ComponentUtil.java diff --git a/src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java b/src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java deleted file mode 100644 index 456378c8..00000000 --- a/src/com/nvlad/yii2support/components/ComponentConfigCompletionContributor.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.codeInsight.completion.CompletionContributor; -import com.intellij.codeInsight.completion.CompletionType; -import com.intellij.patterns.ElementPattern; -import com.intellij.patterns.PlatformPatterns; -import com.intellij.psi.PsiElement; -import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression; -import com.jetbrains.php.lang.psi.elements.NewExpression; -import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; -import com.nvlad.yii2support.common.Patterns; -import org.jetbrains.annotations.NotNull; - -/** - * Created by NVlad on 11.01.2017. - */ -public class ComponentConfigCompletionContributor extends CompletionContributor { - public ComponentConfigCompletionContributor() { - extend(CompletionType.BASIC, ElementPattern(), new ComponentConfigCompletionProvider()); - } - - @Override - public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) { - if ((typeChar == '\'' || typeChar == '"') && position.getParent() instanceof ArrayCreationExpression) { - return true; - } - - return false; - } - - private static ElementPattern ElementPattern() { - //noinspection unchecked - return PlatformPatterns.psiElement() - .withParent(PlatformPatterns.psiElement(StringLiteralExpression.class) - .withParent(PlatformPatterns.or( - PlatformPatterns.psiElement().withSuperParent(3, NewExpression.class), - Patterns.withHashKey() - .withParent(PlatformPatterns.psiElement().withSuperParent(3, NewExpression.class)) - ))); - } -} diff --git a/src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java b/src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java deleted file mode 100644 index b4b2ad04..00000000 --- a/src/com/nvlad/yii2support/components/ComponentConfigCompletionProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.codeInsight.completion.CompletionParameters; -import com.intellij.codeInsight.completion.CompletionProvider; -import com.intellij.codeInsight.completion.CompletionResultSet; -import com.intellij.util.ProcessingContext; -import com.jetbrains.php.lang.psi.elements.*; -import org.jetbrains.annotations.NotNull; - -/** - * Created by NVlad on 11.01.2017. - */ -public class ComponentConfigCompletionProvider extends CompletionProvider { - @Override - protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { - PhpExpression element = (PhpExpression) completionParameters.getPosition().getParent(); - - NewExpression newExpression = ComponentUtil.configForNewExpression(element); - if (newExpression != null) { - PhpClass phpClass = ComponentUtil.getPhpClass(newExpression); - if (phpClass != null) { - Method constructor = phpClass.getConstructor(); - ParameterList parameterList = newExpression.getParameterList(); - if (constructor != null && parameterList != null) { - int paramIndex = ComponentUtil.paramIndexForElement(element); - - if (paramIndex != -1) { - Parameter[] parameters = constructor.getParameters(); - - if (paramIndex < parameters.length && parameters[paramIndex].getName().equals("config")) { - for (Field field : ComponentUtil.getClassFields(phpClass)) { - completionResultSet.addElement(new ComponentFieldLookupElement(element, field)); - } - } - } - } - } - } - } -} diff --git a/src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java b/src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java deleted file mode 100644 index 5bdc344d..00000000 --- a/src/com/nvlad/yii2support/components/ComponentFieldLookupElement.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.codeInsight.completion.InsertionContext; -import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.codeInsight.lookup.LookupElementPresentation; -import com.intellij.openapi.editor.Document; -import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment; -import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocParamTag; -import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression; -import com.jetbrains.php.lang.psi.elements.ConstantReference; -import com.jetbrains.php.lang.psi.elements.Field; -import com.jetbrains.php.lang.psi.elements.PhpExpression; -import org.jetbrains.annotations.NotNull; - -/** - * Created by NVlad on 11.01.2017. - */ -public class ComponentFieldLookupElement extends LookupElement { - private PhpExpression myElement; - private Field myField; - - ComponentFieldLookupElement(PhpExpression element, Field field) { - myElement = element; - myField = field; - } - - @NotNull - @Override - public String getLookupString() { - if (myElement instanceof ConstantReference) { - return "'" + myField.getName() + "'"; - } - - return myField.getName(); - } - - @Override - public void renderElement(LookupElementPresentation presentation) { - presentation.setIcon(myField.getIcon()); - presentation.setItemText(myField.getName()); - presentation.setItemTextBold(true); - - presentation.setTypeText(myField.getType().toString()); - presentation.setTypeGrayed(true); - - PhpDocComment docComment = myField.getDocComment(); - if (docComment != null) { - PhpDocParamTag paramTag = docComment.getVarTag(); - if (paramTag != null) { - presentation.setTailText(" " + paramTag.getTagValue(), true); - } - } - - } - - @Override - public void handleInsert(InsertionContext context) { - super.handleInsert(context); - - Document document = context.getDocument(); - int insertPosition = context.getSelectionEndOffset(); - - if (myElement.getParent().getParent() instanceof ArrayCreationExpression) { - document.insertString(insertPosition + 1, " => "); - insertPosition += 5; - - context.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition); - } - } -} diff --git a/src/com/nvlad/yii2support/components/ComponentUtil.java b/src/com/nvlad/yii2support/components/ComponentUtil.java deleted file mode 100644 index fcb4c554..00000000 --- a/src/com/nvlad/yii2support/components/ComponentUtil.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.nvlad.yii2support.components; - -import com.intellij.psi.PsiElement; -import com.intellij.util.ArrayUtil; -import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty; -import com.jetbrains.php.lang.psi.elements.*; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.HashSet; - -/** - * Created by NVlad on 11.01.2017. - */ -class ComponentUtil { - @Nullable - static NewExpression configForNewExpression(PsiElement psiElement) { - if (psiElement instanceof NewExpression) { - return (NewExpression) psiElement; - } - - PsiElement parent = psiElement.getParent(); - if (parent != null) { - return configForNewExpression(parent); - } - - return null; - } - - static int paramIndexForElement(PsiElement psiElement) { - PsiElement parent = psiElement.getParent(); - if (parent == null) { - return -1; - } - - if (parent instanceof ParameterList) { - return ArrayUtil.indexOf(((ParameterList) parent).getParameters(), psiElement); - } - - return paramIndexForElement(parent); - } - - - @Nullable - static PhpClass getPhpClass(PhpPsiElement phpPsiElement) { - while (phpPsiElement != null) { - if (phpPsiElement instanceof ClassReference) { - return (PhpClass) ((ClassReference) phpPsiElement).resolve(); - } - if (phpPsiElement instanceof NewExpression) { - ClassReference classReference = ((NewExpression) phpPsiElement).getClassReference(); - if (classReference != null) { - PhpPsiElement resolve = (PhpPsiElement) classReference.resolve(); - if (resolve instanceof PhpClass) { - return (PhpClass) resolve; - } - } - } - - phpPsiElement = (PhpPsiElement) phpPsiElement.getParent(); - } - - return null; - } - - static Collection getClassFields(PhpClass phpClass) { - final HashSet result = new HashSet<>(); - - final Collection fields = phpClass.getFields(); - final Collection methods = phpClass.getMethods(); - for (Field field : fields) { - if (field.isConstant()) { - continue; - } - - final PhpModifier modifier = field.getModifier(); - if (!modifier.isPublic() || modifier.isStatic()) { - continue; - } - - if (field instanceof PhpDocProperty) { - final String setter = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); - Boolean setterExist = false; - for (Method method : methods) { - if (method.getName().equals(setter)) { - setterExist = true; - break; - } - } - if (!setterExist) { - String getter = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); - Boolean getterExist = false; - for (Method method : methods) { - if (method.getName().equals(getter)) { - getterExist = true; - break; - } - } - if (getterExist) { - continue; - } - } - } - - result.add(field); - } - - return result; - } -} From c3f1de9ddf79f2414fe625604088925c5d8bc3c9 Mon Sep 17 00:00:00 2001 From: NVlad Date: Fri, 17 Mar 2017 11:57:19 +0300 Subject: [PATCH 17/33] restructure plugin.xml --- resources/META-INF/plugin.xml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 1e8fec5d..786d6dc8 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -46,15 +46,8 @@ - - - + + + + + - From 6984852c3c9e9c78de30473af5430c724a34470b Mon Sep 17 00:00:00 2001 From: NVlad Date: Fri, 17 Mar 2017 11:58:09 +0300 Subject: [PATCH 18/33] add description for MissedFieldInspection --- resources/inspectionDescriptions/MissedFieldInspection.html | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 resources/inspectionDescriptions/MissedFieldInspection.html diff --git a/resources/inspectionDescriptions/MissedFieldInspection.html b/resources/inspectionDescriptions/MissedFieldInspection.html new file mode 100644 index 00000000..82e6e70d --- /dev/null +++ b/resources/inspectionDescriptions/MissedFieldInspection.html @@ -0,0 +1,5 @@ + + +Missed field in object. + + \ No newline at end of file From 55d43498ac6a48e5ad709a16ab1317930a431d04 Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 17 Mar 2017 12:55:09 +0100 Subject: [PATCH 19/33] GridView column fix and test --- .../objectfactory/ObjectFactoryUtils.java | 12 +++++------- .../objectfactory/ObjectFactoryTests.java | 9 +++++++++ .../yii2support/objectfactory/fixtures/classes.php | 11 +++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index f7f4b4b6..61a5ecf1 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -117,9 +117,10 @@ static PhpClass getPhpClassInWidget(ArrayCreationExpression arrayCreation) { } static PhpClass getPhpClassInGridColumns(ArrayCreationExpression arrayCreation) { - PsiElement parent = arrayCreation.getParent().getParent(); - if (parent != null && parent instanceof ArrayCreationExpression) { - PsiElement possibleHashElement = arrayCreation.getParent().getParent().getParent().getParent(); + // PsiElement parent = arrayCreation.getParent(); + + // if (parent != null && parent instanceof ArrayCreationExpression) { + PsiElement possibleHashElement = arrayCreation.getParent().getParent(); if (possibleHashElement instanceof ArrayHashElement && ((ArrayHashElement) possibleHashElement).getKey().getText() != null && @@ -139,7 +140,7 @@ static PhpClass getPhpClassInGridColumns(ArrayCreationExpression arrayCreation) } - } + // } return null; } @@ -149,16 +150,13 @@ static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, phpClass = findClassByArray(arrayCreation); if (phpClass == null){ phpClass = getClassByInstatiation(arrayCreation); - } if (phpClass == null) { phpClass = getPhpClassByYiiCreateObject(arrayCreation); } if (phpClass == null) { - phpClass = getPhpClassInConfig(dir, arrayCreation); } - if (phpClass == null) { phpClass = getPhpClassInWidget(arrayCreation); } diff --git a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java index 598067a6..a9d5cb11 100644 --- a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java +++ b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java @@ -78,4 +78,13 @@ public void testCompletionYii_createObject() { assertEquals(myFixture.getLookupElementStrings().toArray().length, 3); } + public void testCompletionYii_gridColumns() { + + myFixture.configureByText(PhpFileType.INSTANCE, " [''] "); + myFixture.completeBasic(); + assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); + } + } diff --git a/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php b/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php index 972cf60d..5327fb62 100644 --- a/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php +++ b/tests/com/nvlad/yii2support/objectfactory/fixtures/classes.php @@ -71,3 +71,14 @@ class Yii extends BaseYii { } } +namespace yii\grid { + class GridView { + public $column; + } + + class DataColumn { + public $test1; + public $test2; + } +} + From b40b9742013bcd3a48d13825d207a574178acdce Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 17 Mar 2017 13:41:16 +0100 Subject: [PATCH 20/33] GridView column fix and test --- .../yii2support/objectfactory/ObjectFactoryUtils.java | 9 ++++----- .../yii2support/objectfactory/ObjectFactoryTests.java | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index 61a5ecf1..dd9b0ade 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -117,10 +117,9 @@ static PhpClass getPhpClassInWidget(ArrayCreationExpression arrayCreation) { } static PhpClass getPhpClassInGridColumns(ArrayCreationExpression arrayCreation) { - // PsiElement parent = arrayCreation.getParent(); - - // if (parent != null && parent instanceof ArrayCreationExpression) { - PsiElement possibleHashElement = arrayCreation.getParent().getParent(); + PsiElement parent = arrayCreation.getParent().getParent(); + if (parent != null && parent instanceof ArrayCreationExpression) { + PsiElement possibleHashElement = arrayCreation.getParent().getParent().getParent().getParent(); if (possibleHashElement instanceof ArrayHashElement && ((ArrayHashElement) possibleHashElement).getKey().getText() != null && @@ -140,7 +139,7 @@ static PhpClass getPhpClassInGridColumns(ArrayCreationExpression arrayCreation) } - // } + } return null; } diff --git a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java index a9d5cb11..c27703eb 100644 --- a/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java +++ b/tests/com/nvlad/yii2support/objectfactory/ObjectFactoryTests.java @@ -82,7 +82,7 @@ public void testCompletionYii_gridColumns() { myFixture.configureByText(PhpFileType.INSTANCE, " [''] "); + " 'columns' => [['']] "); myFixture.completeBasic(); assertEquals(myFixture.getLookupElementStrings().toArray().length, 2); } From 6a063737ffc06c34f17ebbf8c4e1b6ec48cf8c97 Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 20 Mar 2017 13:37:13 +0100 Subject: [PATCH 21/33] README update --- src/com/nvlad/yii2support/objectfactory/README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index e639471e..bdc1116e 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -13,4 +13,16 @@ Following class reference representations supported: Code completion for GridView columns is supported This module supports Go To Declaration, Rename, Find usages - \ No newline at end of file + + ------------------------------------ + Description + + Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation. + Following cases are supported: + * Array have "class" key with valid class representation: string representation, ClassName::class or Class::className() + * Array is a value of a key that corresponds to standard Yii classes (like "db", "request", "mailer" and so on), and file with this array located in a directory called "config" + * WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of \yii\base\Widget + * $field->widget() method call on \yii\widgets\ActiveField and its descendants + * Inside array in GridView "columns" key + +Go To Declaration, Rename and Find usages works whenever code completion works \ No newline at end of file From a87411ba224f3b8e4f953c8590fad382663e4cd7 Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 20 Mar 2017 13:46:50 +0100 Subject: [PATCH 22/33] README update --- src/com/nvlad/yii2support/objectfactory/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index bdc1116e..c61c3c44 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -19,7 +19,7 @@ Following class reference representations supported: Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation. Following cases are supported: - * Array have "class" key with valid class representation: string representation, ClassName::class or Class::className() + * Array have "class" key with valid class representation: fully qualified string representation, ClassName::class or Class::className() * Array is a value of a key that corresponds to standard Yii classes (like "db", "request", "mailer" and so on), and file with this array located in a directory called "config" * WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of \yii\base\Widget * $field->widget() method call on \yii\widgets\ActiveField and its descendants From 98004d50e5485c3c99c9d634d5e0f32f9793ce06 Mon Sep 17 00:00:00 2001 From: NVlad Date: Mon, 20 Mar 2017 17:03:01 +0300 Subject: [PATCH 23/33] add default class for configuration "db" component --- src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index dd9b0ade..213dacc3 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -227,6 +227,7 @@ static PhpClass getStandardPhpClass(PhpIndex phpIndex, String shortName) { case "user": return ClassUtils.getClass(phpIndex, "\\yii\\web\\User"); case "errorHandler": return ClassUtils.getClass(phpIndex, "\\yii\\web\\ErrorHandler"); // base/Application + case "db": return ClassUtils.getClass(phpIndex, "\\yii\\db\\Connection"); case "log": return ClassUtils.getClass(phpIndex, "\\yii\\log\\Dispatcher"); case "view": return ClassUtils.getClass(phpIndex, "\\yii\\web\\View"); case "formatter": return ClassUtils.getClass(phpIndex, "yii\\i18n\\Formatter"); From 78f3bbc70fe2a6f726be95a6357b7e36a88c8ebf Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 20 Mar 2017 15:25:17 +0100 Subject: [PATCH 24/33] README update --- src/com/nvlad/yii2support/objectfactory/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index c61c3c44..84c301ba 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -15,7 +15,7 @@ Following class reference representations supported: This module supports Go To Declaration, Rename, Find usages ------------------------------------ - Description + Configuration arrays Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation. Following cases are supported: From 723ad1b24a4c7b103ec18aef9be0aceca9041649 Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 20 Mar 2017 15:26:55 +0100 Subject: [PATCH 25/33] README update --- src/com/nvlad/yii2support/objectfactory/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index 84c301ba..951c9cd4 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -19,10 +19,12 @@ Following class reference representations supported: Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation. Following cases are supported: + * Arrays in yii\base\Object constructor in $config parameter * Array have "class" key with valid class representation: fully qualified string representation, ClassName::class or Class::className() * Array is a value of a key that corresponds to standard Yii classes (like "db", "request", "mailer" and so on), and file with this array located in a directory called "config" - * WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of \yii\base\Widget - * $field->widget() method call on \yii\widgets\ActiveField and its descendants + * WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of yii\base\Widget + * $field->widget() method call on yii\widgets\ActiveField and its descendants * Inside array in GridView "columns" key + Go To Declaration, Rename and Find usages works whenever code completion works \ No newline at end of file From bde464164a45b11f2d83ff4daff4f7dce1e8124e Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 20 Mar 2017 15:27:58 +0100 Subject: [PATCH 26/33] README update --- src/com/nvlad/yii2support/objectfactory/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index 951c9cd4..58e15f09 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -19,7 +19,7 @@ Following class reference representations supported: Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation. Following cases are supported: - * Arrays in yii\base\Object constructor in $config parameter + * Array in $config parameter in yii\base\Object or its descendants constructor * Array have "class" key with valid class representation: fully qualified string representation, ClassName::class or Class::className() * Array is a value of a key that corresponds to standard Yii classes (like "db", "request", "mailer" and so on), and file with this array located in a directory called "config" * WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of yii\base\Widget From a94588d79f684cc0cd2583506a24ea20817d1ffd Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 20 Mar 2017 21:03:27 +0100 Subject: [PATCH 27/33] README update --- .../yii2support/objectfactory/ObjectFactoryUtils.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java index 213dacc3..8425b4c5 100644 --- a/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java +++ b/src/com/nvlad/yii2support/objectfactory/ObjectFactoryUtils.java @@ -153,9 +153,6 @@ static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, if (phpClass == null) { phpClass = getPhpClassByYiiCreateObject(arrayCreation); } - if (phpClass == null) { - phpClass = getPhpClassInConfig(dir, arrayCreation); - } if (phpClass == null) { phpClass = getPhpClassInWidget(arrayCreation); } @@ -164,7 +161,9 @@ static PhpClass findClassByArrayCreation(ArrayCreationExpression arrayCreation, } if (phpClass == null && arrayCreation.getParent().getParent() instanceof ArrayHashElement) { phpClass = getPhpClassByHash((ArrayHashElement)arrayCreation.getParent().getParent(), dir); - + } + if (phpClass == null) { + phpClass = getPhpClassInConfig(dir, arrayCreation); } return phpClass; } @@ -227,7 +226,6 @@ static PhpClass getStandardPhpClass(PhpIndex phpIndex, String shortName) { case "user": return ClassUtils.getClass(phpIndex, "\\yii\\web\\User"); case "errorHandler": return ClassUtils.getClass(phpIndex, "\\yii\\web\\ErrorHandler"); // base/Application - case "db": return ClassUtils.getClass(phpIndex, "\\yii\\db\\Connection"); case "log": return ClassUtils.getClass(phpIndex, "\\yii\\log\\Dispatcher"); case "view": return ClassUtils.getClass(phpIndex, "\\yii\\web\\View"); case "formatter": return ClassUtils.getClass(phpIndex, "yii\\i18n\\Formatter"); @@ -236,6 +234,8 @@ static PhpClass getStandardPhpClass(PhpIndex phpIndex, String shortName) { case "urlManager": return ClassUtils.getClass(phpIndex, "\\yii\\web\\UrlManager"); case "assetManager": return ClassUtils.getClass(phpIndex, "\\yii\\web\\AssetManager"); case "security": return ClassUtils.getClass(phpIndex, "\\yii\\base\\Security"); + // custom + case "db": return ClassUtils.getClass(phpIndex, "\\yii\\db\\Connection"); } return null; } From 32dd6d7d747ffa16dc915fdef02d548de8c1e98d Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 21 Mar 2017 09:27:43 +0100 Subject: [PATCH 28/33] README update --- src/com/nvlad/yii2support/objectfactory/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/nvlad/yii2support/objectfactory/README.md b/src/com/nvlad/yii2support/objectfactory/README.md index 58e15f09..0c26f263 100644 --- a/src/com/nvlad/yii2support/objectfactory/README.md +++ b/src/com/nvlad/yii2support/objectfactory/README.md @@ -27,4 +27,4 @@ Following class reference representations supported: * Inside array in GridView "columns" key -Go To Declaration, Rename and Find usages works whenever code completion works \ No newline at end of file +Go To Declaration, Rename, Find usages and Help popup works whenever code completion works \ No newline at end of file From ba8111b557ef4662fe7a0d2edfdc95184a5b3c15 Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 22 Mar 2017 11:23:43 +0100 Subject: [PATCH 29/33] README update --- resources/META-INF/plugin.xml | 59 +++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 786d6dc8..dddbb8ee 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -5,23 +5,38 @@ NVlad -
- Features +

Yii2 Support for PhpStorm

+ +

Views

    -
  • - Views
    - - View files completion
    - - Add View parameters after completion
    - - Inspection missed View files
    - - QuickFix for missed files
    - - Jump to View file (go to declaration)
    - - Inspection by required & unused parameters for View render
    - - QuickFix for required & unused parameters
    - - Update path to View file on file move
    -
  • -
  • i18n (completion, generate params array)
  • -
+
  • View files completion
  • +
  • Add View parameters after completion
  • +
  • Inspection missed View files
  • +
  • QuickFix for missed files
  • +
  • Jump to View file (go to declaration)
  • +
  • Inspection by required & unused parameters for View render
  • +
  • QuickFix for required & unused parameters
  • +
  • Update path to View file on file move
  • + +

    i18n

    +
      +
    • Code completion
    • +
    • Generate params array
    • +
    +

    Configuration arrays

    + Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation.
    + Following cases are supported: +
      +
    • Array in $config parameter in yii\base\Object or its descendants constructor
    • +
    • Array have "class" key with valid class representation: fully qualified string representation, ClassName::class or Class::className()
    • +
    • Array is a value of a key that corresponds to standard Yii classes (like "db", "request", "mailer" and so on), and file with this array located in a directory called "config"
    • +
    • WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of yii\base\Widget
    • +
    • $field->widget() method call on yii\widgets\ActiveField and its descendants
    • +
    • Inside array in GridView "columns" key
    • +
    + Go To Declaration, Rename, Find usages and Help popup works whenever code completion works + + ]]>
    - - + + - - + + Date: Wed, 22 Mar 2017 11:25:04 +0100 Subject: [PATCH 30/33] plugin.xml updated --- resources/META-INF/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index dddbb8ee..e8de93b7 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.yii2support Yii2 Support - 0.3.10.11 + 0.3.0.0 NVlad Date: Wed, 22 Mar 2017 11:27:06 +0100 Subject: [PATCH 31/33] plugin.xml updated --- resources/META-INF/plugin.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index e8de93b7..f61c8756 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -3,6 +3,7 @@ Yii2 Support 0.3.0.0 NVlad + Oleg Lemesenko Yii2 Support for PhpStorm From 9e846efebb90b0f8308f0e1ed651de614bb473b7 Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 22 Mar 2017 11:31:00 +0100 Subject: [PATCH 32/33] plugin.xml updated --- resources/META-INF/plugin.xml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index f61c8756..dc1860c9 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -3,7 +3,6 @@ Yii2 Support 0.3.0.0 NVlad - Oleg Lemesenko Yii2 Support for PhpStorm @@ -21,9 +20,9 @@

    i18n

      -
    • Code completion
    • -
    • Generate params array
    • -
    +
  • Code completion
  • +
  • Generate params array
  • +

    Configuration arrays

    Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation.
    Following cases are supported: @@ -41,10 +40,7 @@ ]]>
    -
  • Fix variables used in closures mark as unused
  • -
  • Fix parameter declared with name identical variable in function scope mark as unused
  • - + ]]>
    From cc7da0ef056410058531d985921c7456579cb0ca Mon Sep 17 00:00:00 2001 From: NVlad Date: Wed, 22 Mar 2017 19:06:36 +0300 Subject: [PATCH 33/33] update plugin.xml --- resources/META-INF/plugin.xml | 42 ++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index dc1860c9..502571c1 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.yii2support Yii2 Support - 0.3.0.0 + 0.3.17.0 NVlad Inspection by required & unused parameters for View render
  • QuickFix for required & unused parameters
  • Update path to View file on file move
  • - -

    i18n

    -
      -
    • Code completion
    • -
    • Generate params array
    • -
    -

    Configuration arrays

    - Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation.
    - Following cases are supported: -
      -
    • Array in $config parameter in yii\base\Object or its descendants constructor
    • -
    • Array have "class" key with valid class representation: fully qualified string representation, ClassName::class or Class::className()
    • -
    • Array is a value of a key that corresponds to standard Yii classes (like "db", "request", "mailer" and so on), and file with this array located in a directory called "config"
    • -
    • WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of yii\base\Widget
    • -
    • $field->widget() method call on yii\widgets\ActiveField and its descendants
    • -
    • Inside array in GridView "columns" key
    • -
    - Go To Declaration, Rename, Find usages and Help popup works whenever code completion works + +

    i18n

    +
      +
    • Code completion
    • +
    • Generate params array
    • +
    +

    Configuration arrays

    +

    Code completion for Yii configuration arrays. Works both in configuration files and on object instantiation.
    + Following cases are supported:

    +
      +
    • Array in $config parameter in yii\base\Object or its descendants constructor
    • +
    • Array have "class" key with valid class representation: fully qualified string representation, ClassName::class or Class::className()
    • +
    • Array is a value of a key that corresponds to standard Yii classes (like "db", "request", "mailer" and so on), and file with this array located in a directory called "config"
    • +
    • WidgetClass::widget() and WidgetClass::begin calls if WidgetClass is a descendant of yii\base\Widget
    • +
    • $field->widget() method call on yii\widgets\ActiveField and its descendants
    • +
    • Inside array in GridView "columns" key
    • +
    +

    Go To Declaration, Rename, Find usages and Help popup works whenever code completion works.

    ]]>
    +
  • Code completion for object configuration array (with "class" key), config files, widgets and object creating
  • + ]]>