當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。