Search in sources :

Example 6 with LeafPsiElement

use of com.intellij.psi.impl.source.tree.LeafPsiElement in project intellij-community by JetBrains.

the class GrVariableBaseImpl method delete.

@Override
public void delete() throws IncorrectOperationException {
    PsiElement parent = getParent();
    PsiElement prev = PsiUtil.getPrevNonSpace(this);
    PsiElement next = PsiUtil.getNextNonSpace(this);
    ASTNode parentNode = parent.getNode();
    assert parentNode != null;
    super.delete();
    if (prev != null && prev.getNode() != null && prev.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
        prev.delete();
    } else if (next instanceof LeafPsiElement && next.getNode() != null && next.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
        next.delete();
    }
    if (parent instanceof GrVariableDeclaration && ((GrVariableDeclaration) parent).getVariables().length == 0) {
        parent.delete();
    }
}
Also used : GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) ASTNode(com.intellij.lang.ASTNode) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 7 with LeafPsiElement

use of com.intellij.psi.impl.source.tree.LeafPsiElement in project intellij-community by JetBrains.

the class GrArgumentLabelImpl method getReferenceFromNamedArgumentProviders.

@Nullable
private PsiPolyVariantReference getReferenceFromNamedArgumentProviders() {
    PsiElement namedArgument = getParent();
    if (!(namedArgument instanceof GrNamedArgument))
        return null;
    PsiElement nameElement = getNameElement();
    if (!(nameElement instanceof LeafPsiElement))
        return null;
    IElementType elementType = ((LeafPsiElement) nameElement).getElementType();
    if (elementType != GroovyTokenTypes.mIDENT && !CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) {
        return null;
    }
    GrCall call = PsiUtil.getCallByNamedParameter((GrNamedArgument) namedArgument);
    if (call == null)
        return NamedArgumentUtilKt.getReferenceFromDescriptor(this);
    String labelName = getName();
    Map<String, NamedArgumentDescriptor> providers = GroovyNamedArgumentProvider.getNamedArgumentsFromAllProviders(call, labelName, false);
    if (providers != null) {
        NamedArgumentDescriptor descr = providers.get(labelName);
        if (descr != null) {
            PsiPolyVariantReference res = descr.createReference(this);
            if (res != null) {
                return res;
            }
        }
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with LeafPsiElement

use of com.intellij.psi.impl.source.tree.LeafPsiElement in project intellij-plugins by JetBrains.

the class GherkinStepParameterImpl method setName.

@Override
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
    final LeafPsiElement content = PsiTreeUtil.getChildOfType(this, LeafPsiElement.class);
    PsiElement[] elements = GherkinElementFactory.getTopLevelElements(getProject(), name);
    getNode().replaceChild(content, elements[0].getNode());
    return this;
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 9 with LeafPsiElement

use of com.intellij.psi.impl.source.tree.LeafPsiElement in project intellij-plugins by JetBrains.

the class AngularJavaScriptCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    if (AngularJSCompletionContributor.getElementLanguage(parameters).isKindOf(JavascriptLanguage.INSTANCE)) {
        PsiElement originalPosition = parameters.getOriginalPosition();
        if (originalPosition == null)
            return;
        final Project project = originalPosition.getProject();
        if (AngularJSReferencesContributor.UI_VIEW_PATTERN.accepts(originalPosition)) {
            final FileBasedIndex instance = FileBasedIndex.getInstance();
            final Collection<String> keys = instance.getAllKeys(AngularUiRouterViewsIndex.UI_ROUTER_VIEWS_CACHE_INDEX, project);
            addCompletionVariants(result, keys, " (angular-ui-router ui-view)");
        } else {
            originalPosition = originalPosition instanceof LeafPsiElement && ((LeafPsiElement) originalPosition).getElementType() == JSTokenTypes.STRING_LITERAL ? originalPosition.getParent() : originalPosition;
            if (AngularJSReferencesContributor.MODULE_PATTERN.accepts(originalPosition) || AngularJSReferencesContributor.MODULE_DEPENDENCY_PATTERN.accepts(originalPosition)) {
                final Collection<String> keys = AngularIndexUtil.getAllKeys(AngularModuleIndex.KEY, project);
                addCompletionVariants(result, keys, " (AngularJS module)");
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Example 10 with LeafPsiElement

use of com.intellij.psi.impl.source.tree.LeafPsiElement in project intellij-plugins by JetBrains.

the class JstdTestFileStructureBuilder method addPrototypeTest.

private static void addPrototypeTest(@NotNull JstdTestCaseStructure testCaseStructure, @Nullable JSExpression rightAssignmentOperand, @NotNull JSDefinitionExpression wholeLeftDefExpr) {
    JSReferenceExpression wholeLeftRefExpr = ObjectUtils.tryCast(wholeLeftDefExpr.getExpression(), JSReferenceExpression.class);
    LeafPsiElement testMethodLeafPsiElement = null;
    if (wholeLeftRefExpr != null) {
        testMethodLeafPsiElement = ObjectUtils.tryCast(wholeLeftRefExpr.getReferenceNameElement(), LeafPsiElement.class);
    }
    if (testMethodLeafPsiElement != null && testMethodLeafPsiElement.getElementType() == JSTokenTypes.IDENTIFIER) {
        JSFunctionExpression jsFunctionExpression = JsPsiUtils.extractFunctionExpression(rightAssignmentOperand);
        JstdTestStructure jstdTestStructure = JstdTestStructure.newPrototypeBasedTestStructure(wholeLeftDefExpr, testMethodLeafPsiElement, jsFunctionExpression);
        if (jstdTestStructure != null) {
            testCaseStructure.addTestStructure(jstdTestStructure);
        }
    }
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Aggregations

LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)25 PsiElement (com.intellij.psi.PsiElement)11 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)4 TextRange (com.intellij.openapi.util.TextRange)2 IElementType (com.intellij.psi.tree.IElementType)2 GrVariableDeclaration (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration)2 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)2 ASTNode (com.intellij.lang.ASTNode)1 Language (com.intellij.lang.Language)1 Annotation (com.intellij.lang.annotation.Annotation)1 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)1 NamedFoldingDescriptor (com.intellij.lang.folding.NamedFoldingDescriptor)1 JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)1 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 Document (com.intellij.openapi.editor.Document)1 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1