List of usage examples for com.intellij.openapi.editor DocumentFragment getTextRange
public TextRange getTextRange()
From source file:com.google.jstestdriver.idea.config.JstdConfigFileAnnotator.java
License:Apache License
private static boolean isOneLineText(@NotNull YAMLSequence sequence) { PsiElementFragment<YAMLSequence> textSequenceFragment = JstdConfigFileUtils .buildSequenceTextFragment(sequence); if (textSequenceFragment != null) { DocumentFragment textFragment = textSequenceFragment.toDocumentFragment(); if (textFragment != null) { Document document = textFragment.getDocument(); TextRange textRange = textFragment.getTextRange(); int startLine = document.getLineNumber(textRange.getStartOffset()); int endLine = document.getLineNumber(textRange.getEndOffset()); return startLine == endLine; }/* w w w . j a v a 2 s.c om*/ } return false; }
From source file:com.google.jstestdriver.idea.config.JstdConfigFileAnnotator.java
License:Apache License
private static void annotatePath(@NotNull VirtualFile basePath, @NotNull DocumentFragment pathAsDocumentFragment, @NotNull final AnnotationHolder holder, boolean tolerateRemoteLocations, boolean expectDirectory) { String pathStr = pathAsDocumentFragment.getDocument().getText(pathAsDocumentFragment.getTextRange()); if (tolerateRemoteLocations && (pathStr.startsWith("http:") || pathStr.startsWith("https:"))) { return;// w w w . j a va2 s . c o m } if (StringUtil.isEmptyOrSpaces(pathStr)) { holder.createErrorAnnotation(pathAsDocumentFragment.getTextRange(), "Malformed path"); return; } int documentOffset = pathAsDocumentFragment.getTextRange().getStartOffset(); List<String> components = JstdConfigFileUtils.convertPathToComponentList(pathStr); VirtualFile current = basePath; if (!components.isEmpty()) { String first = components.get(0); if (first.length() + 1 <= pathStr.length()) { first = pathStr.substring(0, first.length() + 1); } if (!first.isEmpty()) { VirtualFile initial = BasePathInfo.findFile(basePath, first); if (initial != null) { current = initial; components = components.subList(1, components.size()); documentOffset += first.length(); } } } File currentFile = new File(current.getPath()); for (String component : components) { if (component.contains("*")) { return; } if (component.isEmpty()) { holder.createErrorAnnotation(TextRange.create(documentOffset, documentOffset + 1), "Malformed path"); return; } File next = new File(currentFile, component); if (!next.exists()) { holder.createErrorAnnotation(TextRange.create(documentOffset, documentOffset + component.length()), "No such file or directory '" + component + "'"); return; } documentOffset += component.length() + 1; currentFile = next; } if (expectDirectory) { if (!current.isDirectory()) { holder.createErrorAnnotation(pathAsDocumentFragment.getTextRange(), "A directory is expected"); } } else { if (currentFile.isDirectory()) { holder.createErrorAnnotation(pathAsDocumentFragment.getTextRange(), "A file is expected"); } } }