Java Code Examples for com.intellij.openapi.util.text.StringUtil#decapitalize()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#decapitalize() . 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: ExtensibleQueryFactory.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected ExtensibleQueryFactory(@NonNls final String epNamespace) {
  myPoint = new NotNullLazyValue<SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>>() {
    @Override
    @Nonnull
    protected SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>> compute() {
      return new SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>(new SmartList<QueryExecutor<Result, Parameters>>()){
        @Override
        @Nonnull
        protected ExtensionPoint<QueryExecutor<Result, Parameters>> getExtensionPoint() {
          String epName = ExtensibleQueryFactory.this.getClass().getName();
          int pos = epName.lastIndexOf('.');
          if (pos >= 0) {
            epName = epName.substring(pos+1);
          }
          epName = epNamespace + "." + StringUtil.decapitalize(epName);
          return Application.get().getExtensionPoint(ExtensionPointName.create(epName));
        }
      };
    }
  };
}
 
Example 2
Source File: ExtractSuperBaseDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected JComponent createActionComponent() {
  Box box = Box.createHorizontalBox();
  final String s = StringUtil.decapitalize(getEntityName());
  myRbExtractSuperclass = new JRadioButton();
  myRbExtractSuperclass.setText(RefactoringBundle.message("extractSuper.extract", s));
  myRbExtractSubclass = new JRadioButton();
  myRbExtractSubclass.setText(RefactoringBundle.message("extractSuper.rename.original.class", s));
  box.add(myRbExtractSuperclass);
  box.add(myRbExtractSubclass);
  box.add(Box.createHorizontalGlue());
  final ButtonGroup buttonGroup = new ButtonGroup();
  buttonGroup.add(myRbExtractSuperclass);
  buttonGroup.add(myRbExtractSubclass);
  customizeRadiobuttons(box, buttonGroup);
  myRbExtractSuperclass.setSelected(true);

  ItemListener listener = new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent e) {
      updateDialog();
    }
  };
  myRbExtractSuperclass.addItemListener(listener);
  myRbExtractSubclass.addItemListener(listener);
  return box;
}
 
Example 3
Source File: DirectiveUtil.java    From react-templates-plugin with MIT License 5 votes vote down vote up
public static String getAttributeName(final String text) {
    final String[] split = COMPILE.split(StringUtil.unquoteString(text));
    for (int i = 0; i < split.length; i++) {
        split[i] = StringUtil.decapitalize(split[i]);
    }
    return StringUtil.join(split, "-");
}
 
Example 4
Source File: DirectiveUtil.java    From react-templates-plugin with MIT License 5 votes vote down vote up
public static String getAttributeName(final String text) {
    final String[] split = COMPILE.split(StringUtil.unquoteString(text));
    for (int i = 0; i < split.length; i++) {
        split[i] = StringUtil.decapitalize(split[i]);
    }
    return StringUtil.join(split, "-");
}
 
Example 5
Source File: HaxeNameSuggesterUtil.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@NotNull
public static String prepareNameTextForSuggestions(@NotNull String name) {
  // Note: decapitalize only changes the first letter to lower case, but won't do if the second letter is also uppercase.
  name = StringUtil.decapitalize(deleteNonLetterFromString(StringUtil.unquoteString(name.replace('.', '_'))));

  StringBuilder prepped = new StringBuilder();
  int startPos = 0;
  int endPos = name.length() - 1;

  // Trim (skip past) underscores and common leading words.
  // (Leave an underscore or name if that is the entirety of the remaining text.)
  while (startPos < endPos && '_' == name.charAt(startPos)) ++startPos;
  while (endPos > startPos && '_' == name.charAt(endPos)) --endPos;
  for (String prefix : new String[]{"get", "is"}) {
    if (name.startsWith(prefix) && (endPos - startPos) > prefix.length()) {
      startPos += prefix.length();
    }
  }

  // Copy the string, removing consecutive underscores.
  char c = '_';  // Assume last char is '_' to skip any underscores after 'get' or 'is', as in get_myVar();
  for (int i = startPos; i <= endPos; i++) {
    if (c == '_' && name.charAt(i) == '_') continue;
    c = name.charAt(i);
    prepped.append(c);
  }

  return prepped.toString();
}
 
Example 6
Source File: AnalyzeDependenciesOnSpecifiedTargetHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean shouldShowDependenciesPanel(List<DependenciesBuilder> builders) {
  for (DependenciesBuilder builder : builders) {
    for (Set<PsiFile> files : builder.getDependencies().values()) {
      if (!files.isEmpty()) {
        return true;
      }
    }
  }
  final String source = StringUtil.decapitalize(builders.get(0).getScope().getDisplayName());
  final String target = StringUtil.decapitalize(myTargetScope.getDisplayName());
  final String message = AnalysisScopeBundle.message("no.dependencies.found.message", source, target);
  NotificationGroup.toolWindowGroup("Dependencies", ToolWindowId.DEPENDENCIES, true).createNotification(message, MessageType.INFO).notify(myProject);
  return false;
}
 
Example 7
Source File: NameSuggester.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String decapitalizeProbably(String word, String originalWord) {
  if (originalWord.length() == 0) return word;
  if (Character.isLowerCase(originalWord.charAt(0))) {
    return StringUtil.decapitalize(word);
  }
  return word;
}
 
Example 8
Source File: IntroduceVariableDialog.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private String[] calcVariants() {
  // TODO: build many names
  String suggestedName = "";

  for(int i = myIntroducedType.lastIndexOf(':') + 1; i < myIntroducedType.length(); ++i) {
    char ch = myIntroducedType.charAt(i);
    if(Character.isJavaIdentifierPart(ch)) suggestedName += ch;
  }

  suggestedName = StringUtil.decapitalize(suggestedName);
  return new String[] {suggestedName};
}
 
Example 9
Source File: UnityEditorCommunication.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
public static boolean request(@Nonnull Project project, @Nonnull Object postObject, boolean silent)
{
	UnityProcess editorProcess = findEditorProcess();

	if(editorProcess == null)
	{
		if(!silent)
		{
			Messages.showErrorDialog(project, "UnityEditor is not opened", "Consulo");
		}
		return false;
	}

	int port = editorProcess.getPort() + 2000;

	Gson gson = new Gson();
	String urlPart = postObject.getClass().getSimpleName();
	HttpPost post = new HttpPost("http://localhost:" + port + "/" + StringUtil.decapitalize(urlPart));
	post.setEntity(new StringEntity(gson.toJson(postObject), CharsetToolkit.UTF8_CHARSET));
	post.setHeader("Content-Type", "application/json");

	int timeOut = 5 * 1000;
	RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(timeOut).setConnectTimeout(timeOut).setSocketTimeout(timeOut).build();
	try(CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(requestConfig).build())
	{
		String data = client.execute(post, httpResponse -> EntityUtils.toString(httpResponse.getEntity(), CharsetToolkit.UTF8_CHARSET));

		UnityEditorResponse unityEditorResponse = gson.fromJson(data, UnityEditorResponse.class);
		if(!unityEditorResponse.success)
		{
			if(!silent)
			{
				Messages.showInfoMessage(project, "Unity cant execute this request", "Consulo");
			}
		}
		return unityEditorResponse.success;
	}
	catch(IOException e)
	{
		LOGGER.warn(e);

		if(!silent)
		{
			Messages.showErrorDialog(project, "UnityEditor is not opened", "Consulo");
		}
	}
	return false;
}
 
Example 10
Source File: InspectionTestCase.java    From idea-gitignore with MIT License 4 votes vote down vote up
private String name() {
    return StringUtil.decapitalize(StringUtil.trimEnd(StringUtil.trimStart(getClass().getSimpleName(), "Gitignore"), "InspectionTest"));
}
 
Example 11
Source File: RollbackAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void rollbackModifiedWithoutEditing(final Project project, final LinkedHashSet<VirtualFile> modifiedWithoutEditing) {
  final String operationName = StringUtil.decapitalize(UIUtil.removeMnemonic(RollbackUtil.getRollbackOperationName(project)));
  String message = (modifiedWithoutEditing.size() == 1)
                   ? VcsBundle.message("rollback.modified.without.editing.confirm.single",
                                       operationName, modifiedWithoutEditing.iterator().next().getPresentableUrl())
                   : VcsBundle.message("rollback.modified.without.editing.confirm.multiple",
                                       operationName, modifiedWithoutEditing.size());
  int rc = showYesNoDialog(project, message, VcsBundle.message("changes.action.rollback.title", operationName), getQuestionIcon());
  if (rc != Messages.YES) {
    return;
  }
  final List<VcsException> exceptions = new ArrayList<>();

  final ProgressManager progressManager = ProgressManager.getInstance();
  final Runnable action = new Runnable() {
    public void run() {
      final ProgressIndicator indicator = progressManager.getProgressIndicator();
      try {
        ChangesUtil.processVirtualFilesByVcs(project, modifiedWithoutEditing, (vcs, items) -> {
          final RollbackEnvironment rollbackEnvironment = vcs.getRollbackEnvironment();
          if (rollbackEnvironment != null) {
            if (indicator != null) {
              indicator.setText(vcs.getDisplayName() +
                                ": performing " + UIUtil.removeMnemonic(rollbackEnvironment.getRollbackOperationName()).toLowerCase() + "...");
              indicator.setIndeterminate(false);
            }
            rollbackEnvironment
                    .rollbackModifiedWithoutCheckout(items, exceptions, new RollbackProgressModifier(items.size(), indicator));
            if (indicator != null) {
              indicator.setText2("");
            }
          }
        });
      }
      catch (ProcessCanceledException e) {
        // for files refresh
      }
      if (!exceptions.isEmpty()) {
        AbstractVcsHelper.getInstance(project).showErrors(exceptions, VcsBundle.message("rollback.modified.without.checkout.error.tab",
                                                                                        operationName));
      }

      VfsUtil.markDirty(true, false, VfsUtilCore.toVirtualFileArray(modifiedWithoutEditing));

      VirtualFileManager.getInstance().asyncRefresh(new Runnable() {
        public void run() {
          for (VirtualFile virtualFile : modifiedWithoutEditing) {
            VcsDirtyScopeManager.getInstance(project).fileDirty(virtualFile);
          }
        }
      });
    }
  };
  progressManager.runProcessWithProgressSynchronously(action, operationName, true, project);
}
 
Example 12
Source File: LiveTemplateSettingsEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
private JPanel createShortContextPanel(final boolean allowNoContexts) {
  JPanel panel = new JPanel(new BorderLayout());

  final JLabel ctxLabel = new JLabel();
  final JLabel change = new JLabel();
  change.setForeground(JBColor.BLUE);
  change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  panel.add(ctxLabel, BorderLayout.CENTER);
  panel.add(change, BorderLayout.EAST);

  final Runnable updateLabel = new Runnable() {
    @Override
    public void run() {
      StringBuilder sb = new StringBuilder();
      String oldPrefix = "";
      for (TemplateContextType type : getApplicableContexts()) {
        final TemplateContextType base = type.getBaseContextType();
        String ownName = UIUtil.removeMnemonic(type.getPresentableName());
        String prefix = "";
        if (base != null && !(base instanceof EverywhereContextType)) {
          prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": ";
          ownName = StringUtil.decapitalize(ownName);
        }
        if (type instanceof EverywhereContextType) {
          ownName = "Other";
        }
        if (sb.length() > 0) {
          sb.append(oldPrefix.equals(prefix) ? ", " : "; ");
        }
        if (!oldPrefix.equals(prefix)) {
          sb.append(prefix);
          oldPrefix = prefix;
        }
        sb.append(ownName);
      }
      final boolean noContexts = sb.length() == 0;
      ctxLabel.setText((noContexts ? "No applicable contexts" + (allowNoContexts ? "" : " yet") : "Applicable in " + sb.toString()) + ".  ");
      ctxLabel.setForeground(noContexts ? allowNoContexts ? JBColor.GRAY : JBColor.RED : UIUtil.getLabelForeground());
      change.setText(noContexts ? "Define" : "Change");
    }
  };

  new ClickListener() {
    @Override
    public boolean onClick(MouseEvent e, int clickCount) {
      if (disposeContextPopup()) return false;

      final JPanel content = createPopupContextPanel(updateLabel);
      Dimension prefSize = content.getPreferredSize();
      if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) {
        content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height)));
      }
      myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup();
      myContextPopup.show(new RelativePoint(change, new Point(change.getWidth() , -content.getPreferredSize().height - 10)));
      myContextPopup.addListener(new JBPopupAdapter() {
        @Override
        public void onClosed(LightweightWindowEvent event) {
          myLastSize = content.getSize();
        }
      });
      return true;
    }
  }.installOn(change);

  updateLabel.run();

  return panel;
}
 
Example 13
Source File: UsageInModuleClasspath.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public String getPresentableLocationInElement() {
  return myScope != null && myScope != DependencyScope.COMPILE ? "[" + StringUtil.decapitalize(myScope.getDisplayName()) + "]" : null;
}
 
Example 14
Source File: ProjectStructureProblemDescription.java    From consulo with Apache License 2.0 4 votes vote down vote up
public String getMessage(final boolean includePlace) {
  if (includePlace && myCanShowPlace) {
    return myPlace.getContainingElement().getPresentableName() + ": " + StringUtil.decapitalize(myMessage);
  }
  return myMessage;
}
 
Example 15
Source File: ReplaceInProjectManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getLongDescriptiveName() {
  UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(myFindModel);
  return "Replace " + StringUtil.decapitalize(presentation.getToolwindowTitle()) + " with '" + myFindModel.getStringToReplace() + "'";
}