Java Code Examples for com.intellij.psi.util.PsiUtilCore#getElementType()
The following examples show how to use
com.intellij.psi.util.PsiUtilCore#getElementType() .
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: CSharpHighlightVisitor.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override public void visitElement(PsiElement element) { ProgressIndicatorProvider.checkCanceled(); IElementType elementType = PsiUtilCore.getElementType(element); if(CSharpSoftTokens.ALL.contains(elementType)) { myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(CSharpHighlightKey.SOFT_KEYWORD).create()); } else if(elementType == CSharpTokens.NON_ACTIVE_SYMBOL || elementType == CSharpPreprocessorElements.DISABLED_PREPROCESSOR_DIRECTIVE) { if(myDocument == null) { return; } int lineNumber = myDocument.getLineNumber(element.getTextOffset()); if(!myProcessedLines.contains(lineNumber)) { myProcessedLines.add(lineNumber); TextRange textRange = new TextRange(myDocument.getLineStartOffset(lineNumber), myDocument.getLineEndOffset(lineNumber)); myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(textRange).textAttributes(CSharpHighlightKey.DISABLED_BLOCK).create()); } } }
Example 2
Source File: CSharpDeclarationMover.java From consulo-csharp with Apache License 2.0 | 6 votes |
private PsiElement afterEnumConstantsPosition(final CSharpTypeDeclaration aClass) { DotNetNamedElement[] fields = aClass.getMembers(); for(int i = fields.length - 1; i >= 0; i--) { DotNetNamedElement field = fields[i]; if(field instanceof CSharpEnumConstantDeclaration) { PsiElement anchor = firstNonWhiteElement(field.getNextSibling(), true); if(!(anchor != null && (PsiUtilCore.getElementType(anchor) == CSharpTokens.SEMICOLON))) { anchor = field; myEnumToInsertSemicolonAfter = (CSharpEnumConstantDeclaration) field; } return anchor; } } // no enum constants at all ? return aClass.getLeftBrace(); }
Example 3
Source File: CSharpCatchStatementImpl.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction public void deleteVariable() { CSharpLocalVariable variable = getVariable(); if(variable == null) { return; } PsiElement lparElement = variable.getPrevSibling(); PsiElement rparElement = variable.getNextSibling(); ((CSharpLocalVariableImpl) variable).deleteInternal(); if(PsiUtilCore.getElementType(lparElement) == CSharpTokens.LPAR) { lparElement.delete(); } if(PsiUtilCore.getElementType(rparElement) == CSharpTokens.RPAR) { rparElement.delete(); } }
Example 4
Source File: BashPsiUtils.java From BashSupport with Apache License 2.0 | 6 votes |
public static PsiElement findNextSibling(PsiElement start, IElementType ignoreType) { if (start == null) { return null; } PsiElement current = start.getNextSibling(); while (current != null) { if (ignoreType != PsiUtilCore.getElementType(current)) { return current; } current = current.getNextSibling(); } return null; }
Example 5
Source File: CS0509.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Nullable @Override public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetType element) { PsiElement parent = element.getParent(); if(parent instanceof DotNetTypeList && PsiUtilCore.getElementType(parent) == CSharpElements.EXTENDS_LIST) { PsiElement superParent = parent.getParent(); if(superParent instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) superParent).isEnum()) { return null; } PsiElement psiElement = element.toTypeRef().resolve().getElement(); if(psiElement instanceof CSharpTypeDeclaration) { if(((CSharpTypeDeclaration) psiElement).hasModifier(DotNetModifier.SEALED)) { return newBuilder(element, formatElement(parent.getParent()), ((CSharpTypeDeclaration) psiElement).getVmQName()); } } } return null; }
Example 6
Source File: CSharpGotoDeclarationHandler.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable @Override @RequiredReadAction public PsiElement getGotoDeclarationTarget(PsiElement psiElement, Editor editor) { IElementType elementType = PsiUtilCore.getElementType(psiElement); if(elementType == CSharpSoftTokens.VAR_KEYWORD) { PsiElement maybeType = psiElement.getParent(); if(maybeType instanceof CSharpNativeType) { PsiElement maybeVar = maybeType.getParent(); if(maybeVar instanceof DotNetVariable) { DotNetTypeRef ref = ((DotNetVariable) maybeVar).toTypeRef(true); return ref.resolve().getElement(); } } } else if(elementType == CSharpTokens.DARROW) { if(psiElement.getParent() instanceof CSharpLambdaExpressionImpl) { CSharpLambdaResolveResult typeRef = CSharpLambdaExpressionImplUtil.resolveLeftLambdaTypeRef(psiElement.getParent()); if(typeRef != null) { PsiElement element = typeRef.getElement(); return element != null ? element.getNavigationElement() : null; } } } return null; }
Example 7
Source File: CSharpParameterInfoHandler.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable private static CSharpCallArgumentListOwner resolveCallArgumentListOwner(@Nullable PsiElement place) { if(place == null) { return null; } boolean isDelegateKeyword = PsiUtilCore.getElementType(place) == CSharpTokens.DELEGATE_KEYWORD; DotNetElement element; // if we targeted delegate keyword = do not try to search delegate expression if(isDelegateKeyword) { element = PsiTreeUtil.getParentOfType(place, CSharpCallArgumentListOwner.class, CSharpLambdaExpressionImpl.class); } else { element = PsiTreeUtil.getParentOfType(place, CSharpCallArgumentListOwner.class, CSharpLambdaExpressionImpl.class, CSharpDelegateExpressionImpl.class); } if(element instanceof CSharpCallArgumentListOwner) { return (CSharpCallArgumentListOwner) element; } return null; }
Example 8
Source File: CSharpLineMarkerUtil.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable public static PsiElement getParentIfIsIdentifier(@Nonnull PsiElement element) { IElementType elementType = PsiUtilCore.getElementType(element); if(elementType == CSharpTokens.IDENTIFIER && element.getParent() instanceof CSharpIdentifier) { return element.getParent().getParent(); } return null; }
Example 9
Source File: CS1030.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable @Override public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull CSharpPreprocessorWarningImpl element) { IElementType elementType = PsiUtilCore.getElementType(element.getParent()); if(elementType == CSharpPreprocessorElements.DISABLED_PREPROCESSOR_DIRECTIVE) { return null; } return newBuilder(element).setText(element.getText()); }
Example 10
Source File: LambdaToDelegateExpressionFix.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredReadAction public boolean isAvailable(@Nonnull Project project, Editor editor, @Nonnull PsiElement element) { IElementType elementType = PsiUtilCore.getElementType(element); if(elementType == CSharpTokens.DARROW) { CSharpLambdaExpressionImpl lambdaExpression = PsiTreeUtil.getParentOfType(element, CSharpLambdaExpressionImpl.class); return lambdaExpression != null && lambdaExpression.toTypeRef(true) != DotNetTypeRef.ERROR_TYPE; } return false; }
Example 11
Source File: CS1029.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable @Override public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull CSharpPreprocessorErrorImpl element) { IElementType elementType = PsiUtilCore.getElementType(element.getParent()); if(elementType == CSharpPreprocessorElements.DISABLED_PREPROCESSOR_DIRECTIVE) { return null; } return newBuilder(element).setText(element.getText()); }
Example 12
Source File: CSharpOutRefVariableExpressionImpl.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nonnull public CSharpRefTypeRef.Type getType() { PsiElement element = findNotNullChildByFilter(CSharpOutRefWrapExpressionImpl.ourStartTypes); IElementType type = PsiUtilCore.getElementType(element); if(type == CSharpTokens.REF_KEYWORD) { return CSharpRefTypeRef.Type.ref; } else { return CSharpRefTypeRef.Type.out; } }
Example 13
Source File: CSharpMethodDeclarationImpl.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable @Override public IElementType getOperatorElementType() { CSharpMethodDeclStub stub = getGreenStub(); if(stub != null) { return stub.getOperator(); } PsiElement element = findChildByType(CSharpTokenSets.OVERLOADING_OPERATORS); return PsiUtilCore.getElementType(element); }
Example 14
Source File: SimpleExpressionsImpl.java From BashSupport with Apache License 2.0 | 5 votes |
public LiteralType literalType() { if (literalType == null) { //no other lock is used in the callees, it's safe to synchronize around the whole calculation synchronized (stateLock) { if (literalType == null) { LiteralType newType = LiteralType.Other; PsiElement child = getFirstChild(); if (child != null && BashTokenTypes.arithmeticAdditionOps.contains(PsiUtilCore.getElementType(child))) { //ignore prefix operators child = child.getNextSibling(); } if (child != null) { IElementType elementType = PsiUtilCore.getElementType(child); PsiElement second = child.getNextSibling(); IElementType typeSecond = second != null ? PsiUtilCore.getElementType(second) : null; if (elementType == BashTokenTypes.ARITH_HEX_NUMBER) { newType = LiteralType.HexLiteral; } else if (elementType == BashTokenTypes.ARITH_OCTAL_NUMBER) { newType = LiteralType.OctalLiteral; } else if (elementType == BashTokenTypes.ARITH_NUMBER) { if (typeSecond == BashTokenTypes.ARITH_BASE_CHAR) { newType = LiteralType.BaseLiteral; } else { newType = LiteralType.DecimalLiteral; } } } literalType = newType; } } } return literalType; }
Example 15
Source File: BraceHighlightingHandler.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull static EditorHighlighter getLazyParsableHighlighterIfAny(Project project, Editor editor, PsiFile psiFile) { if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) { return ((EditorEx)editor).getHighlighter(); } PsiElement elementAt = psiFile.findElementAt(editor.getCaretModel().getOffset()); for (PsiElement e : SyntaxTraverser.psiApi().parents(elementAt).takeWhile(Conditions.notEqualTo(psiFile))) { if (!(PsiUtilCore.getElementType(e) instanceof ILazyParseableElementType)) continue; Language language = ILazyParseableElementType.LANGUAGE_KEY.get(e.getNode()); if (language == null) continue; TextRange range = e.getTextRange(); final int offset = range.getStartOffset(); SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, psiFile.getVirtualFile()); LexerEditorHighlighter highlighter = new LexerEditorHighlighter(syntaxHighlighter, editor.getColorsScheme()) { @Nonnull @Override public HighlighterIterator createIterator(int startOffset) { return new HighlighterIteratorWrapper(super.createIterator(Math.max(startOffset - offset, 0))) { @Override public int getStart() { return super.getStart() + offset; } @Override public int getEnd() { return super.getEnd() + offset; } }; } }; highlighter.setText(editor.getDocument().getText(range)); return highlighter; } return ((EditorEx)editor).getHighlighter(); }
Example 16
Source File: CSharpFindUsagesProvider.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nonnull private String debugText(String prefix, @Nonnull PsiElement element) { IElementType type = PsiUtilCore.getElementType(element); String suffix = type == null ? element.getClass().getSimpleName() : type.toString(); return prefix + " : " + suffix; }
Example 17
Source File: Identikit.java From consulo with Apache License 2.0 | 4 votes |
private boolean isAcceptable(@Nonnull PsiElement element) { IElementType type = PsiUtilCore.getElementType(element); return myElementClassName.equals(element.getClass().getName()) && type != null && myElementTypeId == type.getIndex(); }
Example 18
Source File: CSharpOperatorReferenceImpl.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Nonnull @RequiredReadAction public IElementType getOperatorElementType() { return PsiUtilCore.getElementType(getOperatorElement()); }
Example 19
Source File: CSharpExtendWordSelectionHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Override public boolean canSelect(PsiElement e) { return PsiUtilCore.getElementType(e) == CSharpTokens.IDENTIFIER; }
Example 20
Source File: LambdaLineMarkerCollector.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction @Override public void collect(PsiElement psiElement, @Nonnull Consumer<LineMarkerInfo> lineMarkerInfos) { IElementType elementType = PsiUtilCore.getElementType(psiElement); if(elementType == CSharpTokens.DARROW) { PsiElement parent = psiElement.getParent(); if(!(parent instanceof CSharpLambdaExpressionImpl)) { return; } MarkerInfo markerInfo = new MarkerInfo(parent, psiElement.getTextRange(), AllIcons.Gutter.ImplementingFunctional, Pass.UPDATE_ALL, new ConstantFunction<>("Navigate to lambda delegate"), new GutterIconNavigationHandler<PsiElement>() { @Override @RequiredUIAccess public void navigate(MouseEvent e, PsiElement elt) { if(!(elt instanceof CSharpLambdaExpressionImpl)) { return; } CSharpLambdaResolveResult lambdaResolveResult = CSharpLambdaExpressionImplUtil.resolveLeftLambdaTypeRef(elt); if(lambdaResolveResult == null) { return; } PsiElement element = lambdaResolveResult.getElement(); if(element instanceof Navigatable) { ((Navigatable) element).navigate(true); } } }, GutterIconRenderer.Alignment.RIGHT); NavigateAction.setNavigateAction(markerInfo, "Navigate to lambda delegate", IdeActions.ACTION_GOTO_SUPER); lineMarkerInfos.consume(markerInfo); } }