com.intellij.psi.PsiElement Java Examples
The following examples show how to use
com.intellij.psi.PsiElement.
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 Project: consulo-csharp Author: consulo File: CSharpReferenceExpressionImplUtil.java License: Apache License 2.0 | 6 votes |
@Nullable public static CSharpCallArgumentListOwner findCallArgumentListOwner(ResolveToKind kind, CSharpReferenceExpression referenceExpression) { PsiElement parent = referenceExpression.getParent(); CSharpCallArgumentListOwner p = null; if(CSharpReferenceExpressionImplUtil.isConstructorKind(kind) || kind == ResolveToKind.PARAMETER) { p = PsiTreeUtil.getParentOfType(referenceExpression, CSharpCallArgumentListOwner.class); } else if(parent instanceof CSharpCallArgumentListOwner) { p = (CSharpCallArgumentListOwner) parent; } return p; }
Example #2
Source Project: consulo-csharp Author: consulo File: OverrideUtil.java License: Apache License 2.0 | 6 votes |
@Nonnull public static Collection<PsiElement> filterOverrideElements(@Nonnull PsiScopeProcessor processor, @Nonnull PsiElement scopeElement, @Nonnull Collection<PsiElement> psiElements, @Nonnull OverrideProcessor overrideProcessor) { if(psiElements.size() == 0) { return psiElements; } if(!ExecuteTargetUtil.canProcess(processor, ExecuteTarget.ELEMENT_GROUP, ExecuteTarget.EVENT, ExecuteTarget.PROPERTY)) { return CSharpResolveUtil.mergeGroupsToIterable(psiElements); } List<PsiElement> elements = CSharpResolveUtil.mergeGroupsToIterable(psiElements); return filterOverrideElements(scopeElement, elements, overrideProcessor); }
Example #3
Source Project: consulo Author: consulo File: HighlightManagerImpl.java License: Apache License 2.0 | 6 votes |
@Override public void addOccurrenceHighlights(@Nonnull Editor editor, @Nonnull PsiElement[] elements, @Nonnull TextAttributes attributes, boolean hideByTextChange, Collection<RangeHighlighter> outHighlighters) { if (elements.length == 0) return; int flags = HIDE_BY_ESCAPE; if (hideByTextChange) { flags |= HIDE_BY_TEXT_CHANGE; } Color scrollmarkColor = getScrollMarkColor(attributes); if (editor instanceof EditorWindow) { editor = ((EditorWindow)editor).getDelegate(); } for (PsiElement element : elements) { TextRange range = element.getTextRange(); range = InjectedLanguageManager.getInstance(myProject).injectedToHost(element, range); addOccurrenceHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, flags, outHighlighters, scrollmarkColor); } }
Example #4
Source Project: consulo Author: consulo File: DefaultChooseByNameItemProvider.java License: Apache License 2.0 | 6 votes |
private static boolean filterElements(@Nonnull ChooseByNameViewModel base, @Nonnull ProgressIndicator indicator, @Nullable PsiElement context, @Nullable Supplier<String[]> allNamesProducer, @Nonnull Processor<FoundItemDescriptor<?>> consumer, @Nonnull FindSymbolParameters parameters) { boolean everywhere = parameters.isSearchInLibraries(); String pattern = parameters.getCompletePattern(); if (base.getProject() != null) { base.getProject().putUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN, pattern); } String namePattern = getNamePattern(base, pattern); boolean preferStartMatches = !pattern.startsWith("*"); List<MatchResult> namesList = getSortedNamesForAllWildcards(base, parameters, indicator, allNamesProducer, namePattern, preferStartMatches); indicator.checkCanceled(); return processByNames(base, everywhere, indicator, context, consumer, preferStartMatches, namesList, parameters); }
Example #5
Source Project: buck Author: facebook File: BuckTestAtCursorAction.java License: Apache License 2.0 | 6 votes |
private void findTestAndDo(AnActionEvent anActionEvent, BiConsumer<PsiClass, PsiMethod> action) { PsiElement psiElement = anActionEvent.getData(CommonDataKeys.PSI_ELEMENT); PsiFile psiFile = anActionEvent.getData(LangDataKeys.PSI_FILE); if (psiElement == null) { Editor editor = anActionEvent.getData(CommonDataKeys.EDITOR); if (editor != null && psiFile != null) { psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset()); } } if (psiFile == null && psiElement != null) { psiFile = psiElement.getContainingFile(); } if (psiElement != null) { PsiElement testElement = findNearestTestElement(psiFile, psiElement); if (testElement instanceof PsiClass) { PsiClass psiClass = (PsiClass) testElement; action.accept(psiClass, null); return; } else if (testElement instanceof PsiMethod) { PsiMethod psiMethod = (PsiMethod) testElement; action.accept(psiMethod.getContainingClass(), psiMethod); return; } } action.accept(null, null); }
Example #6
Source Project: consulo Author: consulo File: ParameterInfoController.java License: Apache License 2.0 | 6 votes |
@Nullable public static <E extends PsiElement> E findArgumentList(PsiFile file, int offset, int lbraceOffset) { if (file == null) return null; ParameterInfoHandler[] handlers = ShowParameterInfoHandler.getHandlers(file.getProject(), PsiUtilCore.getLanguageAtOffset(file, offset), file.getViewProvider().getBaseLanguage()); if (handlers != null) { for (ParameterInfoHandler handler : handlers) { if (handler instanceof ParameterInfoHandlerWithTabActionSupport) { final ParameterInfoHandlerWithTabActionSupport parameterInfoHandler2 = (ParameterInfoHandlerWithTabActionSupport)handler; // please don't remove typecast in the following line; it's required to compile the code under old JDK 6 versions final E e = ParameterInfoUtils.findArgumentList(file, offset, lbraceOffset, parameterInfoHandler2); if (e != null) return e; } } } return null; }
Example #7
Source Project: antlr4-intellij-adaptor Author: antlr File: Trees.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** Find smallest subtree of t enclosing range startCharIndex..stopCharIndex * inclusively using postorder traversal. Recursive depth-first-search. */ public static PsiElement getRootOfSubtreeEnclosingRegion(PsiElement t, int startCharIndex, // inclusive int stopCharIndex) // inclusive { for (PsiElement c : t.getChildren()) { PsiElement sub = getRootOfSubtreeEnclosingRegion(c, startCharIndex, stopCharIndex); if ( sub!=null ) return sub; } IElementType elementType = t.getNode().getElementType(); if ( elementType instanceof RuleIElementType ) { TextRange r = t.getNode().getTextRange(); // is range fully contained in t? Note: jetbrains uses exclusive right end (use < not <=) if ( startCharIndex>=r.getStartOffset() && stopCharIndex<r.getEndOffset() ) { return t; } } return null; }
Example #8
Source Project: idea-php-typo3-plugin Author: cedricziel File: PhpElementsUtil.java License: MIT License | 6 votes |
@Nullable public static String extractArrayIndexFromValue(PsiElement element) { PsiElement arrayElement; if (element.getParent() instanceof StringLiteralExpression) { arrayElement = element.getParent().getParent().getParent(); } else { arrayElement = element.getParent().getParent(); } if (arrayElement instanceof ArrayHashElement) { ArrayHashElement arrayHashElement = (ArrayHashElement) arrayElement; return extractIndexFromArrayHash(arrayHashElement); } return null; }
Example #9
Source Project: idea-php-symfony2-plugin Author: Haehnchen File: TwigPattern.java License: MIT License | 6 votes |
public static ElementPattern<PsiElement> getSetVariablePattern() { // {% set count1 = "var" %} //noinspection unchecked return PlatformPatterns .psiElement(TwigTokenTypes.IDENTIFIER) .afterLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE) ), PlatformPatterns.psiElement(TwigTokenTypes.EQ) ) .withParent( PlatformPatterns.psiElement(TwigElementTypes.SET_TAG) ) .withLanguage(TwigLanguage.INSTANCE); }
Example #10
Source Project: intellij-haxe Author: HaxeFoundation File: HaxeTypeResolver.java License: Apache License 2.0 | 6 votes |
static private void checkMethod(PsiElement element, HaxeExpressionEvaluatorContext context) { if (!(element instanceof HaxeMethod)) return; final HaxeTypeTag typeTag = UsefulPsiTreeUtil.getChild(element, HaxeTypeTag.class); ResultHolder expectedType = SpecificTypeReference.getDynamic(element).createHolder(); if (typeTag == null) { final List<ReturnInfo> infos = context.getReturnInfos(); if (!infos.isEmpty()) { expectedType = infos.get(0).type; } } else { expectedType = getTypeFromTypeTag(typeTag, element); } if (expectedType == null) return; for (ReturnInfo retinfo : context.getReturnInfos()) { if (expectedType.canAssign(retinfo.type)) continue; context.addError( retinfo.element, "Can't return " + retinfo.type + ", expected " + expectedType.toStringWithoutConstant() ); } }
Example #11
Source Project: idea-php-toolbox Author: Haehnchen File: PhpArrayCallbackGotoCompletion.java License: MIT License | 6 votes |
/** * [$this, ''] * array($this, '') */ @NotNull @Override public PsiElementPattern.Capture<PsiElement> getPattern() { return PlatformPatterns.psiElement().withParent( PlatformPatterns.psiElement(StringLiteralExpression.class).withParent( PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).afterLeafSkipping( PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement().withText(",") ).afterSiblingSkipping( PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).withFirstNonWhitespaceChild( PlatformPatterns.psiElement(Variable.class) ).afterLeafSkipping( PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement().withText(PlatformPatterns.string().oneOf("[", "(")) ) ) ) ); }
Example #12
Source Project: idea-php-typo3-plugin Author: cedricziel File: TranslationReferenceTest.java License: MIT License | 6 votes |
public void testReferenceCanResolveDefinition() { PsiFile file = myFixture.configureByText(PhpFileType.INSTANCE, "<?php \n" + "\"LLL:EXT:foo/sample.xlf:sys_<caret>language.language_isocode.ab\";"); PsiElement elementAtCaret = file.findElementAt(myFixture.getCaretOffset()).getParent(); PsiReference[] references = elementAtCaret.getReferences(); for (PsiReference reference : references) { if (reference instanceof TranslationReference) { ResolveResult[] resolveResults = ((TranslationReference) reference).multiResolve(false); for (ResolveResult resolveResult : resolveResults) { assertInstanceOf(resolveResult.getElement(), XmlAttributeValue.class); return; } } } fail("TranslationReference could not be resolved"); }
Example #13
Source Project: NutzCodeInsight Author: threefish File: AbstractPsiElementNavigationHandler.java License: Apache License 2.0 | 6 votes |
@Override public void navigate(MouseEvent mouseEvent, PsiElement psiElement) { if (canNavigate(psiElement)) { final Project project = psiElement.getProject(); final List<PsiElement> psiElements = findReferences(psiElement); if (psiElements.size() == 1) { FileEditorManager.getInstance(project).openFile(PsiUtil.getVirtualFile(psiElements.get(0)), true); } else if (psiElements.size() > 1) { NavigationUtil.getPsiElementPopup(psiElements.toArray(new PsiElement[0]), title).show(new RelativePoint(mouseEvent)); } else { if (Objects.isNull(psiElements) || psiElements.size() <= 0) { Messages.showErrorDialog("没有找到这个调用的方法,请检查!", "错误提示"); } } } }
Example #14
Source Project: reasonml-idea-plugin Author: reasonml-editor File: ResolveInFunctorTest.java License: MIT License | 5 votes |
public void testRml_FileInclude() { configureCode("A.re", "module Make = (M:I) => { let a = 3; }; include Make({})"); configureCode("B.re", "let b = A.a<caret>;"); PsiElement e = myFixture.getElementAtCaret(); assertEquals("A.Make.a", ((PsiQualifiedElement) e.getParent()).getQualifiedName()); }
Example #15
Source Project: netbeans-mmd-plugin Author: raydac File: MMAnnotator.java License: Apache License 2.0 | 5 votes |
public void annotate(@Nonnull PsiElement element, @Nonnull AnnotationHolder holder) { if (!(element instanceof MMPsiElement)) { return; } final ASTNode keyNode = element.getNode(); highlightTokens(keyNode, holder, new MMHighlighter()); }
Example #16
Source Project: BashSupport Author: BashSupport File: BashAnnotator.java License: Apache License 2.0 | 5 votes |
private void annotateVarDef(BashVarDef bashVarDef, AnnotationHolder annotationHolder) { final PsiElement identifier = bashVarDef.findAssignmentWord(); if (identifier != null) { final Annotation annotation = annotationHolder.createInfoAnnotation(identifier, null); annotation.setTextAttributes(BashSyntaxHighlighter.VAR_DEF); } }
Example #17
Source Project: consulo Author: consulo File: StubBasedPsiElementBase.java License: Apache License 2.0 | 5 votes |
@Override public PsiElement getContext() { T stub = getStub(); if (stub != null) { if (!(stub instanceof PsiFileStub)) { return stub.getParentStub().getPsi(); } } return super.getContext(); }
Example #18
Source Project: consulo-csharp Author: consulo File: CSharpPreprocessorDefineImpl.java License: Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable @Override public PsiElement getVarElement() { return findChildByType(CSharpPreprocesorTokens.IDENTIFIER); }
Example #19
Source Project: consulo Author: consulo File: InspectionManagerBase.java License: Apache License 2.0 | 5 votes |
@Override @Nonnull public ProblemDescriptor createProblemDescriptor(@Nonnull PsiElement psiElement, @Nonnull String descriptionTemplate, LocalQuickFix[] fixes, @Nonnull ProblemHighlightType highlightType, boolean onTheFly, boolean isAfterEndOfLine) { return new ProblemDescriptorBase(psiElement, psiElement, descriptionTemplate, fixes, highlightType, isAfterEndOfLine, null, true, onTheFly); }
Example #20
Source Project: intellij-thrift Author: fkorotkov File: ThriftColorAnnotator.java License: Apache License 2.0 | 5 votes |
@Override public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof LeafPsiElement) { IElementType tokenType = ((LeafPsiElement)element).getElementType(); if (tokenType == ThriftTokenTypes.IDENTIFIER && ThriftUtils.getKeywords().contains(element.getText())) { annotateKeyword(element, holder); } } }
Example #21
Source Project: elm-plugin Author: durkiewicz File: ElmMainCompletionProvider.java License: MIT License | 5 votes |
private void addCompletionsAfterWhiteSpace(PsiElement element, CompletionResultSet resultSet) { if (isJustAfterModule(element)) { this.currentModuleProvider.addCompletions((ElmFile) element.getContainingFile(), resultSet); return; } char firstChar = element.getText().charAt(0); ElmFile file = (ElmFile) element.getContainingFile(); if (Character.isLowerCase(firstChar)) { this.valueProvider.addCompletions(file, resultSet); this.keywordsProvider.addCompletions(resultSet); } else if (Character.isUpperCase(firstChar)) { this.typeProvider.addCompletions(file, resultSet); this.moduleProvider.addCompletions(file, resultSet); } }
Example #22
Source Project: arma-intellij-plugin Author: kayler-renslow File: ArmaPluginUserData.java License: MIT License | 5 votes |
/** * Invokes {@link #parseAndGetConfigHeaderFiles(Module)} by first getting a {@link Module} instance for the given PsiElement. * * @return the root config file, or an empty list if couldn't locate a {@link Module} or couldn't be parsed */ @NotNull public List<HeaderFile> parseAndGetConfigHeaderFiles(@NotNull PsiElement elementFromModule) { ArmaPluginModuleData moduleData = getModuleData(elementFromModule); if (moduleData == null) { return Collections.emptyList(); } return doParseAndGetConfigHeaderFiles(moduleData); }
Example #23
Source Project: flutter-intellij Author: flutter File: FlutterUtils.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test if the given element is contained in a module with a pub root that declares a flutter dependency. */ public static boolean isInFlutterProject(@NotNull Project project, @NotNull PsiElement element) { final PsiFile file = element.getContainingFile(); if (file == null) { return false; } final PubRoot pubRoot = PubRootCache.getInstance(project).getRoot(file); if (pubRoot == null) { return false; } return pubRoot.declaresFlutter(); }
Example #24
Source Project: consulo Author: consulo File: HighlightLevelUtil.java License: Apache License 2.0 | 5 votes |
public static boolean shouldHighlight(@Nonnull PsiElement psiRoot) { final HighlightingSettingsPerFile component = HighlightingSettingsPerFile.getInstance(psiRoot.getProject()); if (component == null) return true; final FileHighlightingSetting settingForRoot = component.getHighlightingSettingForRoot(psiRoot); return settingForRoot != FileHighlightingSetting.SKIP_HIGHLIGHTING; }
Example #25
Source Project: ok-gradle Author: scana File: DependenciesModelImpl.java License: Apache License 2.0 | 5 votes |
/** * Returns {@code true} if {@code child} is a descendant of the {@code parent}, {@code false} otherwise. */ private static boolean isChildOfParent(@NotNull PsiElement child, @NotNull PsiElement parent) { List<PsiElement> childElements = Lists.newArrayList(parent); while (!childElements.isEmpty()) { PsiElement element = childElements.remove(0); if (element.equals(child)) { return true; } childElements.addAll(Arrays.asList(element.getChildren())); } return false; }
Example #26
Source Project: idea-php-symfony2-plugin Author: Haehnchen File: ControllerActionGotoRelatedCollectorParameter.java License: MIT License | 5 votes |
public PsiElement[] getParameterLists() { if(parameterLists != null) { return parameterLists; } return parameterLists = PsiTreeUtil.collectElements(method, psiElement -> psiElement.getParent() instanceof ParameterList ); }
Example #27
Source Project: lombok-intellij-plugin Author: mplushnikov File: OnXAnnotationHandler.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private static PsiNameValuePair findContainingNameValuePair(PsiElement highlightedElement) { PsiElement nameValuePair = highlightedElement; while (!(nameValuePair == null || nameValuePair instanceof PsiNameValuePair)) { nameValuePair = nameValuePair.getContext(); } return (PsiNameValuePair) nameValuePair; }
Example #28
Source Project: consulo-csharp Author: consulo File: CSharpExtractMethodDialog.java License: Apache License 2.0 | 5 votes |
public CSharpExtractMethodDialog(Project project, CSharpMethodDescriptor method, boolean allowDelegation, PsiElement defaultValueContext, @Nonnull Processor<DotNetLikeMethodDeclaration> processor) { super(project, method, allowDelegation, defaultValueContext); myProcessor = processor; setOKButtonText(CommonBundle.getOkButtonText()); setTitle("Extract Method"); getRefactorAction().putValue(Action.NAME, CommonBundle.getOkButtonText()); }
Example #29
Source Project: idea-php-symfony2-plugin Author: Haehnchen File: PhpClassServiceGotoDeclarationHandler.java License: MIT License | 5 votes |
@Nullable @Override public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int offset, Editor editor) { if(!Symfony2ProjectComponent.isEnabled(psiElement) || !PhpElementsUtil.getClassNamePattern().accepts(psiElement)) { return new PsiElement[0]; } return ServiceIndexUtil.findServiceDefinitions((PhpClass) psiElement.getContext()); }
Example #30
Source Project: consulo-csharp Author: consulo File: CSharpLightLikeMethodDeclarationBuilder.java License: Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable @Override public String getPresentableParentQName() { PsiElement parent = getParent(); if(parent instanceof DotNetQualifiedElement) { return ((DotNetQualifiedElement) parent).getPresentableQName(); } return myParentQName; }