@NotNull private List<PropTypeBean> findPropsNameListWithIdentityReference(String identity, PsiElement psiElement){ return PsiTreeUtil.findChildrenOfType(psiElement, LeafPsiElement.class) .stream() .filter(o -> o.getText().equals(identity)) .filter(o -> o.getElementType().toString().equals("JS:IDENTIFIER")) .filter(o -> { if(o.getParent() instanceof JSReferenceExpressionImpl){ JSReferenceExpressionImpl parent = (JSReferenceExpressionImpl) o.getParent(); if(parent.getTreeNext()!=null && parent.getTreeNext().getElementType().toString().equals("JS:DOT") &&parent.getTreeNext().getTreeNext()!=null){ return true; } } return false; }) .map(o -> ((JSReferenceExpressionImpl)o.getParent()).getTreeNext().getTreeNext().getText()) .distinct() .map(o -> new PropTypeBean(o,"any", false)) .collect(Collectors.toList()); }
private Map<Integer, CsvColumnInfo<PsiElement>> createColumnInfoMap(CsvFile csvFile) { Map<Integer, CsvColumnInfo<PsiElement>> columnInfoMap = new HashMap<>(); CsvRecord[] records = PsiTreeUtil.getChildrenOfType(csvFile, CsvRecord.class); int row = 0; for (CsvRecord record : records) { int column = 0; for (CsvField field : record.getFieldList()) { Integer length = field.getTextLength(); if (!columnInfoMap.containsKey(column)) { columnInfoMap.put(column, new CsvColumnInfo(column, length)); } else if (columnInfoMap.get(column).getMaxLength() < length) { columnInfoMap.get(column).setMaxLength(length); } columnInfoMap.get(column).addElement(field, row); ++column; } ++row; } return columnInfoMap; }
@Override public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) { MethodReference reference = PsiTreeUtil.getParentOfType(position, MethodReference.class); if (reference != null && reference.getName() != null && reference.getName().equals("t") && reference.getClassReference() instanceof ClassReference) { ClassReference classReference = (ClassReference) reference.getClassReference(); if (classReference == null || classReference.getName() == null || !classReference.getName().equals("Yii")) { return false; } if (typeChar == '\'' || typeChar == '"') { if (position instanceof LeafPsiElement && (position.getText().equals("$category") || position.getText().equals("$message"))) { return true; } if (position.getNextSibling() instanceof ParameterList) { return true; } } } return false; }
@NotNull public static List<AppleScriptComponent> getNamedSubComponentsFor(@NotNull AppleScriptScriptObject script) { List<AppleScriptComponent> result = new ArrayList<>(); AppleScriptScriptBody scriptBody = script.getScriptBody(); AppleScriptComponent[] namedComponents = PsiTreeUtil.getChildrenOfType(scriptBody, AppleScriptComponent.class); AppleScriptAssignmentStatement[] varsCreations = PsiTreeUtil.getChildrenOfType(scriptBody, AppleScriptAssignmentStatement.class); AppleScriptVarDeclarationList[] varsDeclarations = PsiTreeUtil.getChildrenOfType(scriptBody, AppleScriptVarDeclarationList.class); if (namedComponents != null) { result.addAll(Arrays.asList(namedComponents)); } if (varsCreations != null) { for (AppleScriptAssignmentStatement variable : varsCreations) { result.addAll(variable.getTargets()); } } if (varsDeclarations != null) { for (AppleScriptVarDeclarationList declarationList : varsDeclarations) { AppleScriptComponent[] vars = PsiTreeUtil.getChildrenOfType(declarationList, AppleScriptComponent.class); if (vars != null) { result.addAll(Arrays.asList(vars)); } } } return result; }
public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue( @NotNull final PsiElement element, @NotNull final Class<? extends T> domTagClass, @NotNull final Function<T, GenericAttributeValue<V>> domGetter ) { final DomManager domManager = DomManager.getDomManager(element.getProject()); if (!(element instanceof XmlElement)) { return null; } final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false); if (xmlAttribute == null) { return null; } final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false); DomElement domParentTag = domManager.getDomElement(xmlParentTag); return Optional.ofNullable(domParentTag) .map(o -> ObjectUtils.tryCast(o, domTagClass)) .map(domGetter) .filter(val -> val == domManager.getDomElement(xmlAttribute)) .orElse(null); }
public static PsiClass getContainingClass( PsiElement element ) { final PsiClass psiClass = PsiTreeUtil.getParentOfType( element, PsiClass.class, false ); if( psiClass == null ) { final PsiFile containingFile = element.getContainingFile(); if( containingFile instanceof PsiClassOwner ) { final PsiClass[] classes = ((PsiClassOwner)containingFile).getClasses(); if( classes.length == 1 ) { return classes[0]; } } } return psiClass; }
public static String getClassName(@NotNull PsiElement element) { ParameterList parameterList = PsiTreeUtil.getParentOfType(element, ParameterList.class); if (parameterList == null) { return null; } MethodReference methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class); if (methodReference == null) { return null; } Variable variableBeingCalledOn = PsiTreeUtil.findChildOfType(methodReference, Variable.class); if (variableBeingCalledOn != null && variableBeingCalledOn.getInferredType() != null) { PhpType inferredType = variableBeingCalledOn.getInferredType(); return inferredType.toString(); } ClassReference classReference = PsiTreeUtil.getChildOfType(methodReference, ClassReference.class); return extractFqnFromClassReference(methodReference, classReference); }
@Nullable @Contract("null -> null") protected ImpexHeaderTypeName getHeaderTypeNamePsiElementOfAttribute(@Nullable final PsiElement headerAttributePsiElement) { if (null == headerAttributePsiElement || null == headerAttributePsiElement.getNode()) { return null; } final ImpexHeaderLine impexHeaderLine = PsiTreeUtil.getParentOfType( headerAttributePsiElement, ImpexHeaderLine.class ); if (null == impexHeaderLine) { return null; } final ImpexFullHeaderType impexFullHeaderType = impexHeaderLine.getFullHeaderType(); return null == impexFullHeaderType ? null : impexFullHeaderType.getHeaderTypeName(); }
@Override public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) { if (element instanceof PsiModuleName) { element = element.getParent(); PsiElement previousElement = element == null ? null : PsiTreeUtil.prevVisibleLeaf(element); if (previousElement instanceof PsiComment) { StringBuilder sb = new StringBuilder(); sb.append(previousElement.getText()); return sb.toString(); } } return super.generateDoc(element, originalElement); }
private boolean isCallResultUsed(PsiMethodCallExpression call) { if (hasChainedMethodCall(call)) { return true; } else if (getBoundVariable(call, true) != null) { // TODO: Check that variable is actually used return true; } else if (PsiTreeUtil.getParentOfType(call, PsiReturnStatement.class) != null) { return true; } else if (PsiTreeUtil.getParentOfType(call, PsiMethodCallExpression.class) != null) { return true; } return false; }
@Nullable ES6ImportDeclaration getReactImportDeclaration(PsiFile file){ return PsiTreeUtil.findChildrenOfType(file, ES6FromClause.class) .stream() .filter(o -> o.getText().contains("\'react\'")) .filter(o -> o.getParent() instanceof ES6ImportDeclaration) .map(o -> (ES6ImportDeclaration) o.getParent()) .findFirst() .orElse(null); }
@Override protected void setProcessParameters(Project project, ApplicationConfiguration configuration, Module module, @NotNull VirtualFile testsFile) { configuration.setMainClassName(EduIntelliJNames.TEST_RUNNER_CLASS); configuration.setModule(module); PsiFile psiFile = PsiManager.getInstance(project).findFile(testsFile); Collection<KtClass> ktClasses = PsiTreeUtil.findChildrenOfType(psiFile, KtClass.class); for (KtClass ktClass : ktClasses) { String name = ktClass.getName(); configuration.setProgramParameters(name); } }
@NotNull @Override protected ResolveResult[] resolveInner(boolean incompleteCode, @NotNull PsiFile containingFile) { final AppleScriptResolveProcessor resolveProcessor = new AppleScriptResolveProcessor(getHandlerSelector()); PsiTreeUtil.treeWalkUp(resolveProcessor, AbstractAppleScriptHandlerCall.this, null, ResolveState.initial()); final List<PsiElement> results = new ArrayList<>(); results.add(resolveProcessor.getResult()); return AppleScriptResolveUtil.toCandidateInfoArray(results); }
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { PsiElement element = this; final AppleScriptIdentifier identifier = PsiTreeUtil.getChildOfType(element, AppleScriptIdentifier.class); final AppleScriptIdentifier identifierNew = AppleScriptPsiElementFactory.createIdentifierFromText(getProject(), newElementName); if (identifierNew != null && identifier != null) { element.getNode().replaceChild(identifier.getNode(), identifierNew.getNode()); } return this; }
@NotNull @Override public DataIndexer<String, Void, FileContent> getIndexer() { return fileContent -> { final Map<String, Void> map = new THashMap<>(); /* ignore file if its' structure is not as expected */ final PhpReturn returnExpression = PsiTreeUtil.findChildOfType(fileContent.getPsiFile(), PhpReturn.class); final PsiElement argument = null == returnExpression ? null : returnExpression.getArgument(); if (!(argument instanceof ArrayCreationExpression)) { return map; } /* extract translations from the file */ for (ArrayHashElement item : ((ArrayCreationExpression) argument).getHashElements()) { final PhpPsiElement key = item.getKey(); if (key instanceof StringLiteralExpression) { final StringLiteralExpression literal = (StringLiteralExpression) key; final String message = literal.getContents(); if (message.length() > 0) { map.putIfAbsent(PhpStringUtil.unescapeText(message, literal.isSingleQuote()), null); } } } return map; }; }
@Nullable @Override public PsiElement resolve() { PsiElement parent = PsiTreeUtil.getParentOfType(myElement, PsiModule.class, PsiOpen.class); // If name is used in a module definition, it's already the reference if (parent instanceof PsiModule && ((PsiModule) parent).getNameIdentifier() == myElement) { return null; } Project project = myElement.getProject(); // In open expression, name resolve to a file if (parent instanceof PsiOpen) { PsiFile file = RmlPsiUtil.findFileModule(project, m_referenceName); if (file != null) { return file; } } // No parent found, try to find the expression in current file PsiFile containingFile = myElement.getContainingFile(); PsiModule module = ((FileBase) containingFile).getModule(m_referenceName); if (module != null) { return module.getNameIdentifier(); } // No parent found, find the corresponding file PsiFile fileModule = RmlPsiUtil.findFileModule(project, m_referenceName); if (fileModule != null) { return fileModule; } return null; }
@NotNull @Override public DataIndexer<String, Void, FileContent> getIndexer() { return inputData -> { Map<String, Void> map = new HashMap<>(); JsonFile jsonFile = (JsonFile)inputData.getPsiFile(); if (!Settings.isEnabled(jsonFile.getProject())) { return map; } JsonObject jsonObject = PsiTreeUtil.getChildOfType(jsonFile, JsonObject.class); if (jsonObject == null) { return map; } ComposerPackageModel composerObject = new ComposerPackageModelImpl(jsonObject); String type = composerObject.getType(); if (type == null) { return map; } if (!type.startsWith("magento2-")) { return map; } String name = composerObject.getName(); if (name != null) { map.put(name, null); } return map; }; }
private PsiClass getPsiClassFromContext(AnActionEvent e) { PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); Editor editor = e.getData(PlatformDataKeys.EDITOR); // psiFile.getViewProvider().getVirtualFile() if (psiFile == null || editor == null) { return null; } int offset = editor.getCaretModel().getOffset(); PsiElement element = psiFile.findElementAt(offset); return PsiTreeUtil.getParentOfType(element, PsiClass.class); }
private PsiClass getPsiClassFromContext(AnActionEvent e) { PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); Editor editor = e.getData(PlatformDataKeys.EDITOR); if (psiFile == null || editor == null) { return null; } int offset = editor.getCaretModel().getOffset(); PsiElement element = psiFile.findElementAt(offset); return PsiTreeUtil.getParentOfType(element, PsiClass.class); }
@Nullable @Contract(pure = true) public static PsiElement getHeaderForValueGroup(@Nullable final ImpexValueGroup valueGroup) { if (null == valueGroup) { return null; } final int columnNumber = ImpexPsiUtils.getColumnNumberForValueGroup(valueGroup); if (columnNumber < 0) { return null; } final ImpexValueLine impexValueLine = PsiTreeUtil.getParentOfType(valueGroup, ImpexValueLine.class); if (null == impexValueLine) { return null; } if (prevElementIsUserRightsMacros(impexValueLine)) { return null; } final ImpexHeaderLine impexHeaderLine = PsiTreeUtil.getPrevSiblingOfType(impexValueLine, ImpexHeaderLine.class); if (null == impexHeaderLine) { return null; } final ImpexFullHeaderParameter header = ImpexPsiUtils.getImpexFullHeaderParameterFromHeaderLineByNumber( columnNumber, impexHeaderLine ); if (null == header) { return ImpexPsiUtils.getHeaderParametersSeparatorFromHeaderLineByNumber(columnNumber, impexHeaderLine); } else { return header; } }
@NotNull public static List<PsiModule> findModules(@NotNull Project project) { ArrayList<PsiModule> result = new ArrayList<>(); Collection<VirtualFile> virtualFiles = FilenameIndex.getAllFilesByExt(project, RmlFileType.INSTANCE.getDefaultExtension()); for (VirtualFile virtualFile : virtualFiles) { PsiFile file = PsiManager.getInstance(project).findFile(virtualFile); PsiModule[] modules = PsiTreeUtil.getChildrenOfType(file, PsiModule.class); if (modules != null) { result.addAll(Arrays.asList(modules)); } } return result; }
@Contract(pure = true) private boolean isStartOfValueLine(@Nullable final ASTNode currentNode) { return null != currentNode && PsiTreeUtil.findChildOfType( currentNode.getTreeParent().getPsi(), ImpexValueGroup.class ) == currentNode.getPsi(); }
private void migrateColorToIntegerType(@NotNull PsiFile sketchFile, PsiElementFactory elementFactory) { Collection<PsiTypeElement> typeElementsInFile = PsiTreeUtil.findChildrenOfType(sketchFile, PsiTypeElement.class); for (PsiTypeElement typeElement : typeElementsInFile) { boolean isProcessingColorType = typeElement.getType().equalsToText("color"); if (isProcessingColorType) { PsiTypeElement integerType = elementFactory.createTypeElementFromText("int", null); typeElement.replace(integerType); } } }
@Override @NotNull public List<ModuleTerm> getTermList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, ModuleTerm.class); }
@Override @NotNull public List<AppleScriptExpression> getExpressionList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptExpression.class); }
@Override @NotNull public List<AppleScriptRelativeReference> getRelativeReferenceList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptRelativeReference.class); }
@Override @NotNull public List<AppleScriptExitStatement> getExitStatementList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptExitStatement.class); }
@Override @NotNull public List<ImpexValueGroup> getValueGroupList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, ImpexValueGroup.class); }
@Override @NotNull public List<AppleScriptTargetVariable> getTargetVariableList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptTargetVariable.class); }
@Override @NotNull public List<AppleScriptApplicationReference> getApplicationReferenceList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptApplicationReference.class); }
@Override @NotNull public List<AppleScriptNameReference> getNameReferenceList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptNameReference.class); }
@Override @NotNull public List<AppleScriptIgnoringStatement> getIgnoringStatementList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptIgnoringStatement.class); }
@Override @NotNull public List<AppleScriptBuiltInClassIdentifierPlural> getBuiltInClassIdentifierPluralList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptBuiltInClassIdentifierPlural.class); }
@Override @NotNull public List<PrologPredicateSpec> getPredicateSpecList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, PrologPredicateSpec.class); }
@Override @NotNull public List<AppleScriptIndexReferenceClassForm> getIndexReferenceClassFormList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptIndexReferenceClassForm.class); }
@Override @NotNull public List<ImpexModifiers> getModifiersList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, ImpexModifiers.class); }
@Override @NotNull public List<AppleScriptIfSimpleStatement> getIfSimpleStatementList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptIfSimpleStatement.class); }
@Override @NotNull public List<AppleScriptMiddleElemReference> getMiddleElemReferenceList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, AppleScriptMiddleElemReference.class); }