com.intellij.psi.PsiNameIdentifierOwner Java Examples
The following examples show how to use
com.intellij.psi.PsiNameIdentifierOwner.
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: CSharpPsiUtilImpl.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction public static String getNameWithAt(@Nonnull PsiNameIdentifierOwner element) { PsiElement nameIdentifier = element.getNameIdentifier(); if(nameIdentifier == null) { return null; } if(!(nameIdentifier instanceof CSharpIdentifier)) { LOGGER.error("NameIdentifier is not 'CSharpIdentifier' element. Owner: " + element.getClass().getName()); return nameIdentifier.getText(); } String value = ((CSharpIdentifier) nameIdentifier).getValue(); if(value == null) { return null; } return value; }
Example #2
Source File: CS0542.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Nullable @Override public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetQualifiedElement element) { PsiElement parent = element.getParent(); if(!(parent instanceof CSharpTypeDeclaration) | !(element instanceof PsiNameIdentifierOwner) || element instanceof CSharpConstructorDeclaration || element instanceof CSharpConversionMethodDeclaration || element instanceof CSharpEnumConstantDeclaration) { return null; } if(Comparing.equal(element.getName(), ((CSharpTypeDeclaration) parent).getName())) { PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier(); if(nameIdentifier == null) { return null; } return newBuilder(nameIdentifier, element.getName()); } return null; }
Example #3
Source File: CS0539.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Nullable @Override public CompilerCheckBuilder checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetVirtualImplementOwner element) { PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier(); if(nameIdentifier == null) { return null; } final Pair<CSharpLikeMethodDeclarationImplUtil.ResolveVirtualImplementResult, PsiElement> resultPair = CSharpLikeMethodDeclarationImplUtil.resolveVirtualImplementation(element, element); switch(resultPair.getFirst()) { case CANT_HAVE: case FOUND: default: return null; case NOT_FOUND: return newBuilder(nameIdentifier, formatElement(element)); } }
Example #4
Source File: AnnotatorUtils.java From litho with Apache License 2.0 | 6 votes |
static void addError( AnnotationHolder holder, SpecModelValidationError error, List<IntentionAction> fixes) { PsiElement errorElement = (PsiElement) error.element; Annotation errorAnnotation = holder.createErrorAnnotation( Optional.of(errorElement) .filter(element -> element instanceof PsiClass || element instanceof PsiMethod) .map(PsiNameIdentifierOwner.class::cast) .map(PsiNameIdentifierOwner::getNameIdentifier) .orElse(errorElement), error.message); if (!fixes.isEmpty()) { for (IntentionAction fix : fixes) { errorAnnotation.registerFix(fix); } } }
Example #5
Source File: CSharpAnchorProvider.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @Override @RequiredReadAction public PsiElement getAnchor(@Nonnull PsiElement element) { if(element instanceof MsilElementWrapper || !element.isPhysical()) { return null; } if(element instanceof CSharpTypeDeclaration || element instanceof CSharpFieldDeclaration || element instanceof CSharpMethodDeclaration || element instanceof CSharpConstructorDeclaration || element instanceof CSharpIndexMethodDeclaration || //element instanceof CSharpConversionMethodDeclaration || element instanceof CSharpPropertyDeclaration || element instanceof CSharpEventDeclaration) { return ((PsiNameIdentifierOwner) element).getNameIdentifier(); } return null; }
Example #6
Source File: CS0708.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Nullable @Override public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetModifierListOwner element) { PsiElement parent = element.getParent(); if(parent instanceof DotNetTypeDeclaration && ((DotNetTypeDeclaration) parent).hasModifier(DotNetModifier.STATIC)) { if(CSharpPsiUtilImpl.isTypeLikeElement(element)) { return null; } if(!element.hasModifier(DotNetModifier.STATIC)) { PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier(); return newBuilder(ObjectUtil.notNull(nameIdentifier, element), formatElement(element)).addQuickFix(new AddModifierFix (DotNetModifier.STATIC, element)); } } return null; }
Example #7
Source File: IdentifierUtil.java From consulo with Apache License 2.0 | 6 votes |
@javax.annotation.Nullable @RequiredReadAction public static PsiElement getNameIdentifier(@Nonnull PsiElement element) { if (element instanceof PsiNameIdentifierOwner) { return ((PsiNameIdentifierOwner)element).getNameIdentifier(); } if (element.isPhysical() && element instanceof PsiNamedElement && element.getContainingFile() != null && element.getTextRange() != null) { // Quite hacky way to get name identifier. Depends on getTextOffset overriden properly. final PsiElement potentialIdentifier = element.findElementAt(element.getTextOffset() - element.getTextRange().getStartOffset()); if (potentialIdentifier != null && Comparing.equal(potentialIdentifier.getText(), ((PsiNamedElement)element).getName(), false)) { return potentialIdentifier; } } return null; }
Example #8
Source File: JSGraphQLEndpointStructureViewTreeElement.java From js-graphql-intellij-plugin with MIT License | 6 votes |
@Nullable @Override public String getPresentableText() { if(element instanceof JSGraphQLEndpointImportDeclaration) { return element.getText(); } final PsiNameIdentifierOwner identifier = PsiTreeUtil.getChildOfType(element, PsiNameIdentifierOwner.class); if (identifier != null) { return identifier.getText(); } final ASTNode astIdentifier = element.getNode().getFirstChildNode(); if (astIdentifier != null && astIdentifier.getElementType() == JSGraphQLEndpointTokenTypes.IDENTIFIER) { return astIdentifier.getText(); } if (element instanceof PsiFile) { return null; } return element.getText(); }
Example #9
Source File: PsiFileHelper.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull public static Collection<PsiNameIdentifierOwner> getExpressions(@NotNull PsiFile file, @Nullable String name) { Collection<PsiNameIdentifierOwner> result = new ArrayList<>(); if (name != null) { PsiElement element = file.getFirstChild(); while (element != null) { if (element instanceof PsiNameIdentifierOwner && name.equals(((PsiNameIdentifierOwner) element).getName())) { result.add((PsiNameIdentifierOwner) element); } element = element.getNextSibling(); } } return result; }
Example #10
Source File: JSGraphQLEndpointSpellcheckingStrategy.java From js-graphql-intellij-plugin with MIT License | 6 votes |
@NotNull @Override public Tokenizer getTokenizer(PsiElement element) { if (element instanceof PsiWhiteSpace) { return EMPTY_TOKENIZER; } if (element instanceof PsiNameIdentifierOwner) { return new PsiIdentifierOwnerTokenizer(); } if (element.getParent() instanceof PsiNameIdentifierOwner) { return EMPTY_TOKENIZER; } if (element.getNode().getElementType() == JSGraphQLEndpointTokenTypes.IDENTIFIER) { return IDENTIFIER_TOKENIZER; } if (element instanceof PsiComment) { if (SuppressionUtil.isSuppressionComment(element)) { return EMPTY_TOKENIZER; } return myCommentTokenizer; } return EMPTY_TOKENIZER; }
Example #11
Source File: ORLineMarkerProvider.java From reasonml-idea-plugin with MIT License | 6 votes |
private void extractRelatedExpressions(@Nullable PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo<?>> result, @NotNull FileBase containingFile) { if (element == null) { return; } FileBase psiRelatedFile = PsiFinder.getInstance(containingFile.getProject()).findRelatedFile(containingFile); if (psiRelatedFile != null) { Collection<PsiNameIdentifierOwner> expressions = psiRelatedFile.getExpressions(element.getText()); if (expressions.size() == 1) { PsiNameIdentifierOwner relatedElement = expressions.iterator().next(); PsiElement nameIdentifier = relatedElement.getNameIdentifier(); if (nameIdentifier != null) { String tooltip = GutterIconTooltipHelper .composeText(new PsiElement[]{psiRelatedFile}, "", "Implements method <b>" + nameIdentifier.getText() + "</b> in <b>{0}</b>"); result.add(NavigationGutterIconBuilder. create(containingFile.isInterface() ? ORIcons.IMPLEMENTED : ORIcons.IMPLEMENTING). setTooltipText(tooltip). setAlignment(GutterIconRenderer.Alignment.RIGHT). setTargets(Collections.singleton(nameIdentifier instanceof PsiLowerSymbol ? nameIdentifier.getFirstChild() : nameIdentifier)). createLineMarkerInfo(element)); } } } }
Example #12
Source File: ChangeSignatureAction.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static PsiElement findTargetMember(@Nullable PsiElement element) { if (element == null) return null; final ChangeSignatureHandler fileHandler = getChangeSignatureHandler(element.getLanguage()); if (fileHandler != null) { final PsiElement targetMember = fileHandler.findTargetMember(element); if (targetMember != null) return targetMember; } PsiReference reference = element.getReference(); if (reference == null && element instanceof PsiNameIdentifierOwner) { return element; } if (reference != null) { return reference.resolve(); } return null; }
Example #13
Source File: NamedElementDuplicateHandler.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static PsiElement findNameIdentifier(Editor editor, PsiFile file, TextRange toDuplicate) { int nonWs = CharArrayUtil.shiftForward(editor.getDocument().getCharsSequence(), toDuplicate.getStartOffset(), "\n\t "); PsiElement psi = file.findElementAt(nonWs); PsiElement named = null; while (psi != null) { TextRange range = psi.getTextRange(); if (range == null || psi instanceof PsiFile || !toDuplicate.contains(psi.getTextRange())) { break; } if (psi instanceof PsiNameIdentifierOwner) { named = ((PsiNameIdentifierOwner)psi).getNameIdentifier(); } psi = psi.getParent(); } return named; }
Example #14
Source File: BuildElementDescriptionProvider.java From intellij with Apache License 2.0 | 6 votes |
@Nullable @Override public String getElementDescription(PsiElement element, ElementDescriptionLocation location) { if (!(element instanceof BuildElement)) { return null; } if (location instanceof UsageViewLongNameLocation) { return ((BuildElement) element).getPresentableText(); } if (location instanceof UsageViewShortNameLocation) { if (element instanceof PsiNameIdentifierOwner) { // this is used by rename operations, so needs to be accurate return ((PsiNameIdentifierOwner) element).getName(); } if (element instanceof PsiFile) { return ((PsiFile) element).getName(); } return ((BuildElement) element).getPresentableText(); } return null; }
Example #15
Source File: FunctorTest.java From reasonml-idea-plugin with MIT License | 6 votes |
public void testWithConstraints() { Collection<PsiNameIdentifierOwner> expressions = expressions( parseCode("module Make = (M: Input) : (S with type t('a) = M.t('a) and type b = M.b) => {};")); assertEquals(1, expressions.size()); PsiFunctor f = (PsiFunctor) first(expressions); assertEquals("M: Input", first(f.getParameters()).getText()); assertEquals("S", f.getReturnType().getText()); List<PsiConstraint> constraints = new ArrayList<>(f.getConstraints()); assertEquals(2, constraints.size()); assertEquals("type t('a) = M.t('a)", constraints.get(0).getText()); assertEquals("type b = M.b", constraints.get(1).getText()); assertEquals("{}", f.getBinding().getText()); }
Example #16
Source File: GraphQLStructureViewTreeElement.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Nullable @Override public String getPresentableText() { if (element instanceof GraphQLSelectionSetOperationDefinition) { return "anonymous query"; // "{}" selection as root, which corresponds to anonymous query } if (element instanceof GraphQLInlineFragment) { String text = "... on"; GraphQLTypeCondition typeCondition = ((GraphQLInlineFragment) element).getTypeCondition(); if (typeCondition != null && typeCondition.getTypeName() != null) { text += " " + typeCondition.getTypeName().getName(); } return text; } if (element instanceof GraphQLNamedElement) { String name = ((GraphQLNamedElement) element).getName(); if (name == null && element instanceof GraphQLTypedOperationDefinition) { return "anonymous query"; // "query(args) {}" } return name; } if (element instanceof PsiNameIdentifierOwner) { final PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier(); if (nameIdentifier != null) { return nameIdentifier.getText(); } } return element.getText(); }
Example #17
Source File: CSharpMemberInplaceRenameHandler.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @Nonnull @RequiredReadAction protected MemberInplaceRenamer createMemberRenamer(@Nonnull PsiElement element, PsiNameIdentifierOwner elementToRename, Editor editor) { return new CSharpMemberInplaceRenamer(elementToRename, element, editor); }
Example #18
Source File: SampleElementRef.java From jetbrains-plugin-sample with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean isReferenceTo(PsiElement def) { String refName = myElement.getName(); // System.out.println(getClass().getSimpleName()+".isReferenceTo("+refName+"->"+def.getText()+")"); // sometimes def comes in pointing to ID node itself. depends on what you click on if ( def instanceof IdentifierPSINode && isDefSubtree(def.getParent()) ) { def = def.getParent(); } if ( isDefSubtree(def) ) { PsiElement id = ((PsiNameIdentifierOwner)def).getNameIdentifier(); String defName = id!=null ? id.getText() : null; return refName!=null && defName!=null && refName.equals(defName); } return false; }
Example #19
Source File: RelatedItemLineMarkerProvider.java From consulo with Apache License 2.0 | 5 votes |
public void collectNavigationMarkers(List<PsiElement> elements, Collection<? super RelatedItemLineMarkerInfo> result, boolean forNavigation) { //noinspection ForLoopReplaceableByForEach for (int i = 0, size = elements.size(); i < size; i++) { PsiElement element = elements.get(i); collectNavigationMarkers(element, result); if (forNavigation && element instanceof PsiNameIdentifierOwner) { PsiElement nameIdentifier = ((PsiNameIdentifierOwner)element).getNameIdentifier(); if (nameIdentifier != null && !elements.contains(nameIdentifier)) { collectNavigationMarkers(nameIdentifier, result); } } } }
Example #20
Source File: CSharpRefactoringUtil.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction public static void replaceNameIdentifier(PsiNameIdentifierOwner owner, String newName) { PsiElement nameIdentifier = owner.getNameIdentifier(); if(!(nameIdentifier instanceof CSharpIdentifier)) { return; } CSharpIdentifier newIdentifier = CSharpFileFactory.createIdentifier(owner.getProject(), newName); nameIdentifier.replace(newIdentifier); }
Example #21
Source File: CSharpSpellcheckingStrategy.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nonnull @Override public Tokenizer getTokenizer(PsiElement element) { if(element instanceof PsiNameIdentifierOwner) { return ourNameTokenizer; } return super.getTokenizer(element); }
Example #22
Source File: GenericNameNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 5 votes |
/** * Set name for a given element if it implements {@link PsiNameIdentifierOwner} and * {@link PsiNameIdentifierOwner#getNameIdentifier()} resolves to an instance of * {@link GenericNameNode}. */ public static PsiElement setName(PsiNameIdentifierOwner element, String name) { PsiElement nameIdentifier = element.getNameIdentifier(); if (nameIdentifier instanceof GenericNameNode) { GenericNameNode nameNode = (GenericNameNode) nameIdentifier; return nameNode.setName(name); } throw new IncorrectOperationException(OPERATION_NOT_SUPPORTED); }
Example #23
Source File: MemberInplaceRenameHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public InplaceRefactoring doRename(@Nonnull final PsiElement elementToRename, final Editor editor, final DataContext dataContext) { if (elementToRename instanceof PsiNameIdentifierOwner) { final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename); if (processor.isInplaceRenameSupported()) { final StartMarkAction startMarkAction = StartMarkAction.canStart(elementToRename.getProject()); if (startMarkAction == null || processor.substituteElementToRename(elementToRename, editor) == elementToRename) { processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() { @Override public void pass(PsiElement element) { final MemberInplaceRenamer renamer = createMemberRenamer(element, (PsiNameIdentifierOwner)elementToRename, editor); boolean startedRename = renamer.performInplaceRename(); if (!startedRename) { performDialogRename(elementToRename, editor, dataContext); } } }); return null; } else { final InplaceRefactoring inplaceRefactoring = editor.getUserData(InplaceRefactoring.INPLACE_RENAMER); if (inplaceRefactoring != null && inplaceRefactoring.getClass() == MemberInplaceRenamer.class) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(editor)); if (templateState != null) { templateState.gotoEnd(true); } } } } } performDialogRename(elementToRename, editor, dataContext); return null; }
Example #24
Source File: LSPRenameHandler.java From lsp4intellij with Apache License 2.0 | 5 votes |
private InplaceRefactoring doRename(PsiElement elementToRename, Editor editor) { if (elementToRename instanceof PsiNameIdentifierOwner) { RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename); if (processor.isInplaceRenameSupported()) { StartMarkAction startMarkAction = StartMarkAction.canStart(elementToRename.getProject()); if (startMarkAction == null || (processor.substituteElementToRename(elementToRename, editor) == elementToRename)) { processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() { @Override public void pass(PsiElement element) { MemberInplaceRenamer renamer = createMemberRenamer(element, (PsiNameIdentifierOwner) elementToRename, editor); boolean startedRename = renamer.performInplaceRename(); if (!startedRename) { performDialogRename(editor); } } }); return null; } } else { InplaceRefactoring inplaceRefactoring = editor.getUserData(InplaceRefactoring.INPLACE_RENAMER); if ((inplaceRefactoring instanceof MemberInplaceRenamer)) { TemplateState templateState = TemplateManagerImpl .getTemplateState(InjectedLanguageUtil.getTopLevelEditor(editor)); if (templateState != null) { templateState.gotoEnd(true); } } } } performDialogRename(editor); return null; }
Example #25
Source File: FunctionParsingTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testComplexParams() { Collection<PsiNameIdentifierOwner> expressions = expressions(parseCode("let resolve_morphism env ?(fnewt=fun x -> x) args' (b,cstr) = let x = 1")); assertSize(1, expressions); PsiLet let = (PsiLet) first(expressions); assertTrue(let.isFunction()); assertSize(4, let.getFunction().getParameters()); assertEquals("let x = 1", let.getFunction().getBody().getText()); }
Example #26
Source File: FunctorTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testFunctorInstanciationChaining() { PsiFile file = parseCode("module KeyTable = Hashtbl.Make(KeyHash)\ntype infos"); List<PsiNameIdentifierOwner> expressions = new ArrayList<>(expressions(file)); assertEquals(2, expressions.size()); PsiInnerModule module = (PsiInnerModule) expressions.get(0); assertNull(module.getBody()); PsiFunctorCall call = PsiTreeUtil.findChildOfType(module, PsiFunctorCall.class); assertNotNull(call); assertEquals("Hashtbl.Make(KeyHash)", call.getText()); }
Example #27
Source File: FunctorTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testWithConstraints() { Collection<PsiNameIdentifierOwner> expressions = expressions(parseCode("module Make (M: Input) : S with type +'a t = 'a M.t and type b = M.b = struct end")); assertEquals(1, expressions.size()); PsiFunctor f = (PsiFunctor) first(expressions); assertEquals("M: Input", first(f.getParameters()).getText()); assertEquals("S", f.getReturnType().getText()); List<PsiConstraint> constraints = new ArrayList<>(f.getConstraints()); assertEquals(2, constraints.size()); assertEquals("type +'a t = 'a M.t", constraints.get(0).getText()); assertEquals("type b = M.b", constraints.get(1).getText()); assertEquals("struct end", f.getBinding().getText()); }
Example #28
Source File: FunctorTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testBasic() { PsiNameIdentifierOwner e = first(expressions(parseCode("module Make (M:Def) : S = struct end"))); PsiFunctor f = (PsiFunctor) e; assertEquals("struct end", f.getBinding().getText()); assertEquals("S", f.getReturnType().getText()); }
Example #29
Source File: CSharpTupleTypeRef.java From consulo-csharp with Apache License 2.0 | 5 votes |
public CSharpTupleTypeRef(PsiElement scope, DotNetTypeRef[] typeRefs, @Nonnull PsiNameIdentifierOwner[] variables) { super(scope.getProject()); myScope = scope; myTypeRefs = typeRefs; myVariables = variables; }
Example #30
Source File: PolyVariantTest.java From reasonml-idea-plugin with MIT License | 5 votes |
public void testPatternMatchConstant() { PsiFile psiFile = parseCode("let unwrapValue = function " + " | `String s -> toJsUnsafe s " + " | `bool b -> toJsUnsafe (Js.Boolean.to_js_boolean b)"); Collection<PsiNameIdentifierOwner> expressions = expressions(psiFile); assertEquals(1, expressions.size()); Collection<PsiPatternMatch> matches = PsiTreeUtil.findChildrenOfType(first(expressions), PsiPatternMatch.class); assertEquals(2, matches.size()); }