Java 类com.intellij.psi.util.PsiFormatUtil 实例源码

项目:intellij-ce-playground    文件:RefParameterImpl.java   
public void updateTemplateValue(PsiExpression expression) {
  if (myActualValueTemplate == null) return;

  String newTemplate = null;
  if (expression instanceof PsiLiteralExpression) {
    PsiLiteralExpression psiLiteralExpression = (PsiLiteralExpression) expression;
    newTemplate = psiLiteralExpression.getText();
  } else if (expression instanceof PsiReferenceExpression) {
    PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
    PsiElement resolved = referenceExpression.resolve();
    if (resolved instanceof PsiField) {
      PsiField psiField = (PsiField) resolved;
      if (psiField.hasModifierProperty(PsiModifier.STATIC) &&
          psiField.hasModifierProperty(PsiModifier.FINAL) &&
          psiField.getContainingClass().getQualifiedName() != null) {
        newTemplate = PsiFormatUtil.formatVariable(psiField, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_FQ_NAME, PsiSubstitutor.EMPTY);
      }
    }
  }

  if (myActualValueTemplate == VALUE_UNDEFINED) {
    myActualValueTemplate = newTemplate;
  } else if (!Comparing.equal(myActualValueTemplate, newTemplate)) {
    myActualValueTemplate = null;
  }
}
项目:intellij-ce-playground    文件:RefParameterImpl.java   
@Override
public String getExternalName() {
  final String[] result = new String[1];
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      PsiParameter parameter = getElement();
      LOG.assertTrue(parameter != null);
      result[0] = PsiFormatUtil.getExternalName(parameter);
    }
  };

  ApplicationManager.getApplication().runReadAction(runnable);

  return result[0];
}
项目:intellij-ce-playground    文件:JavaLookupElementBuilder.java   
public static LookupElementBuilder forMethod(@NotNull PsiMethod method,
                                             @NotNull String lookupString, final @NotNull PsiSubstitutor substitutor,
                                             @Nullable PsiClass qualifierClass) {
  LookupElementBuilder builder = LookupElementBuilder.create(method, lookupString)
    .withIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY))
    .withPresentableText(method.getName())
    .withTailText(PsiFormatUtil.formatMethod(method, substitutor,
                                             PsiFormatUtilBase.SHOW_PARAMETERS,
                                             PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE));
  final PsiType returnType = method.getReturnType();
  if (returnType != null) {
    builder = builder.withTypeText(substitutor.substitute(returnType).getPresentableText());
  }
  builder = setBoldIfInClass(method, qualifierClass, builder);
  return builder;
}
项目:intellij-ce-playground    文件:JavaDocInfoGenerator.java   
private void generateVariableJavaDoc(@NonNls StringBuilder buffer, PsiVariable variable, boolean generatePrologueAndEpilogue) {
  if (generatePrologueAndEpilogue)
    generatePrologue(buffer);

  buffer.append("<PRE>");
  String modifiers = PsiFormatUtil.formatModifiers(variable, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY);
  if (!modifiers.isEmpty()) {
    buffer.append(modifiers);
    buffer.append(" ");
  }
  generateType(buffer, variable.getType(), variable);
  buffer.append(" ");
  buffer.append("<b>");
  buffer.append(variable.getName());
  appendInitializer(buffer, variable);
  buffer.append("</b>");
  buffer.append("</PRE>");
  //buffer.append("<br>");

  ColorUtil.appendColorPreview(variable, buffer);

  if (generatePrologueAndEpilogue)
    generateEpilogue(buffer);
}
项目:intellij-ce-playground    文件:JavaDocumentationProvider.java   
private static String formatMethodSignature(PsiMethod method, boolean raw, boolean java8Format) {
  int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
  int parameterOptions = PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES;
  if (raw) {
    options |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE;
    parameterOptions |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE;
  }

  String signature = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, options, parameterOptions, 999);

  if (java8Format) {
    signature = signature.replaceAll("\\(|\\)|, ", "-").replaceAll("\\[\\]", ":A");
  }

  return signature;
}
项目:intellij-ce-playground    文件:MethodSmartPointerNode.java   
@Override
public void updateImpl(PresentationData data) {
  String name = PsiFormatUtil.formatMethod(
    (PsiMethod)getPsiElement(),
      PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME |
                            PsiFormatUtilBase.SHOW_TYPE |
                            PsiFormatUtilBase.TYPE_AFTER |
                            PsiFormatUtilBase.SHOW_PARAMETERS,
      PsiFormatUtilBase.SHOW_TYPE
  );
  int c = name.indexOf('\n');
  if (c > -1) {
    name = name.substring(0, c - 1);
  }
  data.setPresentableText(name);
}
项目:intellij-ce-playground    文件:PsiMethodNode.java   
@Override
public void updateImpl(PresentationData data) {
  String name = PsiFormatUtil.formatMethod(
    getValue(),
      PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME |
                            PsiFormatUtilBase.SHOW_TYPE |
                            PsiFormatUtilBase.TYPE_AFTER |
                            PsiFormatUtilBase.SHOW_PARAMETERS,
      PsiFormatUtilBase.SHOW_TYPE
  );
  int c = name.indexOf('\n');
  if (c > -1) {
    name = name.substring(0, c - 1);
  }
  data.setPresentableText(name);
}
项目:intellij-ce-playground    文件:MethodNode.java   
public String toString() {
  final PsiMethod method = (PsiMethod)getPsiElement();
  if (method == null || !method.isValid()) return "";
  if (DumbService.isDumb(myProject)) return method.getName();

  String name = PsiFormatUtil.formatMethod(
    method,
    PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER | PsiFormatUtil.SHOW_PARAMETERS,
    PsiFormatUtil.SHOW_TYPE
  );
  int c = name.indexOf('\n');
  if (c > -1) {
    name = name.substring(0, c - 1);
  }
  return name;
}
项目:intellij-ce-playground    文件:JavaMethodNode.java   
@Override
protected void customizeRendererText(ColoredTreeCellRenderer renderer) {
  final StringBuilder buffer = new StringBuilder(128);
  final PsiClass containingClass = myMethod.getContainingClass();
  if (containingClass != null) {
    buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false));
    buffer.append('.');
  }
  final String methodText = PsiFormatUtil.formatMethod(
    myMethod,
    PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
    PsiFormatUtil.SHOW_TYPE
  );
  buffer.append(methodText);

  final SimpleTextAttributes attributes = isEnabled() ?
                                          new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()) :
                                          SimpleTextAttributes.EXCLUDED_ATTRIBUTES;
  renderer.append(buffer.toString(), attributes);

  if (containingClass != null) {
    final String packageName = getPackageName(containingClass);
    renderer.append("  (" + packageName + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, JBColor.GRAY));
  }
}
项目:intellij-ce-playground    文件:MethodCellRenderer.java   
public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

  PsiMethod method = (PsiMethod) value;

  final String text = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY,
            PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
            PsiFormatUtil.SHOW_TYPE);
  setText(text);

  Icon icon = method.getIcon(Iconable.ICON_FLAG_VISIBILITY);
  if(icon != null) setIcon(icon);
  return this;
}
项目:intellij-ce-playground    文件:OverridingMethodsDialog.java   
public OverridingMethodsDialog(Project project, List<UsageInfo> overridingMethods) {
  super(project, true);
  myOverridingMethods = overridingMethods;
  myChecked = new boolean[myOverridingMethods.size()];
  for (int i = 0; i < myChecked.length; i++) {
    myChecked[i] = true;
  }

  myMethodText = new String[myOverridingMethods.size()];
  for (int i = 0; i < myMethodText.length; i++) {
    myMethodText[i] = PsiFormatUtil.formatMethod(
            ((SafeDeleteOverridingMethodUsageInfo) myOverridingMethods.get(i)).getOverridingMethod(),
            PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_CONTAINING_CLASS
                                  | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE,
            PsiFormatUtilBase.SHOW_TYPE
    );
  }
  myUsagePreviewPanel = new UsagePreviewPanel(project, new UsageViewPresentation());
  setTitle(RefactoringBundle.message("unused.overriding.methods.title"));
  init();
}
项目:intellij-ce-playground    文件:GroovyDocumentationProvider.java   
private static String getMethodCandidateInfo(GrReferenceExpression expr) {
  final GroovyResolveResult[] candidates = expr.multiResolve(false);
  final String text = expr.getText();
  if (candidates.length > 0) {
    @NonNls final StringBuilder sb = new StringBuilder();
    for (final GroovyResolveResult candidate : candidates) {
      final PsiElement element = candidate.getElement();
      if (!(element instanceof PsiMethod)) {
        continue;
      }
      final String str = PsiFormatUtil
        .formatMethod((PsiMethod)element, candidate.getSubstitutor(),
                      PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_PARAMETERS,
                      PsiFormatUtilBase.SHOW_TYPE);
      createElementLink(sb, element, str);
    }
    return CodeInsightBundle.message("javadoc.candidates", text, sb);
  }
  return CodeInsightBundle.message("javadoc.candidates.not.found", text);
}
项目:tools-idea    文件:JavaDocInfoGenerator.java   
private static void generateVariableJavaDoc(@NonNls StringBuilder buffer, PsiVariable variable, boolean generatePrologueAndEpilogue) {
  if (generatePrologueAndEpilogue)
    generatePrologue(buffer);

  buffer.append("<PRE>");
  String modifiers = PsiFormatUtil.formatModifiers(variable, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY);
  if (modifiers.length() > 0) {
    buffer.append(modifiers);
    buffer.append(" ");
  }
  generateType(buffer, variable.getType(), variable);
  buffer.append(" ");
  buffer.append("<b>");
  buffer.append(variable.getName());
  appendInitializer(buffer, variable);
  buffer.append("</b>");
  buffer.append("</PRE>");
  //buffer.append("<br>");

  ColorUtil.appendColorPreview(variable, buffer);

  if (generatePrologueAndEpilogue)
    generateEpilogue(buffer);
}
项目:tools-idea    文件:RefParameterImpl.java   
public void updateTemplateValue(PsiExpression expression) {
  if (myActualValueTemplate == null) return;

  String newTemplate = null;
  if (expression instanceof PsiLiteralExpression) {
    PsiLiteralExpression psiLiteralExpression = (PsiLiteralExpression) expression;
    newTemplate = psiLiteralExpression.getText();
  } else if (expression instanceof PsiReferenceExpression) {
    PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
    PsiElement resolved = referenceExpression.resolve();
    if (resolved instanceof PsiField) {
      PsiField psiField = (PsiField) resolved;
      if (psiField.hasModifierProperty(PsiModifier.STATIC) &&
          psiField.hasModifierProperty(PsiModifier.FINAL) &&
          psiField.getContainingClass().getQualifiedName() != null) {
        newTemplate = PsiFormatUtil.formatVariable(psiField, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_FQ_NAME, PsiSubstitutor.EMPTY);
      }
    }
  }

  if (myActualValueTemplate == VALUE_UNDEFINED) {
    myActualValueTemplate = newTemplate;
  } else if (!Comparing.equal(myActualValueTemplate, newTemplate)) {
    myActualValueTemplate = null;
  }
}
项目:tools-idea    文件:RefParameterImpl.java   
@Override
public String getExternalName() {
  final String[] result = new String[1];
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      PsiParameter parameter = getElement();
      LOG.assertTrue(parameter != null);
      result[0] = PsiFormatUtil.getExternalName(parameter);
    }
  };

  ApplicationManager.getApplication().runReadAction(runnable);

  return result[0];
}
项目:tools-idea    文件:JavaGenerateMemberCompletionContributor.java   
private static LookupElementBuilder createGenerateMethodElement(PsiMethod prototype,
                                                                PsiSubstitutor substitutor,
                                                                Icon icon,
                                                                String typeText, InsertHandler<LookupElement> insertHandler) {
  String methodName = prototype.getName();

  String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList());
  String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " ");

  PsiType type = substitutor.substitute(prototype.getReturnType());
  String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName;

  String parameters = PsiFormatUtil.formatMethod(prototype, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME);

  LookupElementBuilder element = LookupElementBuilder.create(prototype, signature).withLookupString(methodName).
    withLookupString(signature).withInsertHandler(insertHandler).
    appendTailText(parameters, false).appendTailText(" {...}", true).withTypeText(typeText).withIcon(icon);
  element.putUserData(GENERATE_ELEMENT, true);
  return element;
}
项目:tools-idea    文件:JavaLookupElementBuilder.java   
public static LookupElementBuilder forMethod(@NotNull PsiMethod method,
                                             @NotNull String lookupString, final @NotNull PsiSubstitutor substitutor,
                                             @Nullable PsiClass qualifierClass) {
  LookupElementBuilder builder = LookupElementBuilder.create(method, lookupString)
    .withIcon(method.getIcon(Iconable.ICON_FLAG_VISIBILITY))
    .withPresentableText(method.getName())
    .withTailText(PsiFormatUtil.formatMethod(method, substitutor,
                                             PsiFormatUtilBase.SHOW_PARAMETERS,
                                             PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE));
  final PsiType returnType = method.getReturnType();
  if (returnType != null) {
    builder = builder.withTypeText(substitutor.substitute(returnType).getPresentableText());
  }
  builder = setBoldIfInClass(method, qualifierClass, builder);
  return builder;
}
项目:tools-idea    文件:MethodSmartPointerNode.java   
@Override
public void updateImpl(PresentationData data) {
  String name = PsiFormatUtil.formatMethod(
    (PsiMethod)getPsiElement(),
      PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME |
                            PsiFormatUtilBase.SHOW_TYPE |
                            PsiFormatUtilBase.TYPE_AFTER |
                            PsiFormatUtilBase.SHOW_PARAMETERS,
      PsiFormatUtilBase.SHOW_TYPE
  );
  int c = name.indexOf('\n');
  if (c > -1) {
    name = name.substring(0, c - 1);
  }
  data.setPresentableText(name);
}
项目:tools-idea    文件:PsiMethodNode.java   
@Override
public void updateImpl(PresentationData data) {
  String name = PsiFormatUtil.formatMethod(
    getValue(),
      PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME |
                            PsiFormatUtilBase.SHOW_TYPE |
                            PsiFormatUtilBase.TYPE_AFTER |
                            PsiFormatUtilBase.SHOW_PARAMETERS,
      PsiFormatUtilBase.SHOW_TYPE
  );
  int c = name.indexOf('\n');
  if (c > -1) {
    name = name.substring(0, c - 1);
  }
  data.setPresentableText(name);
}
项目:tools-idea    文件:JavaMethodNode.java   
@Override
protected void customizeRendererText(ColoredTreeCellRenderer renderer) {
  final StringBuffer buffer = new StringBuffer(128);
  final PsiClass containingClass = myMethod.getContainingClass();
  if (containingClass != null) {
    buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false));
    buffer.append('.');
  }
  final String methodText = PsiFormatUtil.formatMethod(
    myMethod,
    PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
    PsiFormatUtil.SHOW_TYPE
  );
  buffer.append(methodText);

  final SimpleTextAttributes attributes = isEnabled() ?
                                          new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()) :
                                          SimpleTextAttributes.EXCLUDED_ATTRIBUTES;
  renderer.append(buffer.toString(), attributes);

  if (containingClass != null) {
    final String packageName = getPackageName(containingClass);
    renderer.append("  (" + packageName + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, JBColor.GRAY));
  }
}
项目:tools-idea    文件:MethodCellRenderer.java   
public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

  PsiMethod method = (PsiMethod) value;

  final String text = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY,
            PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
            PsiFormatUtil.SHOW_TYPE);
  setText(text);

  Icon icon = method.getIcon(Iconable.ICON_FLAG_VISIBILITY);
  if(icon != null) setIcon(icon);
  return this;
}
项目:tools-idea    文件:OverridingMethodsDialog.java   
public OverridingMethodsDialog(Project project, List<UsageInfo> overridingMethods) {
  super(project, true);
  myOverridingMethods = overridingMethods;
  myChecked = new boolean[myOverridingMethods.size()];
  for (int i = 0; i < myChecked.length; i++) {
    myChecked[i] = true;
  }

  myMethodText = new String[myOverridingMethods.size()];
  for (int i = 0; i < myMethodText.length; i++) {
    myMethodText[i] = PsiFormatUtil.formatMethod(
            ((SafeDeleteOverridingMethodUsageInfo) myOverridingMethods.get(i)).getOverridingMethod(),
            PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_CONTAINING_CLASS
                                  | PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS | PsiFormatUtil.SHOW_TYPE,
            PsiFormatUtil.SHOW_TYPE
    );
  }
  myUsagePreviewPanel = new UsagePreviewPanel(project);
  setTitle(RefactoringBundle.message("unused.overriding.methods.title"));
  init();
}
项目:tools-idea    文件:MethodList.java   
public MethodList(PsiClass psiClass)
{
    super(new BorderLayout());
    model = new SortedListModel<PsiMethod>(comparator);
    list = new JBList(model);
    this.psiClass = psiClass;
    evaluate(psiClass.getAllMethods(), new TestMethodFilter());
    add(ScrollPaneFactory.createScrollPane(list));
    list.setCellRenderer(new ColoredListCellRenderer() {

        @Override
        protected void customizeCellRenderer(JList jlist, Object obj, int i, boolean flag, boolean flag1)
        {
            PsiMethod psimethod = (PsiMethod)obj;
            append(PsiFormatUtil.formatMethod(psimethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME, 0), StructureNodeRenderer.applyDeprecation(psimethod, SimpleTextAttributes.REGULAR_ATTRIBUTES));
            PsiClass psiclass1 = psimethod.getContainingClass();
            if(!MethodList.this.psiClass.equals(psiclass1)) {
                append(" (" + psiclass1.getQualifiedName() + ')', StructureNodeRenderer.applyDeprecation(psiclass1, SimpleTextAttributes.GRAY_ATTRIBUTES));
            }
        }
    });
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    ListScrollingUtil.ensureSelectionExists(list);
}
项目:tools-idea    文件:GroovyDocumentationProvider.java   
private static String getMethodCandidateInfo(GrReferenceExpression expr) {
  final GroovyResolveResult[] candidates = expr.multiResolve(false);
  final String text = expr.getText();
  if (candidates.length > 0) {
    @NonNls final StringBuilder sb = new StringBuilder();
    for (final GroovyResolveResult candidate : candidates) {
      final PsiElement element = candidate.getElement();
      if (!(element instanceof PsiMethod)) {
        continue;
      }
      final String str = PsiFormatUtil
        .formatMethod((PsiMethod)element, candidate.getSubstitutor(),
                      PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_PARAMETERS,
                      PsiFormatUtilBase.SHOW_TYPE);
      createElementLink(sb, element, str);
    }
    return CodeInsightBundle.message("javadoc.candiates", text, sb);
  }
  return CodeInsightBundle.message("javadoc.candidates.not.found", text);
}
项目:consulo-java    文件:RefMethodImpl.java   
@Override
public String getExternalName()
{
    final String[] result = new String[1];
    final Runnable runnable = new Runnable()
    {
        @Override
        public void run()
        {
            final PsiMethod psiMethod = (PsiMethod) getElement();
            LOG.assertTrue(psiMethod != null);
            result[0] = PsiFormatUtil.getExternalName(psiMethod);
        }
    };

    ApplicationManager.getApplication().runReadAction(runnable);

    return result[0];
}
项目:consulo-java    文件:RefParameterImpl.java   
public void updateTemplateValue(PsiExpression expression) {
  if (myActualValueTemplate == null) return;

  String newTemplate = null;
  if (expression instanceof PsiLiteralExpression) {
    PsiLiteralExpression psiLiteralExpression = (PsiLiteralExpression) expression;
    newTemplate = psiLiteralExpression.getText();
  } else if (expression instanceof PsiReferenceExpression) {
    PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
    PsiElement resolved = referenceExpression.resolve();
    if (resolved instanceof PsiField) {
      PsiField psiField = (PsiField) resolved;
      if (psiField.hasModifierProperty(PsiModifier.STATIC) &&
          psiField.hasModifierProperty(PsiModifier.FINAL) &&
          psiField.getContainingClass().getQualifiedName() != null) {
        newTemplate = PsiFormatUtil.formatVariable(psiField, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_FQ_NAME, PsiSubstitutor.EMPTY);
      }
    }
  }

  if (myActualValueTemplate == VALUE_UNDEFINED) {
    myActualValueTemplate = newTemplate;
  } else if (!Comparing.equal(myActualValueTemplate, newTemplate)) {
    myActualValueTemplate = null;
  }
}
项目:consulo-java    文件:RefParameterImpl.java   
@Override
public String getExternalName() {
  final String[] result = new String[1];
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      PsiParameter parameter = getElement();
      LOG.assertTrue(parameter != null);
      result[0] = PsiFormatUtil.getExternalName(parameter);
    }
  };

  ApplicationManager.getApplication().runReadAction(runnable);

  return result[0];
}
项目:consulo-java    文件:XMLExportUtl.java   
private static void appendMethod(final RefMethod refMethod, Element parentNode) {
  Element methodElement = new Element(refMethod.isConstructor() ? "constructor" : "method");

  PsiMethod psiMethod = (PsiMethod)refMethod.getElement();
  String name = PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_FQ_NAME |
                                                                            PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.SHOW_PARAMETERS,
                                                                            PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE);

  Element shortNameElement = new Element("name");
  shortNameElement.addContent(name);
  methodElement.addContent(shortNameElement);

  Element displayName = new Element("name");
  displayName.addContent(refMethod.getQualifiedName());
  methodElement.addContent(displayName);

  appendClass(RefJavaUtil.getInstance().getTopLevelClass(refMethod), methodElement);

  parentNode.addContent(methodElement);
}
项目:consulo-java    文件:XMLExportUtl.java   
private static void appendField(final RefField refField, Element parentNode) {
  Element fieldElement = new Element("field");
  PsiField psiField = refField.getElement();
  String name = PsiFormatUtil.formatVariable(psiField, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE, PsiSubstitutor.EMPTY);

  Element shortNameElement = new Element("name");
  shortNameElement.addContent(name);
  fieldElement.addContent(shortNameElement);

  Element displayName = new Element("display_name");
  displayName.addContent(refField.getQualifiedName());
  fieldElement.addContent(displayName);

  appendClass(RefJavaUtil.getInstance().getTopLevelClass(refField), fieldElement);

  parentNode.addContent(fieldElement);
}
项目:consulo-java    文件:JavaGenerateMemberCompletionContributor.java   
private static LookupElementBuilder createGenerateMethodElement(PsiMethod prototype, PsiSubstitutor substitutor, Icon icon, String typeText, InsertHandler<LookupElement> insertHandler)
{
    String methodName = prototype.getName();

    String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList());
    String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " ");

    PsiType type = substitutor.substitute(prototype.getReturnType());
    String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName;

    String parameters = PsiFormatUtil.formatMethod(prototype, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME);

    String overrideSignature = " @Override " + signature; // leading space to make it a middle match, under all annotation suggestions
    LookupElementBuilder element = LookupElementBuilder.create(prototype, signature).withLookupString(methodName).
            withLookupString(signature).withLookupString(overrideSignature).withInsertHandler(insertHandler).
            appendTailText(parameters, false).appendTailText(" {...}", true).withTypeText(typeText).withIcon(icon);
    element.putUserData(GENERATE_ELEMENT, true);
    return element;
}
项目:consulo-java    文件:JavaLookupElementBuilder.java   
public static LookupElementBuilder forMethod(@NotNull PsiMethod method,
                                             @NotNull String lookupString, final @NotNull PsiSubstitutor substitutor,
                                             @Nullable PsiClass qualifierClass) {
  LookupElementBuilder builder = LookupElementBuilder.create(method, lookupString)
    .withIcon(IconDescriptorUpdaters.getIcon(method, Iconable.ICON_FLAG_VISIBILITY))
    .withPresentableText(method.getName())
    .withTailText(PsiFormatUtil.formatMethod(method, substitutor,
                                             PsiFormatUtilBase.SHOW_PARAMETERS,
                                             PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE));
  final PsiType returnType = method.getReturnType();
  if (returnType != null) {
    builder = builder.withTypeText(substitutor.substitute(returnType).getPresentableText());
  }
  builder = setBoldIfInClass(method, qualifierClass, builder);
  return builder;
}
项目:consulo-java    文件:JavaDocInfoGenerator.java   
private static void generateFieldSignature(StringBuilder buffer, PsiField field, boolean generateLink)
{
    generateAnnotations(buffer, field, generateLink, true, false);
    String modifiers = PsiFormatUtil.formatModifiers(field, PsiFormatUtilBase.JAVADOC_MODIFIERS_ONLY);
    if(!modifiers.isEmpty())
    {
        buffer.append(modifiers);
        buffer.append(" ");
    }
    generateType(buffer, field.getType(), field, generateLink);
    buffer.append(" ");
    buffer.append("<b>");
    buffer.append(field.getName());
    appendInitializer(buffer, field);
    enumConstantOrdinal(buffer, field, field.getContainingClass(), "\n");
    buffer.append("</b>");
}
项目:consulo-java    文件:JavaDocumentationProvider.java   
public static String formatMethodSignature(PsiMethod method, boolean raw, boolean java8Format)
{
    int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
    int parameterOptions = PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES;
    if(raw)
    {
        options |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE;
        parameterOptions |= PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE;
    }

    String signature = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, options, parameterOptions, 999);

    if(java8Format)
    {
        signature = signature.replaceAll("\\(|\\)|, ", "-").replaceAll("\\[\\]", ":A");
    }

    return signature;
}
项目:consulo-java    文件:MethodSmartPointerNode.java   
@Override
public void updateImpl(PresentationData data) {
  String name = PsiFormatUtil.formatMethod(
    (PsiMethod)getPsiElement(),
      PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME |
                            PsiFormatUtilBase.SHOW_TYPE |
                            PsiFormatUtilBase.TYPE_AFTER |
                            PsiFormatUtilBase.SHOW_PARAMETERS,
      PsiFormatUtilBase.SHOW_TYPE
  );
  int c = name.indexOf('\n');
  if (c > -1) {
    name = name.substring(0, c - 1);
  }
  data.setPresentableText(name);
}
项目:consulo-java    文件:ClassTreeNode.java   
@Override
public void updateImpl(PresentationData data)
{
    final PsiClass aClass = getValue();
    if(aClass != null)
    {
        if(aClass.hasTypeParameters())
        {
            StringBuilder builder = new StringBuilder();
            builder.append(aClass.getName());
            PsiFormatUtil.formatTypeParameters(aClass, builder, PsiFormatUtilBase.SHOW_TYPE_PARAMETER_EXTENDS);
            data.setPresentableText(builder.toString());
        }
        else
        {
            data.setPresentableText(aClass.getName());
        }
    }
}
项目:consulo-java    文件:PsiMethodNode.java   
@Override
public void updateImpl(PresentationData data) {
  String name = PsiFormatUtil.formatMethod(
    getValue(),
      PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME |
                            PsiFormatUtilBase.SHOW_TYPE |
                            PsiFormatUtilBase.TYPE_AFTER |
                            PsiFormatUtilBase.SHOW_TYPE_PARAMETERS |
                            PsiFormatUtilBase.SHOW_TYPE_PARAMETER_EXTENDS |
                            PsiFormatUtilBase.SHOW_PARAMETERS,
      PsiFormatUtilBase.SHOW_TYPE
  );
  int c = name.indexOf('\n');
  if (c > -1) {
    name = name.substring(0, c - 1);
  }
  data.setPresentableText(name);
}
项目:consulo-java    文件:JavaMethodNode.java   
@Override
protected void customizeRendererText(ColoredTreeCellRenderer renderer) {
  final StringBuffer buffer = new StringBuffer(128);
  final PsiClass containingClass = myMethod.getContainingClass();
  if (containingClass != null) {
    buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false));
    buffer.append('.');
  }
  final String methodText = PsiFormatUtil.formatMethod(
    myMethod,
    PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
    PsiFormatUtil.SHOW_TYPE
  );
  buffer.append(methodText);

  final SimpleTextAttributes attributes = isEnabled() ?
                                          new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()) :
                                          SimpleTextAttributes.EXCLUDED_ATTRIBUTES;
  renderer.append(buffer.toString(), attributes);

  if (containingClass != null) {
    final String packageName = getPackageName(containingClass);
    renderer.append("  (" + packageName + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, JBColor.GRAY));
  }
}
项目:consulo-java    文件:MethodCellRenderer.java   
public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

  PsiMethod method = (PsiMethod) value;

  final String text = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY,
            PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
            PsiFormatUtil.SHOW_TYPE);
  setText(text);

  Icon icon = IconDescriptorUpdaters.getIcon(method, Iconable.ICON_FLAG_VISIBILITY);
  if(icon != null) setIcon(icon);
  return this;
}
项目:consulo-java    文件:OverridingMethodsDialog.java   
public OverridingMethodsDialog(Project project, List<UsageInfo> overridingMethods)
{
    super(project, true);
    myOverridingMethods = overridingMethods;
    myChecked = new boolean[myOverridingMethods.size()];
    for(int i = 0; i < myChecked.length; i++)
    {
        myChecked[i] = true;
    }

    myMethodText = new String[myOverridingMethods.size()];
    for(int i = 0; i < myMethodText.length; i++)
    {
        myMethodText[i] = PsiFormatUtil.formatMethod(((SafeDeleteOverridingMethodUsageInfo) myOverridingMethods.get(i)).getOverridingMethod(),
                PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS
                | PsiFormatUtilBase.SHOW_TYPE, PsiFormatUtilBase.SHOW_TYPE);
    }
    myUsagePreviewPanel = new UsagePreviewPanel(project, new UsageViewPresentation());
    setTitle(RefactoringBundle.message("unused.overriding.methods.title"));
    init();
}
项目:consulo-java    文件:PsiMethodListPopupStep.java   
@Override
@NotNull
public String getTextFor(SmartStepTarget value)
{
    final String label = value.getLabel();
    final String formatted;
    if(value instanceof MethodSmartStepTarget)
    {
        final PsiMethod method = ((MethodSmartStepTarget) value).getMethod();
        formatted = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
                PsiFormatUtil.SHOW_TYPE, 999);
    }
    else if(value instanceof LambdaSmartStepTarget)
    {
        final PsiLambdaExpression lambda = ((LambdaSmartStepTarget) value).getLambda();
        formatted = PsiFormatUtil.formatType(lambda.getType(), 0, PsiSubstitutor.EMPTY);
    }
    else
    {
        formatted = "";
    }
    return label != null ? label + formatted : formatted;
}