Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
Expand Down Expand Up @@ -46,6 +47,9 @@
*/
public class AnnotationCompletionContributor extends CompletionContributor {

private static final ElementPattern<PsiElement> DOC_IDENTIFIER_PATTERN =
PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER);

public AnnotationCompletionContributor() {

// @<caret>
Expand Down Expand Up @@ -309,7 +313,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
return;
}

PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(phpDocString, PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER));
PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(phpDocString, DOC_IDENTIFIER_PATTERN);
if(propertyName == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.codeInsight.actions.CodeInsightAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
Expand All @@ -19,6 +20,12 @@
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class DoctrineAddRepositoryGenerateAction extends CodeInsightAction {

private static final ElementPattern<PsiElement> INSIDE_PHP_CLASS_PATTERN =
PlatformPatterns.psiElement().inside(PhpClass.class);
private static final ElementPattern<PsiElement> INSIDE_PHP_DOC_COMMENT_PATTERN =
PlatformPatterns.psiElement().inside(PhpDocComment.class);

@NotNull
@Override
protected CodeInsightActionHandler getHandler() {
Expand Down Expand Up @@ -63,12 +70,12 @@ private static PhpClass getPhpClassOnValidScope(@NotNull Editor editor, @NotNull
}

// attribute and direct hit
if (PlatformPatterns.psiElement().inside(PhpClass.class).accepts(psiElement)) {
if (INSIDE_PHP_CLASS_PATTERN.accepts(psiElement)) {
return PsiTreeUtil.getParentOfType(psiElement, PhpClass.class);
}

// docblock are outside the phpclass scope
if (PlatformPatterns.psiElement().inside(PhpDocComment.class).accepts(psiElement)) {
if (INSIDE_PHP_DOC_COMMENT_PATTERN.accepts(psiElement)) {
PhpDocComment parentOfType = PsiTreeUtil.getParentOfType(psiElement, PhpDocComment.class);
if (parentOfType != null) {
PhpPsiElement nextPsiSibling = parentOfType.getNextPsiSibling();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.codeInsight.actions.CodeInsightAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
Expand All @@ -21,6 +22,10 @@
* @author Daniel Espendiller <daniel@espendiller.net>
*/
abstract public class DoctrineClassGeneratorAction extends CodeInsightAction {

private static final ElementPattern<PsiElement> INSIDE_PHP_CLASS_PATTERN =
PlatformPatterns.psiElement().inside(PhpClass.class);

@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!(file instanceof PhpFile) || !DoctrineUtil.isDoctrineOrmInVendor(project)) {
Expand All @@ -37,7 +42,7 @@ protected boolean isValidForFile(@NotNull Project project, @NotNull Editor edito
return false;
}

if (!PlatformPatterns.psiElement().inside(PhpClass.class).accepts(psiElement)) {
if (!INSIDE_PHP_CLASS_PATTERN.accepts(psiElement)) {
return false;
}

Expand Down Expand Up @@ -76,7 +81,7 @@ public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull Ps
return;
}

if(!PlatformPatterns.psiElement().inside(PhpClass.class).accepts(psiElement)) {
if(!INSIDE_PHP_CLASS_PATTERN.accepts(psiElement)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.codeInsight.actions.CodeInsightAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
Expand All @@ -22,6 +23,9 @@
*/
public class DoctrinePropertyOrmAnnotationGenerateAction extends CodeInsightAction {

private static final ElementPattern<PsiElement> INSIDE_PHP_CLASS_PATTERN =
PlatformPatterns.psiElement().inside(PhpClass.class);

private final PhpGenerateFieldAccessorHandlerBase myHandler = new PhpGenerateFieldAccessorHandlerBase()
{

Expand Down Expand Up @@ -78,7 +82,7 @@ protected boolean isValidForFile(@NotNull Project project, @NotNull Editor edito
return false;
}

if (!PlatformPatterns.psiElement().inside(PhpClass.class).accepts(psiElement)) {
if (!INSIDE_PHP_CLASS_PATTERN.accepts(psiElement)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
Expand Down Expand Up @@ -34,6 +35,10 @@
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class DoctrineTypeDeprecatedInspection extends LocalInspectionTool {

private static final ElementPattern<PsiElement> DOC_IDENTIFIER_PATTERN =
PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER);

@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
Expand Down Expand Up @@ -87,7 +92,7 @@ private static String getContentIfTypeValid(@NotNull StringLiteralExpression str
}
}
} else if (stringLiteralExpression.getNode().getElementType() == PhpDocElementTypes.phpDocString) {
PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(stringLiteralExpression, PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER));
PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(stringLiteralExpression, DOC_IDENTIFIER_PATTERN);
if (propertyName != null && property.equals(propertyName.getText())) {
PhpDocTag phpDocTag = PsiTreeUtil.getParentOfType(stringLiteralExpression, PhpDocTag.class);
if (phpDocTag != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.StandardPatterns;
import com.intellij.psi.PsiElement;
Expand Down Expand Up @@ -31,6 +32,14 @@
*/
public class AnnotationGoToDeclarationHandler implements GotoDeclarationHandler {

// <@Test>, <@Test\Test>
private static final ElementPattern<PsiElement> DOC_TAG_NAME_PATTERN =
PlatformPatterns.psiElement(PhpDocElementTypes.DOC_TAG_NAME).withText(StandardPatterns.string().startsWith("@")).withLanguage(PhpLanguage.INSTANCE);

// @Route(name=<ClassName>::FOO)
private static final ElementPattern<PsiElement> DOC_IDENTIFIER_BEFORE_STATIC_PATTERN =
PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER).beforeLeaf(AnnotationPattern.getDocStaticPattern()).withLanguage(PhpLanguage.INSTANCE);

@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Editor editor) {
Expand All @@ -42,12 +51,12 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit

// <@Test>
// <@Test\Test>
if (PlatformPatterns.psiElement(PhpDocElementTypes.DOC_TAG_NAME).withText(StandardPatterns.string().startsWith("@")).withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) {
if (DOC_TAG_NAME_PATTERN.accepts(psiElement)) {
this.addDocTagNameGoto(psiElement, psiElements);
}

// @Route(name=<ClassName>::FOO)
if (PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER).beforeLeaf(AnnotationPattern.getDocStaticPattern()).withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) {
if (DOC_IDENTIFIER_BEFORE_STATIC_PATTERN.accepts(psiElement)) {
this.addStaticClassTargets(psiElement, psiElements);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ public void collectSlowLineMarkers(@NotNull List<? extends PsiElement> psiElemen
/**
* class "Foo" extends
*/
private static PsiElementPattern.Capture<PsiElement> getClassNamePattern() {
return PlatformPatterns
private static final PsiElementPattern.Capture<PsiElement> CLASS_NAME_PATTERN =
PlatformPatterns
.psiElement(PhpTokenTypes.IDENTIFIER)
.afterLeafSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement(PhpTokenTypes.kwCLASS)
)
.withParent(PhpClass.class)
.withLanguage(PhpLanguage.INSTANCE);

private static PsiElementPattern.Capture<PsiElement> getClassNamePattern() {
return CLASS_NAME_PATTERN;
}
}
Loading
Loading