Java Code Examples for com.intellij.psi.util.PsiTreeUtil#skipWhitespacesBackward()

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#skipWhitespacesBackward() . These examples are extracted from open source projects. 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 Project: intellij-latte   File: LattePsiImplUtil.java    License: MIT License 6 votes vote down vote up
public static boolean isDefinitionInFor(@NotNull LattePhpVariable element) {
	LatteNetteAttrValue parentAttr = PsiTreeUtil.getParentOfType(element, LatteNetteAttrValue.class);
	if (parentAttr != null) {
		PsiElement nextElement = PsiTreeUtil.skipWhitespacesForward(element);
		if (nextElement == null || nextElement.getNode().getElementType() != LatteTypes.T_PHP_DEFINITION_OPERATOR) {
			return false;
		}
		PsiElement prevElement = PsiTreeUtil.skipWhitespacesBackward(parentAttr);
		if (prevElement == null || prevElement.getNode().getElementType() != LatteTypes.T_PHP_DEFINITION_OPERATOR) {
			return false;
		}

		prevElement = PsiTreeUtil.skipWhitespacesBackward(prevElement);
		return prevElement != null && prevElement.getText().equals("n:for");
	}
	return LatteUtil.matchParentMacroName(element, "for") && LattePhpVariableUtil.isNextDefinitionOperator(element);
}
 
Example 2
Source Project: intellij-latte   File: LattePhpVariableUtil.java    License: MIT License 5 votes vote down vote up
@Nullable
private static LattePhpType findPrevPhpType(LattePhpVariable element) {
    LattePhpTypedPartElement typedElement = PsiTreeUtil.getParentOfType(element, LattePhpTypedPartElement.class);
    if (typedElement != null) {
        return typedElement.getPhpType();
    }
    LattePhpStatementPartElement statementPart = element.getPhpStatementPart();
    if (statementPart == null) {
        return null;
    }
    PsiElement phpTypeElement = PsiTreeUtil.skipWhitespacesBackward(statementPart.getPhpStatement());
    return phpTypeElement instanceof LattePhpTypeElement
            ? ((LattePhpTypeElement) phpTypeElement).getPhpType()
            : (phpTypeElement instanceof LattePhpStatement ? ((LattePhpStatement) phpTypeElement).getPhpType() : null);
}
 
Example 3
Source Project: intellij-latte   File: LattePsiImplUtil.java    License: MIT License 5 votes vote down vote up
public static boolean isDefinitionInForeach(@NotNull PsiElement element) {
	PsiElement parent = element.getParent();
	if (parent != null && parent.getNode().getElementType() == PHP_FOREACH) {
		PsiElement prevElement = PsiTreeUtil.skipWhitespacesBackward(element);
		IElementType type = prevElement != null ? prevElement.getNode().getElementType() : null;
		return type == T_PHP_AS || type == T_PHP_DOUBLE_ARROW;

	} else if (parent != null && parent.getNode().getElementType() == PHP_ARRAY_OF_VARIABLES) {
		return isDefinitionInForeach(parent);
	}
	return false;
}
 
Example 4
Source Project: intellij-latte   File: LattePsiImplUtil.java    License: MIT License 4 votes vote down vote up
public static boolean isStatic(@NotNull PsiElement element) {
	PsiElement prev = PsiTreeUtil.skipWhitespacesBackward(element);
	return prev != null && prev.getNode().getElementType() == T_PHP_DOUBLE_COLON;
}
 
Example 5
Source Project: intellij-latte   File: LattePsiImplUtil.java    License: MIT License 4 votes vote down vote up
public static boolean isFunction(@NotNull PsiElement element) {
	PsiElement prev = PsiTreeUtil.skipWhitespacesBackward(element);
	return prev == null || (prev.getNode().getElementType() != T_PHP_DOUBLE_COLON && prev.getNode().getElementType() != T_PHP_OBJECT_OPERATOR);
}