• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PhpExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.jetbrains.php.lang.psi.elements.PhpExpression的典型用法代码示例。如果您正苦于以下问题:Java PhpExpression类的具体用法?Java PhpExpression怎么用?Java PhpExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PhpExpression类属于com.jetbrains.php.lang.psi.elements包,在下文中一共展示了PhpExpression类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getType

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (!(psiElement instanceof FieldReference)) {
        return null;
    }
    FieldReference fieldReference = (FieldReference)psiElement;
    PhpExpression classReference = fieldReference.getClassReference();
    if (classReference == null) {
        return null;
    }
    PhpType referenceType = classReference.getType();
    String fieldReferenceName = fieldReference.getName();
    if (!StringUtil.startsWithUppercaseCharacter(fieldReferenceName)) {
        return null;
    }
    for (String type : referenceType.getTypes()) {
        if (type.contains("Controller")) {
            return new PhpType().add("\\" + fieldReferenceName)
                    .add("\\" + fieldReferenceName + "Component");
        }
    }
    return null;
}
 
开发者ID:dmeybohm,项目名称:chocolate-cakephp,代码行数:25,代码来源:ControllerFieldTypeProvider.java


示例2: getType

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (!(psiElement instanceof FieldReference)) {
        return null;
    }
    FieldReference fieldReference = (FieldReference)psiElement;
    PhpExpression classReference = fieldReference.getClassReference();
    if (classReference == null) {
        return null;
    }
    PhpType types = classReference.getType();
    String fieldReferenceName = fieldReference.getName();
    if (!StringUtil.startsWithUppercaseCharacter(fieldReferenceName)) {
        return null;
    }
    for (String type : types.getTypes()) {
        if (type.contains("#Vthis")) {
            return new PhpType().add("\\" + fieldReferenceName + "Helper");
        }
    }
    return null;
}
 
开发者ID:dmeybohm,项目名称:chocolate-cakephp,代码行数:24,代码来源:ViewHelperTypeProvider.java


示例3: isYiiCreateObjectMethod

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
public static boolean isYiiCreateObjectMethod(PsiElement psiElement) {
    if (psiElement instanceof MethodReference) {
        MethodReference referenceMethod = (MethodReference) psiElement;
        if (referenceMethod.getName() != null && referenceMethod.getName().equals("createObject")
                && referenceMethod.getParameters().length > 0) {
            PhpExpression classReference = ((MethodReferenceImpl) psiElement).getClassReference();
            if (classReference != null && classReference.getName() != null && classReference.getName().equals("Yii")) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:14,代码来源:MethodUtils.java


示例4: buildVisitor

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpElement(PhpPsiElement element) {

            if (!PlatformPatterns.psiElement(PhpElementTypes.METHOD_REFERENCE).accepts(element)) {
                return;
            }

            MethodReference methodReference = (MethodReference) element;
            ParameterList parameterList = methodReference.getParameterList();
            PhpExpression classReference = methodReference.getClassReference();
            if (classReference != null) {
                PhpType inferredType = classReference.getInferredType();
                String compiledClassMethodKey = inferredType.toString() + "->" + methodReference.getName();
                if (ExtensionScannerUtil.classMethodHasDroppedArguments(element.getProject(), compiledClassMethodKey)) {
                    Integer maximumNumberOfArguments = ExtensionScannerUtil.getMaximumNumberOfArguments(element.getProject(), compiledClassMethodKey);

                    if (parameterList != null && maximumNumberOfArguments != -1 && parameterList.getParameters().length != maximumNumberOfArguments) {
                        problemsHolder.registerProblem(element, "Number of arguments changed with TYPO3 9, consider refactoring");
                    }
                }
            }
        }
    };
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:29,代码来源:MethodArgumentDroppedMatcherInspection.java


示例5: reportTimestamps

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
static void reportTimestamps(
    @NotNull final ProblemsHolder problemsHolder,
    @NotNull final PhpClass phpClass
) {
    final Field fieldTimestamps = PhpClassUtil.findPropertyDeclaration(phpClass, "timestamps");

    if (fieldTimestamps == null) {
        return;
    }

    final PsiElement fieldTimestampsDefaultValue = fieldTimestamps.getDefaultValue();

    if (!(fieldTimestampsDefaultValue instanceof PhpExpression)) {
        return;
    }

    final PsiElement fieldTimestampsDefaultValueResolved = PsiElementUtil.resolve(fieldTimestampsDefaultValue);

    if (!(fieldTimestampsDefaultValueResolved instanceof ConstantReference)) {
        return;
    }

    if (!"true".equals(fieldTimestampsDefaultValueResolved.getText())) {
        return;
    }

    final PsiElement issueReceptor = getReportableElement(phpClass, fieldTimestamps);

    if (issueReceptor == null) {
        return;
    }

    validatePropertyAnnotation(problemsHolder, phpClass, issueReceptor, "created_at", null);
    validatePropertyAnnotation(problemsHolder, phpClass, issueReceptor, "updated_at", null);
}
 
开发者ID:rentalhost,项目名称:laravel-insight,代码行数:36,代码来源:ColumnWithoutAnnotationInspection.java


示例6: getStringLiteral

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
@NotNull
private static PsiElement getStringLiteral(
    @NotNull final PsiElement fileSample,
    final String variableName
) {
    return valueOf((PhpExpression) ((AssignmentExpression) getElementByName(fileSample, variableName).getParent()).getValue());
}
 
开发者ID:rentalhost,项目名称:laravel-insight,代码行数:8,代码来源:PsiElementUtilTest.java


示例7: getGotoDeclarationTargets

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
    if (psiElement == null) {
        return PsiElement.EMPTY_ARRAY;
    }
    if (!PlatformPatterns.psiElement().withParent(FieldReference.class).accepts(psiElement)) {
        return PsiElement.EMPTY_ARRAY;
    }
    PsiElement parent = psiElement.getParent();
    if (parent == null) {
        return PsiElement.EMPTY_ARRAY;
    }
    FieldReference fieldReference = (FieldReference)parent;
    String fieldName = fieldReference.getName();
    if (fieldName == null) {
        return PsiElement.EMPTY_ARRAY;
    }
    PhpExpression classReference = fieldReference.getClassReference();
    if (classReference == null) {
        return null;
    }
    PhpType types = classReference.getType();
    String fieldReferenceName = fieldReference.getName();
    if (!StringUtil.startsWithUppercaseCharacter(fieldReferenceName)) {
        return null;
    }
    for (String type : types.getTypes()) {
        if (type.contains("#Vthis")) {
            Collection<PhpClass> classes = PsiUtil.getViewHelperClasses(fieldName, psiElement.getProject());
            return classes.toArray(new PsiElement[classes.size()]);
        }
    }
    return PsiElement.EMPTY_ARRAY;
}
 
开发者ID:dmeybohm,项目名称:chocolate-cakephp,代码行数:36,代码来源:ViewHelperGotoDeclarationHandler.java


示例8: reportPrimaryKey

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
static void reportPrimaryKey(
    @NotNull final ProblemsHolder problemsHolder,
    @NotNull final PhpClass phpClass
) {
    final PsiElement issueReceptor;
    final Field      fieldPrimaryKey              = PhpClassUtil.findPropertyDeclaration(phpClass, "primaryKey");
    String           fieldPrimaryKeyResolvedValue = "id";

    if (fieldPrimaryKey != null) {
        final PsiElement fieldPrimaryKeyValue = fieldPrimaryKey.getDefaultValue();

        if (!(fieldPrimaryKeyValue instanceof PhpExpression)) {
            return;
        }

        final PsiElement fieldPrimaryKeyResolved = PsiElementUtil.resolve(fieldPrimaryKeyValue);

        if (!(fieldPrimaryKeyResolved instanceof StringLiteralExpression)) {
            return;
        }

        fieldPrimaryKeyResolvedValue = ((StringLiteralExpression) fieldPrimaryKeyResolved).getContents();
        issueReceptor = getReportableElement(phpClass, fieldPrimaryKey);
    }
    else {
        final PsiElement issueReceptorPrimary = phpClass.getNameIdentifier();
        issueReceptor = (issueReceptorPrimary == null) ? phpClass : issueReceptorPrimary;
    }

    if (issueReceptor == null) {
        return;
    }

    final Field fieldKeyType = PhpClassUtil.findPropertyDeclaration(phpClass, "keyType");
    String      fieldType    = "int";

    if (fieldKeyType != null) {
        final PsiElement fieldKeyTypeValueRaw = fieldKeyType.getDefaultValue();

        if (fieldKeyTypeValueRaw != null) {
            final PsiElement fieldKeyTypeValue = PsiElementUtil.resolve(fieldKeyTypeValueRaw);

            if (fieldKeyTypeValue instanceof StringLiteralExpression) {
                fieldType = ((StringLiteralExpression) fieldKeyTypeValue).getContents();
            }
        }
    }

    validatePropertyAnnotation(problemsHolder, phpClass, issueReceptor, fieldPrimaryKeyResolvedValue, fieldType);
}
 
开发者ID:rentalhost,项目名称:laravel-insight,代码行数:51,代码来源:ColumnWithoutAnnotationInspection.java


示例9: register

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {

        // "@var $om \Doctrine\Common\Persistence\ObjectManager"
        // "$om->getRepository('Foo\Bar')->" + s + "(['foo' => 'foo', '<caret>' => 'foo'])"
        registrar.register(PhpElementsUtil.getParameterListArrayValuePattern(), psiElement -> {
            PsiElement context = psiElement.getContext();
            if (!(context instanceof StringLiteralExpression)) {
                return null;
            }

            MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.ArrayParameterMatcher(context, 0)
                .withSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findOneBy")
                .withSignature("\\Doctrine\\Common\\Persistence\\ObjectRepository", "findBy")
                .match();

            if(methodMatchParameter != null) {
                MethodReference methodReference = methodMatchParameter.getMethodReference();

                // extract from type provide on completion:
                // $foo->getRepository('MODEL')->findBy()
                Collection<PhpClass> phpClasses = PhpElementsUtil.getClassFromPhpTypeSetArrayClean(psiElement.getProject(), methodReference.getType().getTypes());

                // resolve every direct repository instance $this->findBy()
                // or direct repository instance $repository->findBy()
                if(phpClasses.size() == 0) {
                    PhpExpression classReference = methodReference.getClassReference();
                    if(classReference != null) {
                        PhpType type = classReference.getType();
                        for (String s : type.getTypes()) {
                            // dont visit type providers
                            if(PhpType.isUnresolved(s)) {
                                continue;
                            }

                            for (DoctrineModelInterface doctrineModel : DoctrineMetadataUtil.findMetadataModelForRepositoryClass(psiElement.getProject(), s)) {
                                phpClasses.addAll(PhpElementsUtil.getClassesInterface(psiElement.getProject(), doctrineModel.getClassName()));
                            }
                        }
                    }
                }

                if(phpClasses.size() == 0) {
                    return null;
                }

                return new MyArrayFieldMetadataGotoCompletionRegistrar(psiElement, phpClasses);
            }

            return null;
        });
    }
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:52,代码来源:ObjectRepositoryFindGotoCompletionRegistrar.java


示例10: testResolve

import com.jetbrains.php.lang.psi.elements.PhpExpression; //导入依赖的package包/类
public void testResolve() {
    final PsiFile fileSample = getResourceFile("utils/PsiElementUtil.warpingLiterals.php");

    // Default const types.
    final StringLiteralExpression directLiteral     = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "directLiteral"));
    final StringLiteralExpression indirectLiteral   = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "indirectLiteral"));
    final StringLiteralExpression warpingLiteral    = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "warpingLiteral"));
    final StringLiteralExpression assignedLiteral   = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "assignedLiteral"));
    final StringLiteralExpression withSubAssignment = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "withSubAssignment"));

    Assert.assertEquals("directValue", directLiteral.getContents());

    Assert.assertEquals("indirectValue", indirectLiteral.getContents());
    Assert.assertEquals("indirectValue", warpingLiteral.getContents());
    Assert.assertEquals("indirectValue", assignedLiteral.getContents());
    Assert.assertEquals("indirectValue", withSubAssignment.getContents());

    final PsiElement ccUnresolvedConstantReference = getElementByName(fileSample, "ccUnresolvedConstantReference");

    Assert.assertTrue(PsiElementUtil.resolve(ccUnresolvedConstantReference) instanceof ConstantReference);

    // Class const types.
    final StringLiteralExpression classIndirectLiteral = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "classIndirectLiteral"));
    final StringLiteralExpression classWarpingLiteral  = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "classWarpingLiteral"));

    Assert.assertEquals("indirectClassValue", classIndirectLiteral.getContents());
    Assert.assertEquals("indirectClassValue", classWarpingLiteral.getContents());

    final PsiElement classResolvingFromProperty =
        PsiElementUtil.resolve(valueOf((PhpExpression) ((Field) getElementByName(fileSample, "resolvingFromProperty")).getDefaultValue()));

    Assert.assertEquals("TRUE", classResolvingFromProperty.getText());

    final PsiElement classResolvingDirectlyFromProperty =
        PsiElementUtil.resolve(valueOf((PhpExpression) ((Field) getElementByName(fileSample, "resolvingDirectlyFromProperty")).getDefaultValue()));

    Assert.assertEquals("null", classResolvingDirectlyFromProperty.getText());

    // Avoiding complex loopings.
    final PsiElement shouldAvoidCyclicLoopingsWithConstants = getElementByName(fileSample, "shouldAvoidCyclicLoopingsWithConstants");

    Assert.assertEquals("SHOULD_IGNORES_CYCLIC_LOOPINGS_A", PsiElementUtil.resolve(shouldAvoidCyclicLoopingsWithConstants).getText());

    final PsiElement shouldAvoidCyclicLoopingsWithVariablesA = getElementByName(fileSample, "shouldAvoidCyclicLoopingsWithVariablesA");

    Assert.assertEquals("$shouldAvoidCyclicLoopingsWithVariablesA", PsiElementUtil.resolve(shouldAvoidCyclicLoopingsWithVariablesA).getText());

    // Resolving variables.
    final StringLiteralExpression variableWrapping = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "variableWrapping"));

    Assert.assertEquals("value", variableWrapping.getContents());

    // With wrapping parentheses.
    final StringLiteralExpression withParanteshesWrapping = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "withParanteshesWrapping"));

    Assert.assertEquals("parentheses", withParanteshesWrapping.getContents());

    // Should not resolve totally.
    final PsiElement indirectShouldNotResolveTotally = PsiElementUtil.resolve(getStringLiteral(fileSample, "indirectShouldNotResolveTotally"));

    Assert.assertTrue(indirectShouldNotResolveTotally instanceof MethodReference);

    // Stop on first ConstantReference.
    final PsiElement stopOnFirstConstantReference =
        PsiElementUtil.resolve(getStringLiteral(fileSample, "stopOnFirstConstantReference"), ConstantReference.class::isInstance);

    Assert.assertTrue(stopOnFirstConstantReference instanceof ConstantReference);
    Assert.assertEquals("$stopOnFirstConstantReference = SHOULD_STOP_HERE", stopOnFirstConstantReference.getParent().getText());

    final PsiElement stopOnFirstConstantReferenceIndirect =
        PsiElementUtil.resolve(getStringLiteral(fileSample, "stopOnFirstConstantReferenceIndirect"), ConstantReference.class::isInstance);

    Assert.assertTrue(stopOnFirstConstantReferenceIndirect instanceof ConstantReference);
    Assert.assertEquals("$stopOnFirstConstantReference = SHOULD_STOP_HERE", stopOnFirstConstantReferenceIndirect.getParent().getText());

    // Make sure that resolves to a @property will not broke.
    final AssignmentExpression ccInstancePropertyRef = (AssignmentExpression) getElementByName(fileSample, "ccInstancePropertyRef").getParent();
    final PsiElement           ccInstanceProperty    = PsiElementUtil.resolve(valueOf((PhpExpression) ccInstancePropertyRef.getValue()));

    Assert.assertTrue(ccInstanceProperty instanceof PhpDocProperty);
}
 
开发者ID:rentalhost,项目名称:laravel-insight,代码行数:82,代码来源:PsiElementUtilTest.java



注:本文中的com.jetbrains.php.lang.psi.elements.PhpExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PortType类代码示例发布时间:2022-05-22
下一篇:
Java PartMap类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap