Java Code Examples for com.jetbrains.php.lang.psi.elements.ArrayHashElement#getValue()

The following examples show how to use com.jetbrains.php.lang.psi.elements.ArrayHashElement#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BxComponentIncludeReference.java    From bxfs with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement resolve() {
	BxCore bitrix = new BxCore(getElement().getProject());
	String inclusionType = null;

	for (ArrayHashElement arElement : ((ArrayCreationExpression) getElement().getParent().getParent().getParent()).getHashElements()) {
		if (arElement.getKey() instanceof StringLiteralExpression && ((StringLiteralExpression) arElement.getKey()).getContents().equals("AREA_FILE_SHOW") && arElement.getValue() instanceof StringLiteralExpression)
			inclusionType = ((StringLiteralExpression) arElement.getValue()).getContents();
	}

	if (inclusionType != null) {
		VirtualFile componentTemplateFile = bitrix.getPageIncludeFile(
			getElement(),
			inclusionType.equals("page") ? "index" : "sect"
		);

		if (componentTemplateFile != null)
			return getElement().getManager().findFile(componentTemplateFile);
	}

	return null;
}
 
Example 2
Source File: ArrayReturnPsiRecursiveVisitor.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
public static void collectConfigKeys(ArrayCreationExpression creationExpression, ArrayKeyVisitor arrayKeyVisitor, List<String> context) {

        for(ArrayHashElement hashElement: PsiTreeUtil.getChildrenOfTypeAsList(creationExpression, ArrayHashElement.class)) {

            PsiElement arrayKey = hashElement.getKey();
            PsiElement arrayValue = hashElement.getValue();

            if(arrayKey instanceof StringLiteralExpression) {

                List<String> myContext = new ArrayList<>(context);
                myContext.add(((StringLiteralExpression) arrayKey).getContents());
                String keyName = StringUtils.join(myContext, ".");

                if(arrayValue instanceof ArrayCreationExpression) {
                    arrayKeyVisitor.visit(keyName, arrayKey, true);
                    collectConfigKeys((ArrayCreationExpression) arrayValue, arrayKeyVisitor, myContext);
                } else {
                    arrayKeyVisitor.visit(keyName, arrayKey, false);
                }

            }
        }

    }
 
Example 3
Source File: ArrayReturnPsiRecursiveVisitor.java    From Thinkphp5-Plugin with MIT License 5 votes vote down vote up
public static void collectConfigKeys(ArrayCreationExpression creationExpression, ArrayKeyVisitor arrayKeyVisitor, List<String> context) {

        List<ArrayHashElement> childrenOfTypeAsList = PsiTreeUtil.getChildrenOfTypeAsList(creationExpression, ArrayHashElement.class);
        for (ArrayHashElement hashElement : childrenOfTypeAsList) {  //遍历文件所有元素

            PsiElement arrayKey = hashElement.getKey();
            PsiElement arrayValue = hashElement.getValue();

            if (arrayKey instanceof StringLiteralExpression) {  //键是数组键

                List<String> myContext = new ArrayList<>(context);

                //fwModify: 协助去掉文件前缀
                if (myContext.get(0).equals(""))
                    myContext.remove(0);

                myContext.add(((StringLiteralExpression) arrayKey).getContents());
                String keyName = StringUtils.join(myContext, ".");

                if (arrayValue instanceof ArrayCreationExpression) {
                    arrayKeyVisitor.visit(keyName, arrayKey, false); //数组键也收录
                    collectConfigKeys((ArrayCreationExpression) arrayValue, arrayKeyVisitor, myContext);
                } else {
                    arrayKeyVisitor.visit(keyName, arrayKey, false);
                }
            }
        }

    }
 
Example 4
Source File: RouteGroupUtil.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
/**
 * Analyzes Route::group elements and returns string values for specified property.
 * Route::group(['namespace' => 'Foo'], function() {
 *      Route::group(['namespace' => 'Bar'], function() {
 *          Route::get(...
 *      });
 * });
 *
 * getRouteGroupPropertiesCollection(Route::get element, "namespace") will return list with 'Foo', 'Bar'
 */
@NotNull
public static List<String> getRouteGroupPropertiesCollection(PsiElement element, String propertyName)
{
    List<String> values = new ArrayList<>();

    RouteGroupCondition routeGroupCondition = new RouteGroupCondition();

    PsiElement routeGroup = PsiTreeUtil.findFirstParent(element, true, routeGroupCondition);

    while (routeGroup != null) {
        ArrayCreationExpression arrayCreation = PsiTreeUtil.getChildOfType(((MethodReference)routeGroup).getParameterList(), ArrayCreationExpression.class);

        if (arrayCreation != null) {
            for (ArrayHashElement hashElement : arrayCreation.getHashElements()) {
                if (hashElement.getKey() instanceof StringLiteralExpression) {
                    if (propertyName.equals(((StringLiteralExpression) hashElement.getKey()).getContents())) {
                        if (hashElement.getValue() instanceof StringLiteralExpression) {
                            values.add(((StringLiteralExpression) hashElement.getValue()).getContents());
                        }
                        break;
                    }
                }
            }
        }

        routeGroup = PsiTreeUtil.findFirstParent(routeGroup, true, routeGroupCondition);
    }

    Collections.reverse(values);
    return values;
}
 
Example 5
Source File: MethodArgumentDroppedIndex.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Integer, FileContent> getIndexer() {
    return inputData -> {
        Set<PsiElement> elements = new HashSet<>();

        Collections.addAll(
                elements,
                PsiTreeUtil.collectElements(inputData.getPsiFile(), el -> PlatformPatterns
                        .psiElement(StringLiteralExpression.class)
                        .withParent(
                                PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withAncestor(
                                                4,
                                                PlatformPatterns.psiElement(PhpElementTypes.RETURN)
                                        )
                        )
                        .accepts(el)
                )
        );

        Map<String, Integer> methodMap = new HashMap<>();

        for (PsiElement gatheredElement : elements) {
            PsiElement parent = gatheredElement.getParent().getParent();
            if (parent instanceof ArrayHashElement) {
                ArrayHashElement arr = (ArrayHashElement) parent;
                PhpPsiElement value = arr.getValue();
                if (value instanceof ArrayCreationExpression) {
                    ArrayCreationExpression creationExpression = (ArrayCreationExpression) value;
                    creationExpression.getHashElements().forEach(x -> {
                        PhpPsiElement key = x.getKey();
                        if (key != null && key.getText().contains("maximumNumberOfArguments")) {
                            methodMap.put("\\" + ((StringLiteralExpression) gatheredElement).getContents(), Integer.parseInt(x.getValue().getText()));
                        }
                    });
                }
            }
        }

        return methodMap;
    };
}