Search in sources :

Example 6 with StringLiteralExpression

use of com.jetbrains.php.lang.psi.elements.StringLiteralExpression in project idea-php-typo3-plugin by cedricziel.

the class RouteAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (!(psiElement instanceof StringLiteralExpression)) {
        return;
    }
    StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
    String value = literalExpression.getContents();
    if (value.isEmpty()) {
        return;
    }
    for (PsiReference psiReference : literalExpression.getReferences()) {
        if (psiReference instanceof RouteReference) {
            annotateRoute(psiElement, annotationHolder, value);
        }
    }
}
Also used : RouteReference(com.cedricziel.idea.typo3.routing.RouteReference) StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) PsiReference(com.intellij.psi.PsiReference)

Example 7 with StringLiteralExpression

use of com.jetbrains.php.lang.psi.elements.StringLiteralExpression in project idea-php-typo3-plugin by cedricziel.

the class ClassConstantMatcherInspection method getDeprecatedClassConstants.

private Set<String> getDeprecatedClassConstants(PhpPsiElement element) {
    Set<PsiElement> elements = new HashSet<>();
    PsiFile[] classConstantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
    for (PsiFile file : classConstantMatcherFiles) {
        Collections.addAll(elements, PsiTreeUtil.collectElements(file, el -> PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withAncestor(4, PlatformPatterns.psiElement(PhpElementTypes.RETURN))).accepts(el)));
    }
    return elements.stream().map(stringLiteral -> ((StringLiteralExpression) stringLiteral).getContents()).collect(Collectors.toSet());
}
Also used : PhpElementVisitor(com.jetbrains.php.lang.psi.visitors.PhpElementVisitor) GroupNames(com.intellij.codeInsight.daemon.GroupNames) FilenameIndex(com.intellij.psi.search.FilenameIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ClassConstantReference(com.jetbrains.php.lang.psi.elements.ClassConstantReference) Set(java.util.Set) Collectors(java.util.stream.Collectors) PlatformPatterns(com.intellij.patterns.PlatformPatterns) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) HashSet(java.util.HashSet) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Nls(org.jetbrains.annotations.Nls) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) PhpInspection(com.jetbrains.php.lang.inspections.PhpInspection) StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) NotNull(org.jetbrains.annotations.NotNull) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) Collections(java.util.Collections) PhpElementTypes(com.jetbrains.php.lang.parser.PhpElementTypes) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) PsiFile(com.intellij.psi.PsiFile) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet)

Example 8 with StringLiteralExpression

use of com.jetbrains.php.lang.psi.elements.StringLiteralExpression in project idea-php-typo3-plugin by cedricziel.

the class TCAUtil method getAvailableRenderTypes.

public static Set<String> getAvailableRenderTypes(PsiElement element) {
    Set<String> renderTypes = new HashSet<>();
    Set<PsiElement> elementsFromExtLocalConf = findAvailableRenderTypes(element.getProject());
    // add static list of render types
    renderTypes.addAll(Arrays.asList(TCA_CORE_RENDER_TYPES));
    // add dynamic list of render types from nodeRegistry
    for (PsiElement el : elementsFromExtLocalConf) {
        if (el instanceof StringLiteralExpression) {
            renderTypes.add(((StringLiteralExpression) el).getContents());
        }
    }
    return renderTypes;
}
Also used : StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) PsiElement(com.intellij.psi.PsiElement)

Example 9 with StringLiteralExpression

use of com.jetbrains.php.lang.psi.elements.StringLiteralExpression in project idea-php-typo3-plugin by cedricziel.

the class TYPO3Utility method getTYPO3Version.

@Nullable
public static String getTYPO3Version(@NotNull Project project) {
    Constant versionConstant = getVersionConstant(project);
    if (versionConstant == null) {
        return null;
    }
    PsiElement value = versionConstant.getValue();
    if (value instanceof StringLiteralExpression) {
        return ((StringLiteralExpression) value).getContents();
    }
    return null;
}
Also used : StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) Constant(com.jetbrains.php.lang.psi.elements.Constant) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with StringLiteralExpression

use of com.jetbrains.php.lang.psi.elements.StringLiteralExpression in project idea-php-typo3-plugin by cedricziel.

the class CreateMissingTranslationQuickFix method applyFix.

/**
 * Called to apply the fix.
 *
 * @param project    {@link Project}
 * @param descriptor problem reported by the tool which provided this quick fix action
 */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement psiElement = descriptor.getPsiElement();
    if (psiElement instanceof StringLiteralExpression) {
        StringLiteralExpression stringElement = (StringLiteralExpression) psiElement;
        String contents = stringElement.getContents();
        String fileName = TranslationUtil.extractResourceFilenameFromTranslationString(contents);
        String key = TranslationUtil.extractTranslationKeyTranslationString(contents);
        if (fileName != null) {
            PsiElement[] elementsForKey = ResourcePathIndex.findElementsForKey(project, fileName);
            if (elementsForKey.length > 0) {
            // TranslationUtil.add();
            }
        }
    }
}
Also used : StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

StringLiteralExpression (com.jetbrains.php.lang.psi.elements.StringLiteralExpression)39 PsiElement (com.intellij.psi.PsiElement)35 NotNull (org.jetbrains.annotations.NotNull)28 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)18 FunctionReference (com.jetbrains.php.lang.psi.elements.FunctionReference)16 HashSet (java.util.HashSet)8 PhpElementVisitor (com.jetbrains.php.lang.psi.visitors.PhpElementVisitor)7 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)6 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)6 ArrayCreationExpression (com.jetbrains.php.lang.psi.elements.ArrayCreationExpression)6 PhpPsiElement (com.jetbrains.php.lang.psi.elements.PhpPsiElement)6 Set (java.util.Set)6 Project (com.intellij.openapi.project.Project)5 PhpElementTypes (com.jetbrains.php.lang.parser.PhpElementTypes)5 GroupNames (com.intellij.codeInsight.daemon.GroupNames)4 PlatformPatterns (com.intellij.patterns.PlatformPatterns)4 PsiFile (com.intellij.psi.PsiFile)4 FilenameIndex (com.intellij.psi.search.FilenameIndex)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 IElementType (com.intellij.psi.tree.IElementType)4