com.intellij.util.text.StringTokenizer Java Examples

The following examples show how to use com.intellij.util.text.StringTokenizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsoleViewUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
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();
  }
}
 
Example #2
Source File: HaxeCommonCompilerUtil.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private static List<String> generateNmeCommand(CompilationContext context) {

    final List<String> commandLine = new ArrayList<>();
    final String haxelibPath = context.getHaxelibPath();
    commandLine.add(haxelibPath);

    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());
    }
    return commandLine;
  }
 
Example #3
Source File: HaxeCompilerServices.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private void formatAndAddCompilerArguments(ArrayList<String> commandLineArguments, String flags) {
    if (null != flags && !flags.isEmpty()) {
        final StringTokenizer flagsTokenizer = new StringTokenizer(flags);
        while (flagsTokenizer.hasMoreTokens()) {
            String nextToken = flagsTokenizer.nextToken();
            if (!nextToken.isEmpty()) {
                commandLineArguments.add(nextToken);
            }
        }
    }
}
 
Example #4
Source File: EncodingAwareProperties.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example #5
Source File: HorizontalLabeledIcon.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example #6
Source File: AbstractFileType.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void loadKeywords(Element element, Set<? super 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.isEmpty()) keywords.add(keyword);
    }
  }
  for (final Object o1 : element.getChildren(ELEMENT_KEYWORD)) {
    keywords.add(((Element)o1).getAttributeValue(ATTRIBUTE_NAME));
  }
}
 
Example #7
Source File: PathMacroListEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #8
Source File: LibraryUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #9
Source File: SplitterProportionsDataImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public SplitterProportionsDataImpl fromString(@Nonnull String value) {
  SplitterProportionsDataImpl data = new SplitterProportionsDataImpl();
  StringTokenizer tokenizer = new StringTokenizer(value, ",");
  while (tokenizer.hasMoreTokens()) {
    data.proportions.add(Float.valueOf(tokenizer.nextToken()));
  }
  return data;
}
 
Example #10
Source File: SplitterProportionsDataImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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));
    }
  }
}
 
Example #11
Source File: VfsTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static VirtualFile createFileOrDir(final VirtualFile root, final String relativePath, final String text, final boolean dir) {
  try {
    return Application.get().runWriteAction((ThrowableComputable<VirtualFile, IOException>)() -> {
      VirtualFile parent = root;
      Assert.assertNotNull(parent);
      StringTokenizer parents = new StringTokenizer(PathUtil.getParentPath(relativePath), "/");
      while (parents.hasMoreTokens()) {
        final String name = parents.nextToken();
        VirtualFile child = parent.findChild(name);
        if (child == null || !child.isValid()) {
          child = parent.createChildDirectory(VfsTestUtil.class, name);
        }
        parent = child;
      }
      final VirtualFile file;
      parent.getChildren();//need this to ensure that fileCreated event is fired
      if (dir) {
        file = parent.createChildDirectory(VfsTestUtil.class, PathUtil.getFileName(relativePath));
      }
      else {
        file = parent.createChildData(VfsTestUtil.class, PathUtil.getFileName(relativePath));
        if (!text.isEmpty()) {
          VfsUtil.saveText(file, text);
        }
      }
      return file;
    });
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #12
Source File: TestsLocationProviderUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
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();
  }
  return findFilesClosestToTarget(folders, collectCandidates(project, fileName, true), MIN_PROXIMITY_THRESHOLD);
}
 
Example #13
Source File: HaxeCommonCompilerUtil.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private static List<String> generateUserPropertiesCommand(CompilationContext context) {

    final List<String> commandLine = new ArrayList<String>();
    final String sdkExePath = HaxeSdkUtilBase.getCompilerPathByFolderPath(context.getSdkHomePath());
    commandLine.add(sdkExePath);


    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(calculateOutputPath(context));
    return commandLine;
  }
 
Example #14
Source File: NMERunningState.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private HaxeCommandLine getCommandForNeko(Sdk sdk, HaxeModuleSettings settings) throws ExecutionException {
  final HaxeSdkData sdkData = sdk.getSdkAdditionalData() instanceof HaxeSdkData ? (HaxeSdkData)sdk.getSdkAdditionalData() : null;
  if (sdkData == null) {
    throw new ExecutionException(HaxeCommonBundle.message("invalid.haxe.sdk"));
  }
  final HaxeCommandLine commandLine = new HaxeCommandLine(module);

  commandLine.setWorkDirectory(PathUtil.getParentPath(module.getModuleFilePath()));
  final String haxelibPath = sdkData.getHaxelibPath();
  if (haxelibPath == null || haxelibPath.isEmpty()) {
    throw new ExecutionException(HaxeCommonBundle.message("no.haxelib.for.sdk", sdk.getName()));
  }
  commandLine.setExePath(haxelibPath);
  commandLine.addParameter("run");
  commandLine.addParameter("nme");
  commandLine.addParameter(myRunInTest ? "test" : "run");
  commandLine.addParameter(settings.getNmmlPath());
  for (String flag : settings.getNmeTarget().getFlags()) {
    commandLine.addParameter(flag);
  }
  if (myDebug) {
    commandLine.addParameter("-debug");
    commandLine.addParameter("-Ddebug");
    commandLine.addParameter("-args");
    commandLine.addParameter("-start_debugger");
    commandLine.addParameter("-debugger_host=localhost:" + myDebugPort);
  }

  final StringTokenizer flagsTokenizer = new StringTokenizer(settings.getNmeFlags());
  while (flagsTokenizer.hasMoreTokens()) {
    commandLine.addParameter(flagsTokenizer.nextToken());
  }

  final TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(module.getProject());
  setConsoleBuilder(consoleBuilder);
  return commandLine;
}
 
Example #15
Source File: LibraryUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isClassAvailableInLibrary(List<VirtualFile> files, final String fqn) {
  for (VirtualFile file : files) {
    if (findInFile(file, new StringTokenizer(fqn, "."))) return true;
  }
  return false;
}
 
Example #16
Source File: HaxeCommonCompilerUtil.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
private static List<List<String>> generateOpenflCommands(CompilationContext context) {

    final String haxelibPath = context.getHaxelibPath();
    final HaxeModuleSettingsBase settings = context.getModuleSettings();

    List<List<String>> clList = new ArrayList<>();

    String cmds[] = {"update", "build"};
    for (String cmd : cmds) {

      List<String> commandLine = new ArrayList<>();
      commandLine.add(haxelibPath);

      commandLine.add("run");
      commandLine.add("lime");
      commandLine.add(cmd);

      // XXX: Isn't this an error if the openfl project file is missing?
      if(!StringUtil.isEmpty(settings.getOpenFLPath())) {
        commandLine.add(settings.getOpenFLPath());
      }

      commandLine.add(settings.getOpenFLTarget().getTargetFlag());

      commandLine.add("-verbose");

      if (context.isDebug()) {
        commandLine.add("-debug");
        commandLine.add("-Ddebug");

        if (settings.getOpenFLTarget() == OpenFLTarget.FLASH) {
          commandLine.add("-Dfdb");
        }
      }

      final StringTokenizer flagsTokenizer = new StringTokenizer(settings.getOpenFLFlags());
      while (flagsTokenizer.hasMoreTokens()) {
        commandLine.add(flagsTokenizer.nextToken());
      }

      clList.add(commandLine);
    }
    return clList;
  }
 
Example #17
Source File: OpenFLRunningState.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
private HaxeCommandLine getCommandForOpenFL(Sdk sdk, HaxeModuleSettings settings) throws ExecutionException {
  final HaxeSdkData sdkData = sdk.getSdkAdditionalData() instanceof HaxeSdkData ? (HaxeSdkData)sdk.getSdkAdditionalData() : null;
  if (sdkData == null) {
    throw new ExecutionException(HaxeCommonBundle.message("invalid.haxe.sdk"));
  }
  final HaxeCommandLine commandLine = new HaxeCommandLine(module);

  commandLine.setWorkDirectory(PathUtil.getParentPath(module.getModuleFilePath()));
  final String haxelibPath = sdkData.getHaxelibPath();
  if (haxelibPath == null || haxelibPath.isEmpty()) {
    throw new ExecutionException(HaxeCommonBundle.message("no.haxelib.for.sdk", sdk.getName()));
  }

  commandLine.setExePath(haxelibPath);
  commandLine.addParameter("run");
  commandLine.addParameter("lime");
  commandLine.addParameter(myRunInTest ? "test" : "run");

  if(!StringUtil.isEmpty(settings.getOpenFLPath())) {
    commandLine.addParameter(settings.getOpenFLPath());
  }

  for (String flag : settings.getOpenFLTarget().getFlags()) {
    commandLine.addParameter(flag);
  }

  commandLine.addParameter("-verbose");

  if (myDebug) {
    commandLine.addParameter("-Ddebug");
    commandLine.addParameter("-debug");

    if (settings.getOpenFLTarget() == OpenFLTarget.FLASH) {
      commandLine.addParameter("-Dfdb");
    }
    else {
      commandLine.addParameter("-args");
      commandLine.addParameter("-start_debugger");
      commandLine.addParameter("-debugger_host=localhost:" + myDebugPort);
    }
  }

  final StringTokenizer flagsTokenizer = new StringTokenizer(settings.getOpenFLFlags());
  while (flagsTokenizer.hasMoreTokens()) {
    commandLine.addParameter(flagsTokenizer.nextToken());
  }

  final TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(module.getProject());
  setConsoleBuilder(consoleBuilder);
  return commandLine;
}
 
Example #18
Source File: ChromeParser.java    From JHelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void projectOpened() {
	try {
		server = new SimpleHttpServer(
				new InetSocketAddress("localhost", PORT),
				request -> {
					StringTokenizer st = new StringTokenizer(request);
					String type = st.nextToken();
					Parser parser = PARSERS.get(type);
					if (parser == null) {
						Notificator.showNotification(
								"Unknown parser",
								"Parser " + type + " unknown, request ignored",
								NotificationType.INFORMATION
						);
						return;
					}
					String page = request.substring(st.getCurrentPosition());
					Collection<Task> tasks = parser.parseTaskFromHTML(page);
					if (tasks.isEmpty()) {
						Notificator.showNotification(
								"Couldn't parse any task",
								"Maybe format changed?",
								NotificationType.WARNING
						);
					}

					Configurator configurator = project.getComponent(Configurator.class);
					Configurator.State configuration = configurator.getState();
					String path = configuration.getTasksDirectory();
					for (Task rawTask : tasks) {
						TaskData task = new TaskData(
								rawTask.name,
								rawTask.taskClass,
								String.format("%s/%s.cpp", path, rawTask.taskClass),
								rawTask.input,
								rawTask.output,
								rawTask.testType,
								rawTask.tests
						);
						PsiElement generatedFile = TaskUtils.saveNewTask(task, project);
						UIUtils.openMethodInEditor(project, (OCFile) generatedFile, "solve");
					}

					IDEUtils.reloadProject(project);
				}
		);

		new Thread(server, "ChromeParserThread").start();
	}
	catch (IOException ignored) {
		Notificator.showNotification(
				"Could not create serverSocket for Chrome parser",
				"Probably another CHelper or JHelper project is running?",
				NotificationType.ERROR
		);
	}
}
 
Example #19
Source File: DocumentFoldingInfo.java    From consulo with Apache License 2.0 4 votes vote down vote up
void readExternal(final Element element) {
  ApplicationManager.getApplication().runReadAction(() -> {
    clear();

    if (!myFile.isValid()) return;

    final Document document = FileDocumentManager.getInstance().getDocument(myFile);
    if (document == null) return;

    String date = null;
    for (final Element e : element.getChildren()) {
      String signature = e.getAttributeValue(SIGNATURE_ATT);
      if (signature == null) {
        continue;
      }

      boolean expanded = Boolean.parseBoolean(e.getAttributeValue(EXPANDED_ATT));
      if (ELEMENT_TAG.equals(e.getName())) {
        myInfos.add(new Info(signature, expanded));
      }
      else if (MARKER_TAG.equals(e.getName())) {
        if (date == null) {
          date = getTimeStamp();
        }
        if (date.isEmpty()) continue;

        if (!date.equals(e.getAttributeValue(DATE_ATT)) || FileDocumentManager.getInstance().isDocumentUnsaved(document)) continue;
        StringTokenizer tokenizer = new StringTokenizer(signature, ":");
        try {
          int start = Integer.valueOf(tokenizer.nextToken()).intValue();
          int end = Integer.valueOf(tokenizer.nextToken()).intValue();
          if (start < 0 || end >= document.getTextLength() || start > end) continue;
          RangeMarker marker = document.createRangeMarker(start, end);
          myRangeMarkers.add(marker);
          String placeholderAttributeValue = e.getAttributeValue(PLACEHOLDER_ATT);
          String placeHolderText = placeholderAttributeValue == null ? DEFAULT_PLACEHOLDER : XmlStringUtil.unescapeIllegalXmlChars(placeholderAttributeValue);
          FoldingInfo fi = new FoldingInfo(placeHolderText, expanded);
          marker.putUserData(FOLDING_INFO_KEY, fi);
        }
        catch (NoSuchElementException exc) {
          LOG.error(exc);
        }
      }
      else {
        throw new IllegalStateException("unknown tag: " + e.getName());
      }
    }
  });
}
 
Example #20
Source File: MyLookupItem.java    From CppTools with Apache License 2.0 4 votes vote down vote up
public MyLookupItem(String s) {
  try {
    StringTokenizer tokenizer = new StringTokenizer(s, Communicator.DELIMITER_STRING);
    final String completionType = tokenizer.nextElement();

    name = tokenizer.nextToken();
    signature = tokenizer.nextToken();
    boolean hasFileNameInTypeSignature = false;
    boolean takeReturnOrDeclarationType = false;

    if ("func".equals(completionType)) {
      icon = Icons.METHOD_ICON;
      takeReturnOrDeclarationType = true;
    } else if ("var".equals(completionType)) {
      icon = Icons.VARIABLE_ICON;
      takeReturnOrDeclarationType = true;
    } else if ("type".equals(completionType)) {
      icon = Icons.CLASS_ICON;
    } else if ("macro".equals(completionType)) {
      icon = macroIcon;
      hasFileNameInTypeSignature = true;
    } else if ("macro-param".equals(completionType)) {
      icon = Icons.PARAMETER_ICON;
    } else if ("filename".equals(completionType)) {
      icon = Icons.FILE_ICON;
      hasFileNameInTypeSignature = true;
    }  else if ("dirname".equals(completionType)) {
      icon = Icons.DIRECTORY_OPEN_ICON;
      hasFileNameInTypeSignature = true;
    }

    if (!hasFileNameInTypeSignature && takeReturnOrDeclarationType) {
      final int i = signature.indexOf(name);
      
      if (i != -1) {
        type = signature.substring(0, i).trim();
      } else {
        final int spaceIndex = signature.indexOf(' ');
        type = signature.substring(0, spaceIndex != -1 ? spaceIndex:signature.length());
      }
    } else {
      type = signature;
    }
    
    if (type != null && type.length() > 50) {
      StringBuilder builder = new StringBuilder(50);
      builder.append(type.substring(0, 15));
      builder.append("...");
      builder.append(type.substring(type.length() - 35, type.length()));
      type = builder.toString();
    }
  } catch (NoSuchElementException e1) {
    throw e1;
  }
}