当前位置: 首页>>代码示例>>Java>>正文


Java PsiElement.getPrevSibling方法代码示例

本文整理汇总了Java中com.intellij.psi.PsiElement.getPrevSibling方法的典型用法代码示例。如果您正苦于以下问题:Java PsiElement.getPrevSibling方法的具体用法?Java PsiElement.getPrevSibling怎么用?Java PsiElement.getPrevSibling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.PsiElement的用法示例。


在下文中一共展示了PsiElement.getPrevSibling方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteFunctionParam

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
public static void deleteFunctionParam(PsiElement element) {
    PsiElement next = element.getNextSibling();
    if (next != null && next.getText().equals(",")) {
        next.delete();
    } else {
        PsiElement prev = element.getPrevSibling();
        if (prev != null && prev instanceof PsiWhiteSpace) {
            prev.delete();
            prev = element.getPrevSibling();
        }
        if (prev != null && prev.getText().equals(",")) {
            prev.delete();
        }
    }
    element.delete();
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:17,代码来源:PsiUtil.java

示例2: calculateEndOffsetReductor

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
private static int calculateEndOffsetReductor(
    @NotNull final PsiElement directive,
    final boolean isDefinitivelyClosing
) {
    if (!isDefinitivelyClosing) {
        final PsiElement directiveWhitespace = directive.getPrevSibling();

        if (directiveWhitespace instanceof LeafPsiElement) {
            final String directiveWhitespaceText = directiveWhitespace.getText();
            final int    lastBreakline           = directiveWhitespaceText.lastIndexOf('\n');

            if (lastBreakline != -1) {
                return directiveWhitespaceText.length() - lastBreakline;
            }
        }
    }

    return 0;
}
 
开发者ID:rentalhost,项目名称:laravel-insight,代码行数:20,代码来源:BladeFoldingBuilder.java

示例3: skipAllExceptLineBreaksAndGetImpexValueGroup

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
@Contract(pure = true)
public static ImpexValueGroup skipAllExceptLineBreaksAndGetImpexValueGroup(
    @NotNull final PsiElement psiElement
) {
    Validate.notNull(psiElement);

    if (isLineBreak(psiElement.getPrevSibling())) {
        return null;
    }

    PsiElement prevSibling = psiElement.getPrevSibling();
    while (!isImpexValueLine(prevSibling)) {
        if (null == prevSibling || isLineBreak(prevSibling)) {
            return null;
        }

        prevSibling = prevSibling.getPrevSibling();
    }

    if (!isImpexValueLine(prevSibling)) {
        return null;
    }

    return PsiTreeUtil.getParentOfType(PsiTreeUtil.lastChild(prevSibling), ImpexValueGroup.class);
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:ImpexPsiUtils.java

示例4: getParentFieldElement

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
public static PsiElement getParentFieldElement(PsiElement element) {
    if (getElementType(element) == TokenType.WHITE_SPACE) {
        if (getElementType(element.getParent()) == CsvTypes.FIELD) {
            element = element.getParent();
        } else if (getElementType(element.getPrevSibling()) == CsvTypes.FIELD) {
            element = element.getPrevSibling();
        } else {
            element = null;
        }
    } else {
        while (element != null && CsvIntentionHelper.getElementType(element) != CsvTypes.FIELD) {
            element = element.getParent();
        }
    }
    return element;
}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:17,代码来源:CsvIntentionHelper.java

示例5: deleteArrayElement

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
public static void deleteArrayElement(PsiElement element) {
    PsiElement next = element.getNextSibling();
    String endArray = ((ArrayCreationExpression) element.getParent()).isShortSyntax() ? "]" : ")";

    if (next instanceof PsiWhiteSpace && next.getNextSibling().getText() != null) {
        if (next.getNextSibling().getText().equals(endArray)) {
            next = next.getNextSibling();
        }
    }
    if (next.getText().equals(endArray)) {
        Boolean deleteComma = false;
        if (element.getPrevSibling() instanceof PsiWhiteSpace) {
            deleteComma = !element.getPrevSibling().getText().contains("\n");
            element.getPrevSibling().delete();
        }
        if (deleteComma && element.getPrevSibling().getText().equals(",")) {
            element.getPrevSibling().delete();
        }
    }
    if (next.getText().equals(",")) {
        if (next.getNextSibling() instanceof PsiWhiteSpace) {
            next.getNextSibling().delete();
        }
        next.delete();
    }
    element.delete();
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:28,代码来源:PsiUtil.java

示例6: applyFix

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement expression = descriptor.getPsiElement();
    if (null != expression && expression.getParent() instanceof ArrayCreationExpression) {
        final ArrayCreationExpression container = (ArrayCreationExpression) expression.getParent();
        final PsiElement closingBracket         = container.getLastChild();
        if (null == closingBracket) {
            return;
        }

        for (String translation : missing) {
            /* reach or create a comma */
            PsiElement last = closingBracket.getPrevSibling();
            if (last instanceof PsiWhiteSpace) {
                last = last.getPrevSibling();
            }
            if (null != last && PhpTokenTypes.opCOMMA != last.getNode().getElementType()) {
                last.getParent().addAfter(PhpPsiElementFactory.createComma(project), last);
                last = last.getNextSibling();
            }

            /* add a new translation */
            final String escaped                = PhpStringUtil.escapeText(translation, true, '\n', '\t');
            final String pairPattern            = "array('%s%' => '%s%')".replace("%s%", escaped).replace("%s%", escaped);
            final ArrayCreationExpression array = PhpPsiElementFactory.createFromText(project, ArrayCreationExpression.class, pairPattern);
            final PhpPsiElement pair            = null == array ? null : array.getHashElements().iterator().next();
            final PsiWhiteSpace space           = PhpPsiElementFactory.createFromText(project, PsiWhiteSpace.class, " ");
            if (null == last || null == pair || null == space) {
                continue;
            }
            last.getParent().addAfter(pair, last);
            last.getParent().addAfter(space, last);
        }
    }
}
 
开发者ID:kalessil,项目名称:yii2inspections,代码行数:36,代码来源:MissingTranslationsInspector.java

示例7: getSelectedTable

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
final Pair<PsiElement, PsiElement> getSelectedTable(final @NotNull ImpexTableEditor editor) {
    final PsiElement elementAtCaret = getElementAtCaret(editor.getIdeaEditor());


    final PsiElement valueLineAt;
    if (elementAtCaret != null) {
        if (getNextSiblingOfType(elementAtCaret, ImpexValueLine.class) != null) {
            valueLineAt = elementAtCaret.getNextSibling();
        } else if (getPrevSiblingOfType(elementAtCaret, ImpexValueLine.class) != null) {
            valueLineAt = elementAtCaret.getPrevSibling();
        } else {
            valueLineAt = getParentOfType(
                elementAtCaret,
                ImpexValueLine.class
            );

        }
    } else {
        return null;
    }

    if (valueLineAt == null) {
        return null;
    }

    final PsiElement headerLine = scanFirstLine(elementAtCaret, valueLineAt);

    final PsiElement lastValueLine = scanLastLine(valueLineAt, headerLine);

    return Pair.create(headerLine, lastValueLine);
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:33,代码来源:AbstractOperation.java

示例8: getPrevNonWhitespaceElement

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
@Contract(pure = true)
public static PsiElement getPrevNonWhitespaceElement(@NotNull final PsiElement element) {
    Validate.notNull(element);

    PsiElement prevSibling = element.getPrevSibling();

    while (null != prevSibling && (isWhiteSpace(prevSibling) || isLineBreak(prevSibling))) {
        prevSibling = prevSibling.getPrevSibling();
    }

    return prevSibling;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:14,代码来源:ImpexPsiUtils.java

示例9: getPrevValueLine

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
@Contract(pure = true)
public static PsiElement getPrevValueLine(@NotNull final PsiElement element) {
    Validate.notNull(element);

    PsiElement prevSibling = element.getPrevSibling();

    while (null != prevSibling && !isImpexValueLine(prevSibling)) {
        prevSibling = prevSibling.getPrevSibling();
    }

    return prevSibling;
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:14,代码来源:ImpexPsiUtils.java

示例10: getRealPreElement

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
public static PsiElement getRealPreElement (PsiElement p){
    PsiElement p1 = p.getPrevSibling();
    if(p1 !=null){
        if(!(p1 instanceof PsiWhiteSpace)){
            return  p1;
        }
        PsiElement p2 = p1.getPrevSibling();
        if(p2 !=null && !( p2 instanceof PsiWhiteSpace)){
            return  p2;
        }
    }
    return null;
}
 
开发者ID:dpzxsm,项目名称:ReactPropTypes-Plugin,代码行数:14,代码来源:PsiElementHelper.java

示例11: getPreviousSeparator

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
private static PsiElement getPreviousSeparator(PsiElement fieldElement) {
    while (fieldElement != null) {
        if (getElementType(fieldElement) == CsvTypes.COMMA) {
            break;
        }
        fieldElement = fieldElement.getPrevSibling();
    }
    return fieldElement;
}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:10,代码来源:CsvIntentionHelper.java

示例12: getOpeningQuotePosition

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
public static int getOpeningQuotePosition(PsiElement errorElement) {
    PsiElement lastFieldElement = errorElement;
    while(getElementType(lastFieldElement) != CsvTypes.RECORD) {
        lastFieldElement = lastFieldElement.getPrevSibling();
    }
    lastFieldElement = lastFieldElement.getLastChild();
    if (getElementType(lastFieldElement) != CsvTypes.FIELD) {
        throw new RuntimeException("Field element expected");
    }
    return getOpeningQuotePosition(lastFieldElement.getFirstChild(), lastFieldElement.getLastChild());

}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:13,代码来源:CsvIntentionHelper.java

示例13: collectExpressions

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
public static List<PsiElement> collectExpressions(final PsiFile file,
                                                  final Document document,
                                                  final int offset,
                                                  boolean acceptVoid) {
	CharSequence text = document.getCharsSequence();
	int correctedOffset = offset;
	int textLength = document.getTextLength();
	if (offset >= textLength) {
		correctedOffset = textLength - 1;
	} else if (!Character.isJavaIdentifierPart(text.charAt(offset))) {
		correctedOffset--;
	}
	if (correctedOffset < 0) {
		correctedOffset = offset;
	} else if (!Character.isJavaIdentifierPart(text.charAt(correctedOffset))) {
		if (text.charAt(correctedOffset) == ';') {//initially caret on the end of line
			correctedOffset--;
		}
		if (correctedOffset < 0 || text.charAt(correctedOffset) != ')') {
			correctedOffset = offset;
		}
	}
	final PsiElement elementAtCaret = file.findElementAt(correctedOffset);
	final List<PsiElement> expressions = new ArrayList<>();

	PsiElement expression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiElement.class);

	while (expression != null && expression.getTextRange().getEndOffset() == elementAtCaret.getTextRange().getEndOffset()) {
		//System.out.println(expression + " - " + expression.getText() + " - " + expression.getTextRange());
		final PsiElement finalExpression = expression;

		if (expression.getPrevSibling() == null || expression.getPrevSibling().getNode().getElementType() == TokenType.WHITE_SPACE) {
			if (expressions.stream().noneMatch(pe -> finalExpression.getTextRange().equals(pe.getTextRange()))) {
				expressions.add(expression);
			}
		} else {
			//System.out.println("prevSilbing: " + expression.getPrevSibling().getNode().getElementType());
		}

		//expression = PsiTreeUtil.getParentOfType(expression, KtExpression.class);
		expression = expression.getParent();
	}

	// TODO: For an unknown reason this code completion works only with a single expression and not with multiple ones.
	// TODO: Therefore we have to cut our list to a singleton list.
	if (expressions.isEmpty()) {
		return expressions;
	}
	ArrayList<PsiElement> es = new ArrayList<>();
	es.add(expressions.get(0));
	//es.add(expressions.get(expressions.size()-1));
	return es;
}
 
开发者ID:xylo,项目名称:intellij-postfix-templates,代码行数:54,代码来源:CustomKotlinStringPostfixTemplate.java

示例14: scanLastLine

import com.intellij.psi.PsiElement; //导入方法依赖的package包/类
@Nullable
private PsiElement scanLastLine(final PsiElement valueLineAt, final PsiElement headerLine) {
    final PsiElement secondHeaderLine = getNextSiblingOfAnyType(
        valueLineAt,
        ImpexRootMacroUsage.class,
        ImpexHeaderLine.class
    );

    if (secondHeaderLine == null) {
        PsiElement lastValueLine = valueLineAt != null ? valueLineAt.getNextSibling() : headerLine.getNextSibling();
        final PsiElement nextSiblingOfAnyType = getNextSiblingOfAnyType(
            lastValueLine,
            ImpexHeaderLine.class,
            ImpexRootMacroUsage.class
        );

        if (nextSiblingOfAnyType != null) {
            lastValueLine = nextSiblingOfAnyType.getPrevSibling();
        } else {
            lastValueLine = findSiblingByPredicate(
                lastValueLine,
                (sibling) -> (isImpexValueLine(sibling) || isLineBreak(sibling)) && isLastElement(sibling)
            );
        }

        if (lastValueLine == null) {
            lastValueLine = valueLineAt;
        }

        return lastValueLine;
    }

    if (secondHeaderLine instanceof ImpexRootMacroUsage && secondHeaderLine.getText().startsWith("$END")) {
        return secondHeaderLine;
    }

    return getPrevSiblingOfType(
        secondHeaderLine,
        ImpexValueLine.class
    );
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:42,代码来源:AbstractOperation.java


注:本文中的com.intellij.psi.PsiElement.getPrevSibling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。