@NotNull private static PsiDirectory createParentDirectories(@NotNull PsiDirectory directoryRoot, @NotNull String className) throws IncorrectOperationException { final PsiPackage currentPackage = JavaDirectoryService.getInstance().getPackage(directoryRoot); final String packagePrefix = currentPackage == null? null : currentPackage.getQualifiedName() + "."; final String packageName = extractPackage(packagePrefix != null && className.startsWith(packagePrefix)? className.substring(packagePrefix.length()) : className); final StringTokenizer tokenizer = new StringTokenizer(packageName, "."); while (tokenizer.hasMoreTokens()) { String packagePart = tokenizer.nextToken(); PsiDirectory subdirectory = directoryRoot.findSubdirectory(packagePart); if (subdirectory == null) { directoryRoot.checkCreateSubdirectory(packagePart); subdirectory = directoryRoot.createSubdirectory(packagePart); } directoryRoot = subdirectory; } return directoryRoot; }
public static PsiReference[] getReferencesForAttributeValue(@Nullable XmlAttributeValue element, PairFunction<String, Integer, PsiReference> refFun) { if (element == null) { return PsiReference.EMPTY_ARRAY; } String text = element.getText(); String urls = StringUtil.unquoteString(text); StringTokenizer tokenizer = new StringTokenizer(urls); List<PsiReference> result = new ArrayList<PsiReference>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = text.indexOf(token); PsiReference ref = refFun.fun(token, index); if (ref != null) { result.add(ref); } } return result.toArray(new PsiReference[result.size()]); }
@NotNull protected List<File> getFiles(@Nullable AntDomPattern pattern, Set<AntFilesProvider> processed) { final File root = getCanonicalFile(getDir().getStringValue()); if (root == null) { return Collections.emptyList(); } final ArrayList<File> files = new ArrayList<File>(); final String filenames = getFilesString().getStringValue(); if (filenames != null) { final StringTokenizer tokenizer = new StringTokenizer(filenames, ", \t\n\r\f", false); while (tokenizer.hasMoreTokens()) { files.add(new File(root, tokenizer.nextToken())); } } for (AntDomNamedElement child : getFiles()) { final String fileName = child.getName().getStringValue(); if (fileName != null) { files.add(new File(root, fileName)); } } return files; }
public TargetResolver.Result fromString(@Nullable @NonNls String s, ConvertContext context) { final AntDomProject project = context.getInvocationElement().getParentOfType(AntDomProject.class, false); if (project == null) { return null; } final AntDomTarget contextTarget = context.getInvocationElement().getParentOfType(AntDomTarget.class, false); if (contextTarget == null) { return null; } final List<String> refs; if (s == null) { refs = Collections.emptyList(); } else { refs = new ArrayList<String>(); final StringTokenizer tokenizer = new StringTokenizer(s, ",", false); while (tokenizer.hasMoreTokens()) { final String ref = tokenizer.nextToken(); refs.add(ref.trim()); } } final TargetResolver.Result result = TargetResolver.resolve(project.getContextAntProject(), contextTarget, refs); result.setRefsString(s); return result; }
private Set<String> getExistingNames() { final AntDomElement hostingElement = getHostingAntDomElement(); if (hostingElement == null) { return Collections.emptySet(); } final AntDomTarget contextTarget = hostingElement.getParentOfType(AntDomTarget.class, false); if (contextTarget == null) { return Collections.emptySet(); } final Set<String> existing = new ArrayListSet<String>(); final String selfName = contextTarget.getName().getStringValue(); if (selfName != null) { existing.add(selfName); } final String dependsString = contextTarget.getDependsList().getRawText(); if (dependsString != null) { final StringTokenizer tokenizer = new StringTokenizer(dependsString, ",", false); while (tokenizer.hasMoreTokens()) { existing.add(tokenizer.nextToken().trim()); } } return existing; }
public static PsiReference[] getReferencesForAttributeValue(@Nullable XmlAttributeValue element, PairFunction<String, Integer, PsiReference> refFun) { if (element == null) { return PsiReference.EMPTY_ARRAY; } String text = element.getText(); String urls = StringUtil.stripQuotesAroundValue(text); StringTokenizer tokenizer = new StringTokenizer(urls); List<PsiReference> result = new ArrayList<PsiReference>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = text.indexOf(token); PsiReference ref = refFun.fun(token, index); if (ref != null) { result.add(ref); } } return result.toArray(new PsiReference[result.size()]); }
private static void setupUserProperties(List<String> commandLine, CompilationContext context) { final HaxeModuleSettingsBase settings = context.getModuleSettings(); commandLine.add("-main"); commandLine.add(context.getCompilationClass()); final StringTokenizer argumentsTokenizer = new StringTokenizer(settings.getArguments()); while (argumentsTokenizer.hasMoreTokens()) { commandLine.add(argumentsTokenizer.nextToken()); } if (context.isDebug()) { commandLine.add("-debug"); } if (context.getHaxeTarget() == HaxeTarget.FLASH && context.isDebug()) { commandLine.add("-D"); commandLine.add("fdb"); } for (String sourceRoot : context.getSourceRoots()) { commandLine.add("-cp"); commandLine.add(sourceRoot); } commandLine.add(context.getHaxeTarget().getCompilerFlag()); commandLine.add(context.getOutputFileName()); }
private static void setupNME(List<String> commandLine, CompilationContext context) { final HaxeModuleSettingsBase settings = context.getModuleSettings(); commandLine.add("run"); commandLine.add("nme"); commandLine.add("build"); commandLine.add(settings.getNmmlPath()); commandLine.add(settings.getNmeTarget().getTargetFlag()); if (context.isDebug()) { commandLine.add("-debug"); commandLine.add("-Ddebug"); } if (settings.getNmeTarget() == NMETarget.FLASH && context.isDebug()) { commandLine.add("-Dfdb"); } final StringTokenizer flagsTokenizer = new StringTokenizer(settings.getNmeFlags()); while (flagsTokenizer.hasMoreTokens()) { commandLine.add(flagsTokenizer.nextToken()); } }
private static void setupUserProperties(List<String> commandLine, CompilationContext context) { final HaxeModuleSettingsBase settings = context.getModuleSettings(); commandLine.add("-main"); commandLine.add(settings.getMainClass()); final StringTokenizer argumentsTokenizer = new StringTokenizer(settings.getArguments()); while (argumentsTokenizer.hasMoreTokens()) { commandLine.add(argumentsTokenizer.nextToken()); } if (context.isDebug()) { commandLine.add("-debug"); } if (settings.getHaxeTarget() == HaxeTarget.FLASH && context.isDebug()) { commandLine.add("-D"); commandLine.add("fdb"); } for (String sourceRoot : context.getSourceRoots()) { commandLine.add("-cp"); commandLine.add(sourceRoot); } commandLine.add(settings.getHaxeTarget().getCompilerFlag()); commandLine.add(settings.getOutputFileName()); }
public static void printWithHighlighting(@Nonnull ConsoleView console, @Nonnull String text, @Nonnull SyntaxHighlighter highlighter, Runnable doOnNewLine) { Lexer lexer = highlighter.getHighlightingLexer(); lexer.start(text, 0, text.length(), 0); IElementType tokenType; while ((tokenType = lexer.getTokenType()) != null) { ConsoleViewContentType contentType = getContentTypeForToken(tokenType, highlighter); StringTokenizer eolTokenizer = new StringTokenizer(lexer.getTokenText(), "\n", true); while (eolTokenizer.hasMoreTokens()) { String tok = eolTokenizer.nextToken(); console.print(tok, contentType); if (doOnNewLine != null && "\n".equals(tok)) { doOnNewLine.run(); } } lexer.advance(); } }
public static PsiReference[] getReferencesForAttributeValue(@Nullable XmlAttributeValue element, PairFunction<String, Integer, PsiReference> refFun) { if(element == null) { return PsiReference.EMPTY_ARRAY; } String text = element.getText(); String urls = StringUtil.unquoteString(text); StringTokenizer tokenizer = new StringTokenizer(urls); List<PsiReference> result = new ArrayList<>(); while(tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = text.indexOf(token); PsiReference ref = refFun.fun(token, index); if(ref != null) { result.add(ref); } } return result.toArray(new PsiReference[result.size()]); }
@NotNull private static PsiDirectory createParentDirectories(@NotNull PsiDirectory directoryRoot, @NotNull String className) throws IncorrectOperationException { final PsiJavaPackage currentPackage = JavaDirectoryService.getInstance().getPackage(directoryRoot); final String packagePrefix = currentPackage == null? null : currentPackage.getQualifiedName() + "."; final String packageName = extractPackage(packagePrefix != null && className.startsWith(packagePrefix)? className.substring(packagePrefix.length()) : className); final StringTokenizer tokenizer = new StringTokenizer(packageName, "."); while (tokenizer.hasMoreTokens()) { String packagePart = tokenizer.nextToken(); PsiDirectory subdirectory = directoryRoot.findSubdirectory(packagePart); if (subdirectory == null) { directoryRoot.checkCreateSubdirectory(packagePart); subdirectory = directoryRoot.createSubdirectory(packagePart); } directoryRoot = subdirectory; } return directoryRoot; }
@Nullable @Override public VirtualFile findRootByClass(List<VirtualFile> roots, String fqn) { for (VirtualFile file : roots) { if (findInFile(file, new StringTokenizer(fqn, "."))) return file; } return null; }
@Override public boolean isClassAvailable(final String[] urls, String fqn) { for (String url : urls) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file == null) continue; if (!(file.getFileSystem() instanceof JarFileSystem) && !file.isDirectory()) { file = JarFileSystem.getInstance().getJarRootForLocalFile(file); } if (file == null) continue; if (findInFile(file, new StringTokenizer(fqn, "."))) return true; } return false; }
private static boolean findInFile(VirtualFile root, final StringTokenizer filePath) { if (!filePath.hasMoreTokens()) return true; @NonNls String name = filePath.nextToken(); if (!filePath.hasMoreTokens()) { name += ".class"; } final VirtualFile child = root.findChild(name); return child != null && findInFile(child, filePath); }
private static boolean findInFile(VirtualFile file, final StringTokenizer tokenizer) { if (!tokenizer.hasMoreTokens()) return true; @NonNls StringBuilder name = new StringBuilder(tokenizer.nextToken()); if (!tokenizer.hasMoreTokens()) { name.append(".class"); } final VirtualFile child = file.findChild(name.toString()); return child != null && findInFile(child, tokenizer); }
@Override public void readExternal(Element element) throws InvalidDataException { proportions.clear(); String prop = element.getAttributeValue(ATTRIBUTE_PROPORTIONS); String version = element.getAttributeValue(ATTRIBUTE_VERSION); if (prop != null && Comparing.equal(version, DATA_VERSION)) { StringTokenizer tokenizer = new StringTokenizer(prop, ","); while (tokenizer.hasMoreTokens()) { String p = tokenizer.nextToken(); proportions.add(Float.valueOf(p)); } } }
@Nullable @Override public SplitterProportionsDataImpl fromString(@NotNull String value) { SplitterProportionsDataImpl data = new SplitterProportionsDataImpl(); StringTokenizer tokenizer = new StringTokenizer(value, ","); while (tokenizer.hasMoreTokens()) { data.proportions.add(Float.valueOf(tokenizer.nextToken())); } return data; }
public static List<VirtualFile> findSuitableFilesFor(final String filePath, final Project project) { final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); // at first let's try to find file as is, by it's real path // and check that file belongs to current project // this location provider designed for tests thus we will check only project content // (we cannot check just sources or tests folders because RM doesn't use it final VirtualFile file = getByFullPath(filePath); final boolean inProjectContent = file != null && (index.isInContent(file)); if (inProjectContent) { return Collections.singletonList(file); } //split file by "/" in parts final LinkedList<String> folders = new LinkedList<String>(); final StringTokenizer st = new StringTokenizer(filePath, "/", false); String fileName = null; while (st.hasMoreTokens()) { final String pathComponent = st.nextToken(); if (st.hasMoreTokens()) { folders.addFirst(pathComponent); } else { // last token fileName = pathComponent; } } if (fileName == null) { return Collections.emptyList(); } final List<VirtualFile> target = findFilesClosestToTarget(folders, collectCandidates(project, fileName, true), MIN_PROXIMITY_THRESHOLD); return target.isEmpty() && file != null ? Collections.singletonList(file) : target; }
private Collection<String> parseIgnoredVariables() { final String s = myIgnoredVariables.getText(); final List<String> ignored = new ArrayList<String>(); final StringTokenizer st = new StringTokenizer(s, ";"); while (st.hasMoreElements()) { ignored.add(st.nextElement().trim()); } return ignored; }
private static void loadKeywords(Element element, Set<String> keywords) { String value = element.getAttributeValue(ELEMENT_KEYWORDS); if (value != null) { StringTokenizer tokenizer = new StringTokenizer(value, SEMICOLON); while(tokenizer.hasMoreElements()) { String keyword = tokenizer.nextToken().trim(); if (keyword.length() != 0) keywords.add(keyword); } } for (final Object o1 : element.getChildren(ELEMENT_KEYWORD)) { keywords.add(((Element)o1).getAttributeValue(ATTRIBUTE_NAME)); } }
/** * @param icon not <code>null</code> icon. * @param text to be painted under the <code>icon<code>. This parameter can * be <code>null</code> if text isn't specified. In that case <code>LabeledIcon</code> * @param mnemonic */ public LabeledIcon(Icon icon, String text, String mnemonic) { myIcon = icon; myMnemonic = mnemonic; if (text != null) { StringTokenizer tokenizer = new StringTokenizer(text, "\n"); myStrings = new String[tokenizer.countTokens()]; for (int i = 0; tokenizer.hasMoreTokens(); i++) { myStrings[i] = tokenizer.nextToken(); } } else { myStrings = null; } }
/** * @param icon not <code>null</code> icon. * @param text to be painted under the <code>icon<code>. This parameter can * be <code>null</code> if text isn't specified. In that case <code>LabeledIcon</code> */ public HorizontalLabeledIcon(Icon icon, String text, String mnemonic) { myIcon = icon; if (text != null) { StringTokenizer tokenizer = new StringTokenizer(text, "\n"); myStrings = new String[tokenizer.countTokens()]; for (int i = 0; tokenizer.hasMoreTokens(); i++) { myStrings[i] = tokenizer.nextToken(); } } else { myStrings = null; } myMnemonic = mnemonic; }
public void load(File file, String encoding) throws IOException{ String propText = FileUtil.loadFile(file, encoding); propText = StringUtil.convertLineSeparators(propText); StringTokenizer stringTokenizer = new StringTokenizer(propText, "\n"); while (stringTokenizer.hasMoreElements()){ String line = stringTokenizer.nextElement(); int i = line.indexOf('='); String propName = i == -1 ? line : line.substring(0,i); String propValue = i == -1 ? "" : line.substring(i+1); setProperty(propName, propValue); } }
private static void addAdditionalClassPath(Collection<URL> classpath) { try { StringTokenizer tokenizer = new StringTokenizer(System.getProperty(PROPERTY_ADDITIONAL_CLASSPATH, ""), File.pathSeparator + ",", false); while (tokenizer.hasMoreTokens()) { String pathItem = tokenizer.nextToken(); classpath.add(new File(pathItem).toURI().toURL()); } } catch (MalformedURLException e) { getLogger().error(e); } }
private static void addAdditionalClassPath(@NotNull Collection<URL> classpath) throws MalformedURLException { StringTokenizer tokenizer = new StringTokenizer(System.getProperty(PROPERTY_ADDITIONAL_CLASSPATH, ""), File.pathSeparator, false); while (tokenizer.hasMoreTokens()) { String pathItem = tokenizer.nextToken(); classpath.add(new File(pathItem).toURI().toURL()); } }
@NotNull public PsiReference[] createReferences(GenericDomValue<TargetResolver.Result> value, PsiElement element, ConvertContext context) { final XmlElement xmlElement = value.getXmlElement(); if (!(xmlElement instanceof XmlAttribute)) { return PsiReference.EMPTY_ARRAY; } final XmlAttributeValue valueElement = ((XmlAttribute)xmlElement).getValueElement(); if (valueElement == null) { return PsiReference.EMPTY_ARRAY; } final String refsString = value.getStringValue(); if (refsString == null) { return PsiReference.EMPTY_ARRAY; } final List<PsiReference> refs = new ArrayList<PsiReference>(); final AntDomTargetReference.ReferenceGroup group = new AntDomTargetReference.ReferenceGroup(); final TextRange wholeStringRange = ElementManipulators.getValueTextRange(valueElement); final StringTokenizer tokenizer = new StringTokenizer(refsString, ",", false); while (tokenizer.hasMoreTokens()) { final String token = tokenizer.nextToken(); int tokenStartOffset = tokenizer.getCurrentPosition() - token.length(); final String ref = token.trim(); if (ref.length() != token.length()) { for (int idx = 0; idx < token.length(); idx++) { if (Character.isWhitespace(token.charAt(idx))) { tokenStartOffset++; } else { break; } } } refs.add(new AntDomTargetReference(element, TextRange.from(wholeStringRange.getStartOffset() + tokenStartOffset, ref.length()), group)); } return refs.toArray(new PsiReference[refs.size()]); }
@Override public boolean isClassAvailable(final String[] urls, String fqn) { for (String url : urls) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file == null) continue; if (!(file.getFileSystem() instanceof JarFileSystem) && !file.isDirectory()) { file = JarFileSystem.getInstance().findFileByPath(file.getPath() + JarFileSystem.JAR_SEPARATOR); } if (file == null) continue; if (findInFile(file, new StringTokenizer(fqn, "."))) return true; } return false; }
public void readExternal(Element element) throws InvalidDataException { proportions.clear(); String prop = element.getAttributeValue(ATTRIBUTE_PROPORTIONS); String version = element.getAttributeValue(ATTRIBUTE_VERSION); if (prop != null && Comparing.equal(version, DATA_VERSION)) { StringTokenizer tokenizer = new StringTokenizer(prop, ","); while (tokenizer.hasMoreTokens()) { String p = tokenizer.nextToken(); proportions.add(Float.valueOf(p)); } } }