use of org.intellij.plugins.relaxNG.compact.psi.RncFile in project intellij-community by JetBrains.
the class RngSchemaValidator method handleError.
public static void handleError(SAXParseException ex, PsiFile file, Document document, ValidationMessageConsumer consumer) {
final String systemId = ex.getSystemId();
if (LOG.isDebugEnabled()) {
LOG.debug("RNG Schema error: " + ex.getMessage() + " [" + systemId + "]");
}
if (systemId != null) {
final VirtualFile virtualFile = findVirtualFile(systemId);
if (!Comparing.equal(virtualFile, file.getVirtualFile())) {
return;
}
}
final PsiElement at;
final int line = ex.getLineNumber();
if (line > 0) {
final int column = ex.getColumnNumber();
final int startOffset = document.getLineStartOffset(line - 1);
if (column > 0) {
if (file.getFileType() == RncFileType.getInstance()) {
final PsiElement e = file.findElementAt(startOffset + column);
if (e == null) {
at = e;
} else {
at = file.findElementAt(startOffset + column - 1);
}
} else {
at = file.findElementAt(startOffset + column - 2);
}
} else {
final PsiElement e = file.findElementAt(startOffset);
at = e != null ? PsiTreeUtil.nextLeaf(e) : null;
}
} else {
final XmlDocument d = ((XmlFile) file).getDocument();
assert d != null;
final XmlTag rootTag = d.getRootTag();
assert rootTag != null;
at = rootTag.getFirstChild();
}
final PsiElement host;
if (file instanceof RncFile) {
host = at;
} else {
host = PsiTreeUtil.getParentOfType(at, XmlAttribute.class, XmlTag.class);
}
if (at != null && host != null) {
consumer.onMessage(host, ex.getMessage());
} else {
consumer.onMessage(file, ex.getMessage());
}
}
use of org.intellij.plugins.relaxNG.compact.psi.RncFile in project intellij-community by JetBrains.
the class RenameUtil method createPrefixedNode.
/*private static boolean isTokenOfType(PsiManager manager, String name, TokenSet set) {
final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(RngCompactLanguage.INSTANCE);
assert definition != null;
final Lexer lexer = definition.createLexer(manager.getProject());
lexer.start(name, 0, name.length(), 0);
final IElementType t = lexer.getTokenType();
lexer.advance();
return lexer.getTokenType() == null && set.contains(t);
}*/
public static ASTNode createPrefixedNode(PsiManager manager, String prefix, String localPart) {
final PsiFileFactory f = PsiFileFactory.getInstance(manager.getProject());
final RncFile file = (RncFile) f.createFileFromText("dummy.rnc", RncFileType.getInstance(), "element " + prefix + ":" + localPart + " { text }");
final ASTNode node = findFirstGrammarNode(file);
final ASTNode nameClassNode = node.findChildByType(RncElementTypes.NAME_CLASS);
assert nameClassNode != null;
final ASTNode astNode = nameClassNode.findChildByType(RncElementTypes.NAME);
assert astNode != null;
return astNode;
}
use of org.intellij.plugins.relaxNG.compact.psi.RncFile in project intellij-community by JetBrains.
the class RncFileReferenceImpl method processDeclarations.
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState substitutor, PsiElement lastParent, @NotNull PsiElement place) {
final FollowFileHint hint = processor.getHint(FollowFileHint.KEY);
final RncFile file = getReferencedFile();
if (file != null && hint != null && hint.doFollow(file)) {
file.processDeclarations(processor, substitutor, lastParent, place);
}
return true;
}
use of org.intellij.plugins.relaxNG.compact.psi.RncFile in project intellij-community by JetBrains.
the class RenameUtil method createIdentifierNode.
@NotNull
public static ASTNode createIdentifierNode(PsiManager manager, String name) throws IncorrectOperationException {
if (isKeyword(name)) {
name = "\\" + name;
} else if (!isIdentifier(name)) {
throw new IncorrectOperationException("Illegal identifier: " + name);
}
final PsiFileFactory f = PsiFileFactory.getInstance(manager.getProject());
final RncFile file = (RncFile) f.createFileFromText("dummy.rnc", RncFileType.getInstance(), name + " = bar");
final ASTNode astNode = findFirstGrammarNode(file);
final ASTNode newNode = astNode.findChildByType(RncTokenTypes.IDENTIFIERS);
assert newNode != null;
return newNode;
}
use of org.intellij.plugins.relaxNG.compact.psi.RncFile in project intellij-community by JetBrains.
the class RenameUtil method createLiteralNode.
public static ASTNode createLiteralNode(PsiManager manager, String content) {
final PsiFileFactory f = PsiFileFactory.getInstance(manager.getProject());
final RncFile file = (RncFile) f.createFileFromText("dummy.rnc", RncFileType.getInstance(), "include \"" + content + "\"");
final ASTNode include = findFirstGrammarNode(file);
final ASTNode literal = include.findChildByType(RncTokenTypes.LITERAL);
assert literal != null;
return literal;
}
Aggregations