Java Code Examples for com.intellij.util.StringBuilderSpinAllocator

The following examples show how to use com.intellij.util.StringBuilderSpinAllocator. These examples are extracted from open source projects. 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 Project: sqlitemagic   Source File: SqliteMagicLightMethodBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private PsiMethod rebuildMethodFromString() {
  final StringBuilder builder = StringBuilderSpinAllocator.alloc();
  try {
    builder.append(getAllModifierProperties((LightModifierList) getModifierList()));
    PsiType returnType = getReturnType();
    if (null != returnType) {
      builder.append(returnType.getCanonicalText()).append(' ');
    }
    builder.append(getName());
    builder.append('(');
    if (getParameterList().getParametersCount() > 0) {
      for (PsiParameter parameter : getParameterList().getParameters()) {
        builder.append(parameter.getType().getCanonicalText()).append(' ').append(parameter.getName()).append(',');
      }
      builder.deleteCharAt(builder.length() - 1);
    }
    builder.append(')');
    builder.append('{').append("  ").append('}');

    PsiElementFactory elementFactory = JavaPsiFacade.getInstance(getManager().getProject()).getElementFactory();
    return elementFactory.createMethodFromText(builder.toString(), getContainingClass());
  } finally {
    StringBuilderSpinAllocator.dispose(builder);
  }
}
 
Example 2
@Nullable
static String readQualifiedName(final CharSequence charSequence, final Lexer lexer, boolean allowStar) {
  final StringBuilder buffer = StringBuilderSpinAllocator.alloc();
  try {
    while (true) {
      if (lexer.getTokenType() != HaxeTokenTypes.ID && !(allowStar && lexer.getTokenType() != HaxeTokenTypes.OMUL)) break;
      buffer.append(charSequence, lexer.getTokenStart(), lexer.getTokenEnd());
      if (lexer.getTokenType() == HaxeTokenTypes.OMUL) break;
      lexer.advance();
      if (lexer.getTokenType() != HaxeTokenTypes.ODOT) break;
      buffer.append('.');
      lexer.advance();
    }
    String packageName = buffer.toString();
    if (StringUtil.endsWithChar(packageName, '.')) return null;
    return packageName;
  }
  finally {
    StringBuilderSpinAllocator.dispose(buffer);
  }
}
 
Example 3
Source Project: consulo   Source File: CompilerPathsEx.java    License: Apache License 2.0 6 votes vote down vote up
protected void acceptDirectory(final VirtualFile file, final String fileRoot, final String filePath) {
  ProgressManager.checkCanceled();
  final VirtualFile[] children = file.getChildren();
  for (final VirtualFile child : children) {
    final String name = child.getName();
    final String _filePath;
    final StringBuilder buf = StringBuilderSpinAllocator.alloc();
    try {
      buf.append(filePath).append("/").append(name);
      _filePath = buf.toString();
    }
    finally {
      StringBuilderSpinAllocator.dispose(buf);
    }
    accept(child, fileRoot, _filePath);
  }
}
 
Example 4
Source Project: consulo   Source File: PackagingElementPath.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public String getPathStringFrom(String separator, @Nullable CompositePackagingElement<?> ancestor) {
  final StringBuilder builder = StringBuilderSpinAllocator.alloc();
  try {
    final List<CompositePackagingElement<?>> parents = getParentsFrom(ancestor);
    for (int i = parents.size() - 1; i >= 0; i--) {
      builder.append(parents.get(i).getName());
      if (i > 0) {
        builder.append(separator);
      }
    }
    return builder.toString();
  }
  finally {
    StringBuilderSpinAllocator.dispose(builder);
  }
}
 
Example 5
Source Project: consulo   Source File: ModuleChunk.java    License: Apache License 2.0 6 votes vote down vote up
public String getSourcePath(final int sourcesFilter) {
  if (getModuleCount() == 0) {
    return "";
  }
  final VirtualFile[] filteredRoots = getSourceRoots(sourcesFilter);
  final StringBuilder buffer = StringBuilderSpinAllocator.alloc();
  try {
    ApplicationManager.getApplication().runReadAction(new Runnable() {
      public void run() {
        for (VirtualFile root : filteredRoots) {
          if (buffer.length() > 0) {
            buffer.append(File.pathSeparatorChar);
          }
          buffer.append(root.getPath().replace('/', File.separatorChar));
        }
      }
    });
    return buffer.toString();
  }
  finally {
    StringBuilderSpinAllocator.dispose(buffer);
  }
}
 
Example 6
Source Project: consulo   Source File: LogFilterModel.java    License: Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private Pattern getCustomPattern() {
  String customFilter = getCustomFilter();
  if (myCustomPattern == null && customFilter != null) {
    final StringBuilder buf = StringBuilderSpinAllocator.alloc();
    try {
      for (int i = 0; i < customFilter.length(); i++) {
        final char c = customFilter.charAt(i);
        if (Character.isLetterOrDigit(c)) {
          buf.append(Character.toUpperCase(c));
        }
        else {
          buf.append("\\").append(c);
        }
      }
      myCustomPattern = Pattern.compile(".*" + buf + ".*", Pattern.DOTALL);
    }
    finally {
      StringBuilderSpinAllocator.dispose(buf);
    }
  }
  return myCustomPattern;
}
 
Example 7
public String composeTooltipMessage() {
  final StringBuilder buf = StringBuilderSpinAllocator.alloc();
  try {
    buf.append("<html><body>");
    if (myProblemDescriptions != null) {
      int problems = 0;
      for (ProjectStructureProblemDescription problemDescription : myProblemDescriptions) {
        buf.append(XmlStringUtil.escapeString(problemDescription.getMessage(false))).append("<br>");
        problems++;
        if (problems >= 10 && myProblemDescriptions.size() > 12) {
          buf.append(myProblemDescriptions.size() - problems).append(" more problems...<br>");
          break;
        }
      }
    }
    buf.append("</body></html>");
    return buf.toString();
  }
  finally {
    StringBuilderSpinAllocator.dispose(buf);
  }
}
 
Example 8
Source Project: consulo   Source File: PackagingElementNode.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void update(PresentationData presentation) {
  final Collection<ArtifactProblemDescription> problems = ((ArtifactEditorImpl)myContext.getThisArtifactEditor()).getValidationManager().getProblems(this);
  if (problems == null || problems.isEmpty()) {
    super.update(presentation);
    return;
  }
  StringBuilder buffer = StringBuilderSpinAllocator.alloc();
  final String tooltip;
  boolean isError = false;
  try {
    for (ArtifactProblemDescription problem : problems) {
      isError |= problem.getSeverity() == ProjectStructureProblemType.Severity.ERROR;
      buffer.append(problem.getMessage(false)).append("<br>");
    }
    tooltip = XmlStringUtil.wrapInHtml(buffer);
  }
  finally {
    StringBuilderSpinAllocator.dispose(buffer);
  }

  getElementPresentation().render(presentation, addErrorHighlighting(isError, SimpleTextAttributes.REGULAR_ATTRIBUTES),
                                  addErrorHighlighting(isError, SimpleTextAttributes.GRAY_ATTRIBUTES));
  presentation.setTooltip(tooltip);
}
 
Example 9
Source Project: sqlitemagic   Source File: SqliteMagicLightMethodBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public String getAllModifierProperties(LightModifierList modifierList) {
  final StringBuilder builder = StringBuilderSpinAllocator.alloc();
  try {
    for (String modifier : modifierList.getModifiers()) {
      if (!PsiModifier.PACKAGE_LOCAL.equals(modifier)) {
        builder.append(modifier).append(' ');
      }
    }
    return builder.toString();
  } finally {
    StringBuilderSpinAllocator.dispose(builder);
  }
}
 
Example 10
Source Project: consulo   Source File: CacheUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static String getMethodSignature(String name, String descriptor) {
  final StringBuilder builder = StringBuilderSpinAllocator.alloc();
  try {
    builder.append(name);
    builder.append(descriptor.substring(0, descriptor.indexOf(')') + 1));
    return builder.toString();
  }
  finally {
    StringBuilderSpinAllocator.dispose(builder);
  }
}
 
Example 11
Source Project: consulo   Source File: CompileDriver.java    License: Apache License 2.0 5 votes vote down vote up
private void showNotSpecifiedError(@NonNls final String resourceId, List<String> modules, String editorNameToSelect) {
  String nameToSelect = null;
  final StringBuilder names = StringBuilderSpinAllocator.alloc();
  final String message;
  try {
    final int maxModulesToShow = 10;
    for (String name : modules.size() > maxModulesToShow ? modules.subList(0, maxModulesToShow) : modules) {
      if (nameToSelect == null) {
        nameToSelect = name;
      }
      if (names.length() > 0) {
        names.append(",\n");
      }
      names.append("\"");
      names.append(name);
      names.append("\"");
    }
    if (modules.size() > maxModulesToShow) {
      names.append(",\n...");
    }
    message = CompilerBundle.message(resourceId, modules.size(), names.toString());
  }
  finally {
    StringBuilderSpinAllocator.dispose(names);
  }

  if (ApplicationManager.getApplication().isUnitTestMode()) {
    LOG.error(message);
  }

  Messages.showMessageDialog(myProject, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  showConfigurationDialog(nameToSelect, editorNameToSelect);
}