Java Code Examples for com.intellij.psi.util.PsiTreeUtil#skipWhitespacesForward()
The following examples show how to use
com.intellij.psi.util.PsiTreeUtil#skipWhitespacesForward() .
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: LattePhpVariableUtil.java From intellij-latte with MIT License | 6 votes |
public static boolean isNextDefinitionOperator(@NotNull PsiElement element) { PsiElement found = null; if (element instanceof LattePhpVariable && ((LattePhpVariable) element).getPhpStatementPart() != null) { found = ((LattePhpVariable) element).getPhpStatementPart().getPhpStatement(); } else if (element.getParent() instanceof LattePhpArrayOfVariables) { found = element.getParent(); } if (found == null) { LattePhpTypedArguments typedArgs = PsiTreeUtil.getParentOfType(element, LattePhpTypedArguments.class); found = typedArgs != null ? typedArgs : element; } PsiElement nextElement = PsiTreeUtil.skipWhitespacesForward(found); return nextElement != null && nextElement.getNode().getElementType() == LatteTypes.T_PHP_DEFINITION_OPERATOR; }
Example 2
Source File: LattePsiImplUtil.java From intellij-latte with MIT License | 6 votes |
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 3
Source File: PsiIncludeImpl.java From reasonml-idea-plugin with MIT License | 5 votes |
@NotNull @Override public String getPath() { PsiElement firstChild = PsiTreeUtil.skipWhitespacesForward(getFirstChild()); if (firstChild instanceof PsiFunctorCall) { return ((PsiFunctorCall) firstChild).getFunctorName(); } return firstChild == null ? "" : ORUtil.getTextUntilClass(firstChild, PsiConstraints.class); }
Example 4
Source File: PsiOpenImpl.java From reasonml-idea-plugin with MIT License | 5 votes |
@NotNull @Override public String getPath() { PsiElement firstChild = PsiTreeUtil.skipWhitespacesForward(getFirstChild()); if (firstChild instanceof PsiFunctorCall) { return ((PsiFunctorCall) firstChild).getFunctorName(); } return firstChild == null ? "" : ORUtil.getTextUntilTokenType(firstChild, null); }
Example 5
Source File: PsiIncludeImpl.java From reasonml-idea-plugin with MIT License | 4 votes |
@Override public boolean useFunctor() { PsiElement firstChild = PsiTreeUtil.skipWhitespacesForward(getFirstChild()); return firstChild instanceof PsiFunctorCall; }
Example 6
Source File: PsiOpenImpl.java From reasonml-idea-plugin with MIT License | 4 votes |
@Override public boolean useFunctor() { PsiElement firstChild = PsiTreeUtil.skipWhitespacesForward(getFirstChild()); return firstChild instanceof PsiFunctorCall; }
Example 7
Source File: LattePhpVariableUtil.java From intellij-latte with MIT License | 4 votes |
public static LattePhpType detectVariableType(@NotNull LattePhpVariable element) { String variableName = element.getVariableName(); List<PsiPositionedElement> all = LatteUtil.findVariablesInFileBeforeElement( element, element.getContainingFile().getOriginalFile().getVirtualFile(), element.getVariableName() ); List<PsiPositionedElement> definitions = all.stream().filter( psiPositionedElement -> psiPositionedElement.getElement() instanceof LattePhpVariable && ((LattePhpVariable) psiPositionedElement.getElement()).isDefinition() ).collect(Collectors.toList()); LattePhpStatementPartElement mainStatementPart = element.getPhpStatementPart(); for (PsiPositionedElement positionedElement : definitions) { if (!(positionedElement.getElement() instanceof LattePhpVariable)) { continue; } PsiElement current = positionedElement.getElement(); if ( ((LattePhpVariable) current).isVarTypeDefinition() || ((LattePhpVariable) current).isVarDefinition() || ((LattePhpVariable) current).isPhpArrayVarDefinition() || ((LattePhpVariable) current).isCaptureDefinition() || ((LattePhpVariable) current).isBlockDefineVarDefinition() || ((LattePhpVariable) current).isDefinitionInForeach() ) { int startDepth = 0; if (!(current.getParent() instanceof LattePhpArrayOfVariables)) { LattePhpType prevPhpType = findPrevPhpType((LattePhpVariable) current); if (prevPhpType != null) { return prevPhpType; } } else { startDepth = 1; } if (((LattePhpVariable) current).isDefinitionInForeach()) { PsiElement nextElement = PsiTreeUtil.skipWhitespacesForward(current); IElementType type = nextElement != null ? nextElement.getNode().getElementType() : null; if (type != T_PHP_DOUBLE_ARROW) { LattePhpForeach phpForeach = PsiTreeUtil.getParentOfType(current, LattePhpForeach.class); if (phpForeach != null && phpForeach.getPhpExpression().getPhpStatementList().size() > 0) { return phpForeach.getPhpExpression().getPhpType().withDepth(startDepth + 1); } } } LattePhpStatementPartElement statementPart = ((LattePhpVariable) current).getPhpStatementPart(); LattePhpContent phpContent = PsiTreeUtil.getParentOfType(current, LattePhpContent.class); if (phpContent != null && statementPart != mainStatementPart) { return detectVariableType(phpContent, startDepth); } return LattePhpType.MIXED; } } LattePhpType templateType = detectVariableTypeFromTemplateType(element, variableName); if (templateType != null) { return templateType; } LatteVariableSettings defaultVariable = LatteConfiguration.getInstance(element.getProject()).getVariable(variableName); if (defaultVariable != null) { return defaultVariable.toPhpType(); } return LattePhpType.MIXED; }