Search in sources :

Example 36 with StringLiteralExpression

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

the class GeneralUtilityServiceTypeProvider method getType.

@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb()) {
        return null;
    }
    if (!(psiElement instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "makeInstanceService")) {
        return null;
    }
    MethodReference methodReference = (MethodReference) psiElement;
    if (methodReference.getParameters().length == 0) {
        return null;
    }
    PsiElement firstParam = methodReference.getParameters()[0];
    if (firstParam instanceof StringLiteralExpression) {
        StringLiteralExpression ref = (StringLiteralExpression) firstParam;
        String serviceId = ref.getContents();
        return new PhpType().add("#" + this.getKey() + serviceId);
    }
    return null;
}
Also used : StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) MethodReference(com.jetbrains.php.lang.psi.elements.MethodReference) PsiElement(com.intellij.psi.PsiElement) PhpType(com.jetbrains.php.lang.psi.resolve.types.PhpType) Nullable(org.jetbrains.annotations.Nullable)

Example 37 with StringLiteralExpression

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

the class RouteLineMarkerProvider method collectNavigationMarkers.

@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
    if (!(element instanceof StringLiteralExpression)) {
        return;
    }
    StringLiteralExpression literalExpression = (StringLiteralExpression) element;
    String value = literalExpression.getContents();
    if (value.isEmpty()) {
        return;
    }
    PsiElement methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getAjaxUrl") || PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "buildUriFromRoute")) {
        if (RouteIndex.hasRoute(element.getProject(), value)) {
            Collection<RouteStub> routes = RouteIndex.getRoute(element.getProject(), value);
            routes.forEach(def -> {
                PsiElement[] routeDefinitionElements = RouteHelper.getRouteDefinitionElements(element.getProject(), value);
                NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(TYPO3CMSIcons.ROUTE_ICON).setTargets(routeDefinitionElements);
                if (def.getPath() != null) {
                    builder.setTooltipTitle("Path: " + def.getPath());
                }
                result.add(builder.createLineMarkerInfo(element));
            });
        }
    }
}
Also used : StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) RouteStub(com.cedricziel.idea.typo3.routing.RouteStub) PsiElement(com.intellij.psi.PsiElement)

Example 38 with StringLiteralExpression

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

the class TYPO3Utility method getTYPO3Branch.

@Nullable
public static String getTYPO3Branch(@NotNull Project project) {
    Constant versionConstant = getBranchVersionConstant(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 39 with StringLiteralExpression

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

the class TranslationAnnotator 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 (TranslationUtil.isTranslationKeyString(value) && value.length() > 4 && !(psiElement.getParent() instanceof ConcatenationExpression)) {
        annotateTranslationUsage(psiElement, annotationHolder, value);
    }
}
Also used : StringLiteralExpression(com.jetbrains.php.lang.psi.elements.StringLiteralExpression) ConcatenationExpression(com.jetbrains.php.lang.psi.elements.ConcatenationExpression)

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