Search in sources :

Example 1 with RncFile

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RncFile(org.intellij.plugins.relaxNG.compact.psi.RncFile)

Example 2 with RncFile

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;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) ASTNode(com.intellij.lang.ASTNode) RncFile(org.intellij.plugins.relaxNG.compact.psi.RncFile)

Example 3 with RncFile

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;
}
Also used : RncFile(org.intellij.plugins.relaxNG.compact.psi.RncFile)

Example 4 with RncFile

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;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) ASTNode(com.intellij.lang.ASTNode) IncorrectOperationException(com.intellij.util.IncorrectOperationException) RncFile(org.intellij.plugins.relaxNG.compact.psi.RncFile) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with RncFile

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;
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) ASTNode(com.intellij.lang.ASTNode) RncFile(org.intellij.plugins.relaxNG.compact.psi.RncFile)

Aggregations

RncFile (org.intellij.plugins.relaxNG.compact.psi.RncFile)5 ASTNode (com.intellij.lang.ASTNode)3 PsiFileFactory (com.intellij.psi.PsiFileFactory)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 NotNull (org.jetbrains.annotations.NotNull)1