use of org.intellij.lang.xpath.psi.XPathType in project intellij-community by JetBrains.
the class XsltFunctionImpl method getFunction.
private Function getFunction() {
final XPathType returnType = XsltCodeInsightUtil.getDeclaredType(getTag());
final XmlTag[] params = getTag().findSubTags("param", XsltSupport.XSLT_NS);
final Parameter[] parameters = ContainerUtil.map2Array(params, Parameter.class, PARAM_MAPPER);
return new FunctionImpl(null, returnType != null ? returnType : XPathType.UNKNOWN, parameters) {
@Override
public String getName() {
return getQName().getLocalPart();
}
};
}
use of org.intellij.lang.xpath.psi.XPathType in project intellij-community by JetBrains.
the class XsltVariableImpl method getType.
@NotNull
public XPathType getType() {
final XPathType declaredType = XsltCodeInsightUtil.getDeclaredType(getTag());
if (declaredType != null) {
return declaredType;
}
final XmlAttribute attr = getTag().getAttribute("type", XsltSupport.PLUGIN_EXTENSIONS_NS);
if (attr != null) {
return XPathType.fromString(attr.getValue());
}
final XPathExpression value = getValue();
if (value instanceof XPathVariableReference) {
// recursive reference <xsl:variable name="foo" select="$foo" />
final XPathVariableReference reference = (XPathVariableReference) value;
if (reference.resolve() == this) {
return XPathType.UNKNOWN;
}
}
return value != null ? value.getType() : XPathType.UNKNOWN;
}
use of org.intellij.lang.xpath.psi.XPathType in project intellij-community by JetBrains.
the class XPath2ExpressionTest method doTest.
protected XPathType doTest(boolean symmetric) throws Throwable {
myFixture.configureByFile(getTestFileName() + ".xpath2");
final XPathExpression expression = getExpression();
// all these cases must be green
myFixture.checkHighlighting();
if (symmetric && expression instanceof XPathBinaryExpression) {
final XPathBinaryExpression expr = (XPathBinaryExpression) expression;
if (expr.getLOperand().getType() != expr.getROperand().getType()) {
myFixture.configureByText(XPathFileType.XPATH2, expr.getROperand().getText() + " " + expr.getOperationSign() + " " + expr.getLOperand().getText());
assertEquals(getExpression().getType(), expression.getType());
myFixture.checkHighlighting();
}
}
final XPathType type = expression.getType();
if (type instanceof XPath2SequenceType) {
return ((XPath2SequenceType) type).getType();
}
return type;
}
use of org.intellij.lang.xpath.psi.XPathType in project intellij-community by JetBrains.
the class FunctionDeclarationParsing method parseFuntionDeclaration.
public static Pair<String, ? extends Function> parseFuntionDeclaration(String decl) {
final Lexer lexer = new FilterLexer(XPathLexer.create(true), new FilterLexer.SetFilter(TokenSet.create(XPathTokenTypes.WHITESPACE)));
lexer.start(decl);
String prefix = "";
if (lexer.getTokenType() == XPathTokenTypes.EXT_PREFIX) {
prefix = lexer.getTokenText();
lexer.advance();
match(lexer, XPathTokenTypes.COL);
}
final String name = match(lexer, XPathTokenTypes.FUNCTION_NAME);
match(lexer, XPathTokenTypes.LPAREN);
final List<Parameter> parameters = new ArrayList<>();
while (lexer.getTokenType() != XPathTokenTypes.RPAREN) {
if (lexer.getTokenType() == XPathTokenTypes.DOTDOT) {
lexer.advance();
match(lexer, XPathTokenTypes.DOT);
parameters.add(new Parameter(XPathType.ANY, Parameter.Kind.VARARG));
} else {
match(lexer, XPathTokenTypes.DOLLAR);
match(lexer, XPathTokenTypes.VARIABLE_NAME);
match(lexer, XPath2TokenTypes.AS);
final String type = parseType(lexer);
final XPath2SequenceType.Cardinality indicator = parseCardinality(lexer);
parameters.add(new Parameter(mapType(type, indicator), Parameter.Kind.REQUIRED));
}
if (lexer.getTokenType() == XPathTokenTypes.COMMA) {
lexer.advance();
}
}
lexer.advance();
match(lexer, XPath2TokenTypes.AS);
final String ret = parseType(lexer);
final XPath2SequenceType.Cardinality indicator = parseCardinality(lexer);
final XPathType returnType = mapType(ret, indicator);
return Pair.create(prefix, new FunctionImpl(name, returnType, parameters.toArray(new Parameter[parameters.size()])));
}
Aggregations