forked from Haehnchen/idea-php-toolbox
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add references for Doctrine @Orm\Embedded.class Haehnchen#68
- Loading branch information
Showing
5 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/de/espend/idea/php/annotation/doctrine/reference/EmbeddedClassCompletionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package de.espend.idea.php.annotation.doctrine.reference; | ||
|
||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiReference; | ||
import com.jetbrains.php.PhpIndex; | ||
import com.jetbrains.php.completion.PhpCompletionUtil; | ||
import com.jetbrains.php.lang.PhpLangUtil; | ||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; | ||
import de.espend.idea.php.annotation.extension.PhpAnnotationCompletionProvider; | ||
import de.espend.idea.php.annotation.extension.PhpAnnotationReferenceProvider; | ||
import de.espend.idea.php.annotation.extension.parameter.AnnotationCompletionProviderParameter; | ||
import de.espend.idea.php.annotation.extension.parameter.AnnotationPropertyParameter; | ||
import de.espend.idea.php.annotation.extension.parameter.PhpAnnotationReferenceProviderParameter; | ||
import de.espend.idea.php.annotation.reference.references.PhpClassReference; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public class EmbeddedClassCompletionProvider implements PhpAnnotationReferenceProvider, PhpAnnotationCompletionProvider { | ||
@Nullable | ||
@Override | ||
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter parameter, PhpAnnotationReferenceProviderParameter referencesByElementParameter) { | ||
if(parameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE || | ||
!"class".equals(parameter.getPropertyName()) || | ||
!PhpLangUtil.equalsClassNames(parameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Embedded") | ||
) { | ||
return new PsiReference[0]; | ||
} | ||
|
||
PsiElement element = parameter.getElement(); | ||
if(!(element instanceof StringLiteralExpression) || StringUtils.isBlank(((StringLiteralExpression) element).getContents())) { | ||
return new PsiReference[0]; | ||
} | ||
|
||
return new PsiReference[] { | ||
new PhpClassReference((StringLiteralExpression) element) | ||
}; | ||
} | ||
|
||
@Override | ||
public void getPropertyValueCompletions(AnnotationPropertyParameter parameter, AnnotationCompletionProviderParameter completionParameter) { | ||
if(parameter.getType() != AnnotationPropertyParameter.Type.PROPERTY_VALUE || | ||
!"class".equals(parameter.getPropertyName()) || | ||
!PhpLangUtil.equalsClassNames(parameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Embedded") | ||
) { | ||
return; | ||
} | ||
|
||
String className = ""; | ||
PsiElement element = parameter.getElement(); | ||
if(element instanceof StringLiteralExpression) { | ||
className = ((StringLiteralExpression) element).getContents(); | ||
} | ||
|
||
PhpIndex phpIndex = PhpIndex.getInstance(parameter.getProject()); | ||
PhpCompletionUtil.addClasses(className, completionParameter.getResult(), phpIndex, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...end/idea/php/annotation/tests/doctrine/reference/EmbeddedClassCompletionProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package de.espend.idea.php.annotation.tests.doctrine.reference; | ||
|
||
import com.intellij.patterns.PlatformPatterns; | ||
import com.jetbrains.php.lang.PhpFileType; | ||
import com.jetbrains.php.lang.psi.elements.PhpClass; | ||
import de.espend.idea.php.annotation.tests.AnnotationLightCodeInsightFixtureTestCase; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public class EmbeddedClassCompletionProviderTest extends AnnotationLightCodeInsightFixtureTestCase { | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
myFixture.copyFileToProject("classes.php"); | ||
} | ||
|
||
public String getTestDataPath() { | ||
return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath(); | ||
} | ||
|
||
public void testThatDoctrineEmbeddedClassPropertyProvidesClassReferences() { | ||
assertCompletionContains(PhpFileType.INSTANCE, "<?php\n" + | ||
"use Doctrine\\ORM\\Mapping as ORM;\n" + | ||
"class Foo\n" + | ||
"{\n" + | ||
" /** @ORM\\Embedded(class=\"<caret>\") */\n" + | ||
" protected $logo;\n" + | ||
"}", | ||
"Bar" | ||
); | ||
|
||
assertReferenceMatchOnParent(PhpFileType.INSTANCE, "<?php\n" + | ||
"use Doctrine\\ORM\\Mapping as ORM;\n" + | ||
"class Foo\n" + | ||
"{\n" + | ||
" /** @ORM\\Embedded(class=\"My\\FooC<caret>lass\\Bar\") */\n" + | ||
" protected $logo;\n" + | ||
"}", | ||
PlatformPatterns.psiElement(PhpClass.class) | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/de/espend/idea/php/annotation/tests/doctrine/reference/fixtures/classes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Doctrine\ORM\Mapping | ||
{ | ||
/** | ||
* @Annotation | ||
* @Target("PROPERTY") | ||
*/ | ||
final class Embedded implements Annotation | ||
{ | ||
} | ||
} | ||
|
||
namespace My\FooClass | ||
{ | ||
class Bar | ||
{ | ||
} | ||
} |