com.jetbrains.php.lang.psi.elements.ArrayCreationExpression Java Examples
The following examples show how to use
com.jetbrains.php.lang.psi.elements.ArrayCreationExpression.
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: CompletionNavigationProvider.java From idea-php-generics-plugin with MIT License | 6 votes |
private Collection<PsiElement> collectArrayKeyParameterTargets(PsiElement psiElement) { Collection<PsiElement> psiElements = new HashSet<>(); ArrayCreationExpression parentOfType = PsiTreeUtil.getParentOfType(psiElement, ArrayCreationExpression.class); if (parentOfType != null) { String contents = ((StringLiteralExpression) psiElement).getContents(); psiElements.addAll(GenericsUtil.getTypesForParameter(parentOfType).stream() .filter(parameterArrayType -> parameterArrayType.getKey().equalsIgnoreCase(contents)) .map(ParameterArrayType::getContext).collect(Collectors.toSet()) ); } return psiElements; }
Example #2
Source File: ArrayReturnPsiRecursiveVisitor.java From Thinkphp5-Plugin with MIT License | 6 votes |
@Override public void visitElement(PsiElement element) { // if (element instanceof PhpReturn) { // visitPhpReturn((PhpReturn) element); // } if (element instanceof ArrayCreationExpression && !(element.getParent().getParent() instanceof ArrayHashElement)) { //如果是创建数组会进行收录, 如果是数组中的数组不能满足条件 // if (element instanceof ArrayCreationExpression) { collectConfigKeys((ArrayCreationExpression) element, this.arrayKeyVisitor, fileNameWithoutExtension); // Tool.printPsiTree(element.getParent().getParent()); // element = element.getNextSibling(); } super.visitElement(element); }
Example #3
Source File: ReturnArraySignatureRegistrarMatcher.java From idea-php-toolbox with MIT License | 6 votes |
@Override public boolean matches(@NotNull LanguageMatcherParameter parameter) { PsiElement parent = parameter.getElement().getParent(); if(!(parent instanceof StringLiteralExpression)) { return false; } PsiElement arrayValue = parent.getParent(); if(arrayValue == null || arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) { return false; } PsiElement arrayCreation = arrayValue.getParent(); if(!(arrayCreation instanceof ArrayCreationExpression)) { return false; } PsiElement phpReturn = arrayCreation.getParent(); if(!(phpReturn instanceof PhpReturn)) { return false; } return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn); }
Example #4
Source File: BladePattern.java From idea-php-laravel-plugin with MIT License | 6 votes |
/** * "@foobar(['<caret>'])" * * whereas "foobar" is registered a directive */ public static PsiElementPattern.Capture<PsiElement> getArrayParameterDirectiveForElementType(@NotNull IElementType... elementType) { return PlatformPatterns.psiElement() .withParent( PlatformPatterns.psiElement(StringLiteralExpression.class) .withParent( PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent( PlatformPatterns.psiElement(ArrayCreationExpression.class) .withParent(ParameterList.class) ) ) .with( new MyDirectiveInjectionElementPatternCondition(elementType) ) ) .withLanguage(PhpLanguage.INSTANCE); }
Example #5
Source File: ArrayReturnPsiRecursiveVisitor.java From idea-php-laravel-plugin with MIT License | 6 votes |
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 #6
Source File: ReturnArraySignatureRegistrarMatcher.java From idea-php-toolbox with MIT License | 6 votes |
@Override public boolean matches(@NotNull LanguageMatcherParameter parameter) { PsiElement parent = parameter.getElement().getParent(); if(!(parent instanceof StringLiteralExpression)) { return false; } PsiElement arrayValue = parent.getParent(); if(arrayValue == null || arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) { return false; } PsiElement arrayCreation = arrayValue.getParent(); if(!(arrayCreation instanceof ArrayCreationExpression)) { return false; } PsiElement phpReturn = arrayCreation.getParent(); if(!(phpReturn instanceof PhpReturn)) { return false; } return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn); }
Example #7
Source File: BxComponentIncludeReference.java From bxfs with MIT License | 6 votes |
@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 #8
Source File: CompletionNavigationProvider.java From idea-php-generics-plugin with MIT License | 5 votes |
@Override protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { PsiElement position = parameters.getPosition(); ArrayCreationExpression parentOfType = PsiTreeUtil.getParentOfType(position, ArrayCreationExpression.class); if (parentOfType != null) { result.addAllElements(GenericsUtil.getTypesForParameter(parentOfType).stream() .map(CompletionNavigationProvider::createParameterArrayTypeLookupElement) .collect(Collectors.toSet()) ); } }
Example #9
Source File: MethodMatcher.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable public MethodMatchParameter match() { if (!Symfony2ProjectComponent.isEnabled(this.psiElement)) { return null; } ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(this.psiElement); if (arrayCreationExpression == null) { return null; } PsiElement parameterList = arrayCreationExpression.getContext(); if (!(parameterList instanceof ParameterList)) { return null; } PsiElement methodParameters[] = ((ParameterList) parameterList).getParameters(); if (methodParameters.length < this.parameterIndex) { return null; } if (!(parameterList.getContext() instanceof MethodReference)) { return null; } MethodReference methodReference = (MethodReference) parameterList.getContext(); ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(arrayCreationExpression); if (currentIndex == null || currentIndex.getIndex() != this.parameterIndex) { return null; } CallToSignature matchedMethodSignature = this.isCallTo(methodReference); if(matchedMethodSignature == null) { return null; } return new MethodMatchParameter(matchedMethodSignature, currentIndex, methodParameters, methodReference); }
Example #10
Source File: ThemeUtil.java From idea-php-shopware-plugin with MIT License | 5 votes |
@NotNull public static PsiElementPattern.Capture<PsiElement> getJavascriptClassFieldPattern() { return PlatformPatterns.psiElement().withParent( PlatformPatterns.psiElement(StringLiteralExpression.class).withParent( PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent( PlatformPatterns.psiElement(ArrayCreationExpression.class).withParent( PlatformPatterns.psiElement(Field.class).withName("javascript") ) ) ) ); }
Example #11
Source File: ThemeUtil.java From idea-php-shopware-plugin with MIT License | 5 votes |
public static void collectThemeJsFieldReferences(@NotNull StringLiteralExpression element, @NotNull ThemeAssetVisitor visitor) { PsiElement arrayValue = element.getParent(); if(arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) { return; } PsiElement arrayCreation = arrayValue.getParent(); if(!(arrayCreation instanceof ArrayCreationExpression)) { return; } PsiElement classField = arrayCreation.getParent(); if(!(classField instanceof Field)) { return; } if(!"javascript".equals(((Field) classField).getName())) { return; } PhpClass phpClass = PsiTreeUtil.getParentOfType(classField, PhpClass.class); if(phpClass == null || !PhpElementsUtil.isInstanceOf(phpClass, "\\Shopware\\Components\\Theme")) { return; } visitThemeAssetsFile(phpClass, visitor); }
Example #12
Source File: RouteGroupUtil.java From idea-php-laravel-plugin with MIT License | 5 votes |
/** * 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 #13
Source File: ExtensionUtility.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Override public void visitElement(@NotNull PsiElement element) { if (PlatformPatterns.psiElement(StringLiteralExpression.class).withParent( PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withParent( PlatformPatterns.psiElement(ArrayHashElement.class).withParent( PlatformPatterns.psiElement(ArrayCreationExpression.class).withParent( PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent( PlatformPatterns.psiElement(ArrayHashElement.class).withFirstChild( PlatformPatterns.or( PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withText("'psr-4'"), PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withText("\"psr-4\"") ) ) ) ) ) ) ).accepts(element)) { if (ns == null) { ns = new ArrayList<>(); } String contents = ((StringLiteralExpression) element).getContents(); if (contents.contains("\\")) { contents = contents.replace("\\\\", "\\"); } if (contents.endsWith("\\")) { ns.add(contents); } ns.add((contents + "\\")); } super.visitElement(element); }
Example #14
Source File: RouteUtil.java From Thinkphp5-Plugin with MIT License | 5 votes |
public static Boolean isRoutePosition(PsiElement element) { PsiElement parent1 = element.getParent().getParent(); if (parent1 instanceof ArrayCreationExpression) { PsiElement parent2 = parent1.getParent().getParent().getParent().getParent(); if (parent2 instanceof PhpReturnImpl) { return true; } } return false; }
Example #15
Source File: ArrayReturnPsiRecursiveVisitor.java From Thinkphp5-Plugin with MIT License | 5 votes |
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 #16
Source File: TCAPatterns.java From idea-php-typo3-plugin with MIT License | 4 votes |
@Contract(pure = true) public static boolean isWizard(@NotNull ArrayCreationExpression expression) { return isWizard().accepts(expression); }
Example #17
Source File: ArrayReturnPsiRecursiveVisitor.java From idea-php-laravel-plugin with MIT License | 4 votes |
public void visitPhpReturn(PhpReturn phpReturn) { PsiElement arrayCreation = phpReturn.getFirstPsiChild(); if(arrayCreation instanceof ArrayCreationExpression) { collectConfigKeys((ArrayCreationExpression) arrayCreation, this.arrayKeyVisitor, fileNameWithoutExtension); } }
Example #18
Source File: ArrayReturnPsiRecursiveVisitor.java From idea-php-laravel-plugin with MIT License | 4 votes |
public static void collectConfigKeys(ArrayCreationExpression creationExpression, ArrayKeyVisitor arrayKeyVisitor, String configName) { collectConfigKeys(creationExpression, arrayKeyVisitor, Collections.singletonList(configName)); }
Example #19
Source File: MethodArgumentDroppedIndex.java From idea-php-typo3-plugin with MIT License | 4 votes |
@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; }; }
Example #20
Source File: ArrayReturnPsiRecursiveVisitor.java From Thinkphp5-Plugin with MIT License | 4 votes |
public static void collectConfigKeys(ArrayCreationExpression creationExpression, ArrayKeyVisitor arrayKeyVisitor, String configName) { collectConfigKeys(creationExpression, arrayKeyVisitor, Collections.singletonList(configName)); }
Example #21
Source File: ArrayReturnPsiRecursiveVisitor.java From Thinkphp5-Plugin with MIT License | 4 votes |
public void visitPhpReturn(PhpReturn phpReturn) { PsiElement arrayCreation = phpReturn.getFirstPsiChild(); if (arrayCreation instanceof ArrayCreationExpression) { collectConfigKeys((ArrayCreationExpression) arrayCreation, this.arrayKeyVisitor, fileNameWithoutExtension); } }
Example #22
Source File: TCAPatterns.java From idea-php-typo3-plugin with MIT License | 2 votes |
public static boolean hasArrayHashElement(@NotNull ArrayCreationExpression expression, @NotNull String arrayKey, String arrayValue) { return hasArrayHashElementPattern(arrayKey, arrayValue).accepts(expression); }
Example #23
Source File: TCAPatterns.java From idea-php-typo3-plugin with MIT License | 2 votes |
public static boolean hasArrayHashElement(@NotNull ArrayCreationExpression expression, @NotNull String arrayKey) { return hasArrayHashElementPattern(arrayKey, null).accepts(expression); }