private static void checkEqualFunctionNames(
     @NotNull PsiNamedElement namedElement, @NotNull JavaMethod method) {
   if (!ComparatorUtil.equalsNullable(method.getName().asString(), namedElement.getName())) {
     throw new AlternativeSignatureMismatchException(
         "Function names mismatch, original: %s, alternative: %s",
         method.getName().asString(), namedElement.getName());
   }
 }
Esempio n. 2
0
 private static String getParentDeclarationDescription(DLanguageIdentifier o) {
   PsiNamedElement funcDecl =
       (PsiNamedElement) findParentOfType(o, DLanguageFuncDeclaration.class);
   PsiNamedElement classDecl =
       (PsiNamedElement) findParentOfType(o, DLanguageClassDeclaration.class);
   String description = "";
   if (funcDecl != null) {
     description = " [Function] (" + funcDecl.getName() + ")";
   }
   if (classDecl != null) {
     description = " [Class] (" + classDecl.getName() + ")";
   }
   return description;
 }
 @Nullable
 public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
   if (element instanceof AntTarget) {
     final PsiNamedElement psiNamedElement = (PsiNamedElement) element;
     return handleElementRename(psiNamedElement.getName());
   }
   throw new IncorrectOperationException("Can bind only to ant targets.");
 }
Esempio n. 4
0
 public static boolean processElement(PsiScopeProcessor processor, PsiNamedElement namedElement) {
   if (namedElement == null) return true;
   NameHint nameHint = processor.getHint(NameHint.KEY);
   String name = nameHint == null ? null : nameHint.getName(ResolveState.initial());
   if (name == null || name.equals(namedElement.getName())) {
     return processor.execute(namedElement, ResolveState.initial());
   }
   return true;
 }
    private void handleNamedElement(final PsiNamedElement named) {
      String name = named.getName();

      assert name != null;

      if (StructuralSearchUtil.isTypedVariable(name)) {
        name = name.substring(1, name.length() - 1);
      }

      if (!namedElements.containsKey(name)) namedElements.put(name, named);
      named.acceptChildren(this);
    }
 protected void suggestAllNames(final String oldClassName, String newClassName) {
   final NameSuggester suggester = new NameSuggester(oldClassName, newClassName);
   for (int varIndex = myElements.size() - 1; varIndex >= 0; varIndex--) {
     final PsiNamedElement element = myElements.get(varIndex);
     final String name = element.getName();
     if (!myRenames.containsKey(element)) {
       String newName = suggestNameForElement(element, suggester, newClassName, oldClassName);
       if (!newName.equals(name)) {
         myRenames.put(element, newName);
       } else {
         myRenames.put(element, null);
       }
     }
     if (myRenames.get(element) == null) {
       myElements.remove(varIndex);
     }
   }
 }
 public boolean execute(
     ReferencesSearch.SearchParameters params, final Processor<PsiReference> consumer) {
   final PsiElement elem = params.getElementToSearch();
   SearchScope scope = params.getEffectiveSearchScope();
   if (elem instanceof PsiNamedElement
       /* An optimization for Java refactorings */
       && !(elem instanceof PsiVariable)) {
     final PsiNamedElement symbolToSearch = (PsiNamedElement) elem;
     final String name = symbolToSearch.getName();
     if (name != null) {
       RequestResultProcessor processor =
           new RequestResultProcessor() {
             @Override
             public boolean processTextOccurrence(
                 @NotNull PsiElement element,
                 int offsetInElement,
                 @NotNull Processor<PsiReference> consumer) {
               if (element instanceof ClSymbol) {
                 ClSymbol refSymbol = (ClSymbol) element;
                 for (PsiReference ref : refSymbol.getReferences()) {
                   if (ref.getRangeInElement().contains(offsetInElement)
                       &&
                       // atom may refer to definition or to the symbol in it
                       (ref.resolve() == symbolToSearch
                           || ref.resolve() == symbolToSearch.getParent())) {
                     if (!consumer.process(ref)) return false;
                   }
                 }
               }
               return true;
             }
           };
       if (scope instanceof GlobalSearchScope) {
         scope =
             GlobalSearchScope.getScopeRestrictedByFileTypes(
                 (GlobalSearchScope) scope, ClojureFileType.CLOJURE_FILE_TYPE);
       }
       for (String word : StringUtil.getWordsIn(name)) {
         params.getOptimizer().searchWord(word, scope, UsageSearchContext.ANY, true, processor);
       }
     }
   }
   return true;
 }
 public static boolean isTooExpensiveToSearch(PsiNamedElement element, boolean zeroResult) {
   final String name = element.getName();
   if (name == null) {
     return true;
   }
   final ProgressManager progressManager = ProgressManager.getInstance();
   final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
   final SearchScope useScope = element.getUseScope();
   if (!(useScope instanceof GlobalSearchScope)) {
     return zeroResult;
   }
   final PsiSearchHelper.SearchCostResult cost =
       searchHelper.isCheapEnoughToSearch(
           name, (GlobalSearchScope) useScope, null, progressManager.getProgressIndicator());
   if (cost == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES) {
     return zeroResult;
   }
   return cost == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
 }
 protected String suggestNameForElement(
     PsiNamedElement element, NameSuggester suggester, String newClassName, String oldClassName) {
   String name = element.getName();
   if (oldClassName.equals(name)) {
     return newClassName;
   }
   String canonicalName = nameToCanonicalName(name, element);
   final String newCanonicalName = suggester.suggestName(canonicalName);
   if (newCanonicalName.length() == 0) {
     LOG.error(
         "oldClassName = "
             + oldClassName
             + ", newClassName = "
             + newClassName
             + ", name = "
             + name
             + ", canonicalName = "
             + canonicalName
             + ", newCanonicalName = "
             + newCanonicalName);
   }
   return canonicalNameToName(newCanonicalName, element);
 }
  @Override
  public Object[] getFileReferenceCompletionVariants(final FileReference reference) {
    final String s = reference.getText();
    if (s != null && s.equals("/")) {
      return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }

    final CommonProcessors.CollectUniquesProcessor<PsiFileSystemItem> collector =
        new CommonProcessors.CollectUniquesProcessor<PsiFileSystemItem>();
    final PsiElementProcessor<PsiFileSystemItem> processor =
        new PsiElementProcessor<PsiFileSystemItem>() {
          @Override
          public boolean execute(@NotNull PsiFileSystemItem fileSystemItem) {
            return new FilteringProcessor<PsiFileSystemItem>(
                    reference.getFileReferenceSet().getReferenceCompletionFilter(), collector)
                .process(FileReference.getOriginalFile(fileSystemItem));
          }
        };

    List<Object> additionalItems = ContainerUtil.newArrayList();
    for (PsiFileSystemItem context : reference.getContexts()) {
      for (final PsiElement child : context.getChildren()) {
        if (child instanceof PsiFileSystemItem) {
          processor.execute((PsiFileSystemItem) child);
        }
      }
      if (context instanceof FileReferenceResolver) {
        additionalItems.addAll(((FileReferenceResolver) context).getVariants(reference));
      }
    }

    final FileType[] types = reference.getFileReferenceSet().getSuitableFileTypes();
    final THashSet<PsiElement> set =
        new THashSet<PsiElement>(collector.getResults(), VARIANTS_HASHING_STRATEGY);
    final PsiElement[] candidates = PsiUtilCore.toPsiElementArray(set);

    final Object[] variants = new Object[candidates.length + additionalItems.size()];
    for (int i = 0; i < candidates.length; i++) {
      PsiElement candidate = candidates[i];
      Object item = reference.createLookupItem(candidate);
      if (item == null) {
        item = FileInfoManager.getFileLookupItem(candidate);
      }
      if (candidate instanceof PsiFile
          && item instanceof LookupElement
          && types.length > 0
          && ArrayUtil.contains(((PsiFile) candidate).getFileType(), types)) {
        item = PrioritizedLookupElement.withPriority((LookupElement) item, Double.MAX_VALUE);
      }
      variants[i] = item;
    }

    for (int i = 0; i < additionalItems.size(); i++) {
      variants[i + candidates.length] = additionalItems.get(i);
    }
    if (!reference.getFileReferenceSet().isUrlEncoded()) {
      return variants;
    }
    List<Object> encodedVariants = new ArrayList<Object>(variants.length + additionalItems.size());
    for (int i = 0; i < candidates.length; i++) {
      final PsiElement element = candidates[i];
      if (element instanceof PsiNamedElement) {
        final PsiNamedElement psiElement = (PsiNamedElement) element;
        String name = psiElement.getName();
        final String encoded = reference.encode(name, psiElement);
        if (encoded == null) continue;
        if (!encoded.equals(name)) {
          final Icon icon =
              psiElement.getIcon(Iconable.ICON_FLAG_READ_STATUS | Iconable.ICON_FLAG_VISIBILITY);
          LookupElementBuilder item =
              FileInfoManager.getFileLookupItem(candidates[i], encoded, icon);
          encodedVariants.add(item.withTailText(" (" + name + ")"));
        } else {
          encodedVariants.add(variants[i]);
        }
      }
    }
    encodedVariants.addAll(additionalItems);
    return ArrayUtil.toObjectArray(encodedVariants);
  }
 @NotNull
 private static AngularBindingDescriptor createBinding(PsiNamedElement field) {
   return new AngularBindingDescriptor(field, "[" + field.getName() + "]");
 }
 @NotNull
 private static AngularEventHandlerDescriptor createEvenHandler(PsiNamedElement field) {
   return new AngularEventHandlerDescriptor(field, "(" + field.getName() + ")");
 }
  /**
   * Tries to produce signature for the exact given PSI element.
   *
   * @param element target element
   * @param buffer buffer to store the signature in
   * @return buffer that contains signature of the given element if it was produced; <code>null
   *     </code> as an indication that signature for the given element was not produced
   */
  @SuppressWarnings("unchecked")
  @Nullable
  private static StringBuilder getSignature(
      @NotNull PsiElement element, @Nullable StringBuilder buffer) {
    if (element instanceof PsiNamedElement) {
      PsiNamedElement named = (PsiNamedElement) element;
      final String name = named.getName();
      if (StringUtil.isEmpty(name)) {
        return null;
      }
      int index = getChildIndex(named, element.getParent(), name, PsiNamedElement.class);
      StringBuilder bufferToUse = buffer;
      if (bufferToUse == null) {
        bufferToUse = new StringBuilder();
      }
      bufferToUse
          .append(TYPE_MARKER)
          .append(ELEMENT_TOKENS_SEPARATOR)
          .append(escape(name))
          .append(ELEMENT_TOKENS_SEPARATOR)
          .append(index);
      return bufferToUse;
    }
    if (element instanceof PsiComment) {
      PsiElement parent = element.getParent();
      boolean nestedComment = false;
      if (parent instanceof PsiComment && parent.getTextRange().equals(element.getTextRange())) {
        parent = parent.getParent();
        nestedComment = true;
      }
      if (parent instanceof PsiNamedElement
          && (nestedComment || parent.getFirstChild() == element)) {
        // Consider doc comment element that is the first child of named element to be a doc
        // comment.
        StringBuilder bufferToUse = buffer;
        if (bufferToUse == null) {
          bufferToUse = new StringBuilder();
        }
        bufferToUse.append(TYPE_MARKER).append(ELEMENT_TOKENS_SEPARATOR).append(DOC_COMMENT_MARKER);
        return bufferToUse;
      }
    }

    PsiElement parent = element.getParent();
    if (parent instanceof PsiNamedElement && !(parent instanceof PsiFile)) {
      if (isBlockElement(element)) {
        int index = getBlockElementIndex(element);
        StringBuilder bufferToUse = buffer;
        if (bufferToUse == null) {
          bufferToUse = new StringBuilder();
        }
        bufferToUse.append(TYPE_MARKER).append(ELEMENT_TOKENS_SEPARATOR).append(CODE_BLOCK_MARKER);
        if (index > 0) {
          bufferToUse.append(ELEMENT_TOKENS_SEPARATOR).append(index);
        }
        return bufferToUse;
      }
    }

    return null;
  }
Esempio n. 14
0
 public DReference(@NotNull PsiNamedElement element, TextRange textRange) {
   super(element, textRange);
   name = element.getName();
 }
 protected TLSchemaNamedElementReferenceBase(PsiNamedElement element, TextRange rangeInElement) {
   super(element, rangeInElement);
   myName = element.getName();
 }
 public MemberInplaceRenamer(
     @NotNull PsiNamedElement elementToRename, PsiElement substituted, Editor editor) {
   this(
       elementToRename, substituted, editor, elementToRename.getName(), elementToRename.getName());
 }