public void testTypingDoesNotInterfereWithDuplicates() throws Exception { SliceTreeStructure treeStructure = configureTree("DupSlice"); SliceNode root = (SliceNode) treeStructure.getRootElement(); List<SliceNode> nodes = new ArrayList<SliceNode>(); expandNodesTo(root, nodes); for (int i = 0; i < nodes.size() - 1; i++) { SliceNode node = nodes.get(i); assertNull(node.getDuplicate()); } SliceNode last = nodes.get(nodes.size() - 1); assertNotNull(last.getDuplicate()); type(" xx"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); backspace(); backspace(); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); nodes.clear(); expandNodesTo(root, nodes); for (int i = 0; i < nodes.size() - 1; i++) { SliceNode node = nodes.get(i); assertNull(node.getDuplicate()); } assertNotNull(last.getDuplicate()); }
private static String buildAllMethodNamesString( String allMethodNames, List<MethodEntry> parents) { StringBuffer allMN = new StringBuffer(120); allMN.append(allMethodNames); if (allMN.length() > 0) { allMN.append("."); } if (parents.size() > 1) { allMN.append("["); } { boolean first = true; for (MethodEntry entry : parents) { if (!first) { allMN.append(","); } first = false; allMN.append(((PsiMethod) entry.myEnd).getName()); } } if (parents.size() > 1) { allMN.append("]"); } return allMN.toString(); }
@Override public UsageView showUsages( UsageInfo[] usages, UsageViewPresentation presentation, UsageViewManager manager, PsiElement[] elements) { final List<PsiElement> overridingMethods = new ArrayList<>(); final List<UsageInfo> others = new ArrayList<>(); for (UsageInfo usage : usages) { if (usage instanceof SafeDeleteOverridingMethodUsageInfo) { overridingMethods.add(((SafeDeleteOverridingMethodUsageInfo) usage).getOverridingMethod()); } else { others.add(usage); } } UsageTarget[] targets = new UsageTarget[elements.length + overridingMethods.size()]; for (int i = 0; i < targets.length; i++) { if (i < elements.length) { targets[i] = new PsiElement2UsageTargetAdapter(elements[i]); } else { targets[i] = new PsiElement2UsageTargetAdapter(overridingMethods.get(i - elements.length)); } } return manager.showUsages( targets, UsageInfoToUsageConverter.convert(elements, others.toArray(new UsageInfo[others.size()])), presentation); }
@NotNull public List<String> createConversions(@NotNull PsiCallExpression expression) { PsiExpressionList argumentList = expression.getArgumentList(); PsiExpression[] arguments = argumentList != null ? argumentList.getExpressions() : new PsiExpression[] {}; List<String> conversions = new LinkedList<String>(); //noinspection UnusedDeclaration for (PsiExpression a : arguments) { conversions.add(""); } PsiMethod resolve = expression.resolveMethod(); if (resolve != null) { List<PsiType> expectedTypes = new LinkedList<PsiType>(); List<PsiType> actualTypes = new LinkedList<PsiType>(); for (PsiParameter p : resolve.getParameterList().getParameters()) expectedTypes.add(p.getType()); for (PsiExpression e : arguments) actualTypes.add(e.getType()); if (conversions.size() == actualTypes.size() && actualTypes.size() == expectedTypes.size()) { for (int i = 0; i < actualTypes.size(); i++) conversions.set(i, createConversionForExpression(arguments[i], expectedTypes.get(i))); } } return conversions; }
private <T> boolean findListToRemoveFrom( @NotNull String name, @NotNull final List<T> elements, final Convertor<T, AbstractUrl> convertor) { Collection<TreeItem<Pair<AbstractUrl, String>>> list = getFavoritesListRootUrls(name); if (elements.size() > 1) { final List<T> sublist = elements.subList(0, elements.size() - 1); for (T obj : sublist) { AbstractUrl objUrl = convertor.convert(obj); final TreeItem<Pair<AbstractUrl, String>> item = findNextItem(objUrl, list); if (item == null || item.getChildren() == null) return false; list = item.getChildren(); } } TreeItem<Pair<AbstractUrl, String>> found = null; AbstractUrl url = convertor.convert(elements.get(elements.size() - 1)); if (url == null) return false; for (TreeItem<Pair<AbstractUrl, String>> pair : list) { if (url.equals(pair.getData().getFirst())) { found = pair; break; } } if (found != null) { list.remove(found); fireListeners.rootsChanged(name); return true; } return false; }
@Override public void visitListOrMap(GrListOrMap listOrMap) { if (listOrMap.isMap()) return; final TypeConstraint[] constraints = calculateTypeConstraints(listOrMap); List<PsiType> result = new ArrayList<PsiType>(constraints.length); for (TypeConstraint constraint : constraints) { if (constraint instanceof SubtypeConstraint) { final PsiType type = constraint.getType(); final PsiType iterable = com.intellij.psi.util.PsiUtil.extractIterableTypeParameter(type, true); if (iterable != null) { result.add(iterable); } } } if (result.size() == 0) { myResult = TypeConstraint.EMPTY_ARRAY; } else { myResult = new TypeConstraint[result.size()]; for (int i = 0; i < result.size(); i++) { final PsiType type = result.get(i); if (type != null) { myResult[i] = SubtypeConstraint.create(type); } } } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DocumentFoldingInfo info = (DocumentFoldingInfo) o; if (myFile != null ? !myFile.equals(info.myFile) : info.myFile != null) { return false; } if (!myProject.equals(info.myProject) || !myPsiElements.equals(info.myPsiElements) || !mySerializedElements.equals(info.mySerializedElements)) { return false; } if (myRangeMarkers.size() != info.myRangeMarkers.size()) return false; for (int i = 0; i < myRangeMarkers.size(); i++) { RangeMarker marker = myRangeMarkers.get(i); RangeMarker other = info.myRangeMarkers.get(i); if (marker == other || !marker.isValid() || !other.isValid()) { continue; } if (!TextRange.areSegmentsEqual(marker, other)) return false; FoldingInfo fi = marker.getUserData(FOLDING_INFO_KEY); FoldingInfo ofi = other.getUserData(FOLDING_INFO_KEY); if (!Comparing.equal(fi, ofi)) return false; } return true; }
@Nullable private PsiDirectory chooseDirectory(final Project project, final PsiFile file) { PsiDirectory preferredDirectory = myWritableDirectoryList.isEmpty() ? null : myWritableDirectoryList.get(0); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final VirtualFile virtualFile = file.getVirtualFile(); assert virtualFile != null; final Module moduleForFile = fileIndex.getModuleForFile(virtualFile); if (myWritableDirectoryList.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode()) { if (moduleForFile != null) { for (PsiDirectory directory : myWritableDirectoryList) { if (fileIndex.getModuleForFile(directory.getVirtualFile()) == moduleForFile) { preferredDirectory = directory; break; } } } return DirectoryChooserUtil.chooseDirectory( myWritableDirectoryList.toArray(new PsiDirectory[myWritableDirectoryList.size()]), preferredDirectory, project, new HashMap<PsiDirectory, String>()); } return preferredDirectory; }
@Override public void addEntryPoint(@NotNull RefElement newEntryPoint, boolean isPersistent) { if (!newEntryPoint.isValid()) return; if (isPersistent) { if (newEntryPoint instanceof RefMethod && ((RefMethod) newEntryPoint).isConstructor() || newEntryPoint instanceof RefClass) { final ClassPattern classPattern = new ClassPattern(); classPattern.pattern = new SmartRefElementPointerImpl(newEntryPoint, true).getFQName(); getPatterns().add(classPattern); final EntryPointsManager entryPointsManager = getInstance(newEntryPoint.getElement().getProject()); if (this != entryPointsManager) { entryPointsManager.addEntryPoint(newEntryPoint, true); } return; } } if (newEntryPoint instanceof RefClass) { RefClass refClass = (RefClass) newEntryPoint; if (refClass.isAnonymous()) { // Anonymous class cannot be an entry point. return; } List<RefMethod> refConstructors = refClass.getConstructors(); if (refConstructors.size() == 1) { addEntryPoint(refConstructors.get(0), isPersistent); } else if (refConstructors.size() > 1) { // Many constructors here. Need to ask user which ones are used for (RefMethod refConstructor : refConstructors) { addEntryPoint(refConstructor, isPersistent); } } } if (!isPersistent) { myTemporaryEntryPoints.add(newEntryPoint); ((RefElementImpl) newEntryPoint).setEntry(true); } else { if (myPersistentEntryPoints.get(newEntryPoint.getExternalName()) == null) { final SmartRefElementPointerImpl entry = new SmartRefElementPointerImpl(newEntryPoint, true); myPersistentEntryPoints.put(entry.getFQName(), entry); ((RefElementImpl) newEntryPoint).setEntry(true); ((RefElementImpl) newEntryPoint).setPermanentEntry(true); if (entry.isPersistent()) { // do save entry points final EntryPointsManager entryPointsManager = getInstance(newEntryPoint.getElement().getProject()); if (this != entryPointsManager) { entryPointsManager.addEntryPoint(newEntryPoint, true); } } } } }
/** a = S & a = T imply S = T */ private void eqEq(List<PsiType> eqBounds) { for (int i = 0; i < eqBounds.size(); i++) { PsiType sBound = eqBounds.get(i); for (int j = i + 1; j < eqBounds.size(); j++) { final PsiType tBound = eqBounds.get(j); addConstraint(new TypeEqualityConstraint(tBound, sBound)); } } }
public String toString() { return "MethodEntry " + myEnd.toString() + "; calls " + myCalledMethods.size() + ", called by " + myCalledByMethods.size() + ", nParameters=" + nParameters; }
public static ClassFilter[] readFilters(List<Element> children) throws InvalidDataException { if (ContainerUtil.isEmpty(children)) { return ClassFilter.EMPTY_ARRAY; } ClassFilter[] filters = new ClassFilter[children.size()]; for (int i = 0, size = children.size(); i < size; i++) { filters[i] = create(children.get(i)); } return filters; }
@Override public void generatePlaces() { final PatternCompiler<PsiElement> compiler = getCompiler(); List<String> patternString = getPatternString(this); InjectionPlace[] places = InjectionPlace.ARRAY_FACTORY.create(patternString.size()); for (int i = 0, patternStringSize = patternString.size(); i < patternStringSize; i++) { String text = patternString.get(i); places[i] = new InjectionPlace(compiler.createElementPattern(text, getDisplayName()), true); } setInjectionPlaces(places); }
public static ClassFilter[] readFilters(List children) throws InvalidDataException { if (children == null || children.size() == 0) { return ClassFilter.EMPTY_ARRAY; } List<ClassFilter> classFiltersList = new ArrayList<ClassFilter>(children.size()); for (Iterator i = children.iterator(); i.hasNext(); ) { final ClassFilter classFilter = new ClassFilter(); classFilter.readExternal((Element) i.next()); classFiltersList.add(classFilter); } return classFiltersList.toArray(new ClassFilter[classFiltersList.size()]); }
public void removeRootByIndexes(String name, List<Integer> elementsIndexes) { List<TreeItem<Pair<AbstractUrl, String>>> list = getFavoritesListRootUrls(name); assert list != null; for (Integer index : elementsIndexes.subList(0, elementsIndexes.size() - 1)) { assert index >= 0 && index < list.size(); final TreeItem<Pair<AbstractUrl, String>> item = list.get(index); list = item.getChildren(); } assert list != null && !list.isEmpty(); list.remove(elementsIndexes.get(elementsIndexes.size() - 1).intValue()); fireListeners.rootsChanged(name); }
/** Return class names form jet sources in given scope which should be visible as Java classes. */ @NotNull @Override public PsiClass[] getClassesByName( @NotNull @NonNls String name, @NotNull GlobalSearchScope scope) { List<PsiClass> result = new ArrayList<PsiClass>(); IDELightClassGenerationSupport lightClassGenerationSupport = IDELightClassGenerationSupport.getInstanceForIDE(project); MultiMap<String, FqName> packageClasses = lightClassGenerationSupport.getAllPackageClasses(scope); // .namespace classes can not be indexed, since they have no explicit declarations Collection<FqName> fqNames = packageClasses.get(name); if (!fqNames.isEmpty()) { for (FqName fqName : fqNames) { PsiClass psiClass = JavaElementFinder.getInstance(project).findClass(fqName.getFqName(), scope); if (psiClass != null) { result.add(psiClass); } } } // Quick check for classes from getAllClassNames() Collection<JetClassOrObject> classOrObjects = JetShortClassNameIndex.getInstance().get(name, project, scope); if (classOrObjects.isEmpty()) { return result.toArray(new PsiClass[result.size()]); } for (JetClassOrObject classOrObject : classOrObjects) { FqName fqName = JetPsiUtil.getFQName(classOrObject); if (fqName != null) { assert fqName.shortName().getName().equals(name) : "A declaration obtained from index has non-matching name:\n" + "in index: " + name + "\n" + "declared: " + fqName.shortName() + "(" + fqName + ")"; PsiClass psiClass = JavaElementFinder.getInstance(project).findClass(fqName.getFqName(), scope); if (psiClass != null) { result.add(psiClass); } } } return result.toArray(new PsiClass[result.size()]); }
private static void processCallerMethod( JavaChangeInfo changeInfo, PsiMethod caller, PsiMethod baseMethod, boolean toInsertParams, boolean toInsertThrows) throws IncorrectOperationException { LOG.assertTrue(toInsertParams || toInsertThrows); if (toInsertParams) { List<PsiParameter> newParameters = new ArrayList<PsiParameter>(); ContainerUtil.addAll(newParameters, caller.getParameterList().getParameters()); final JavaParameterInfo[] primaryNewParms = changeInfo.getNewParameters(); PsiSubstitutor substitutor = baseMethod == null ? PsiSubstitutor.EMPTY : ChangeSignatureProcessor.calculateSubstitutor(caller, baseMethod); for (JavaParameterInfo info : primaryNewParms) { if (info.getOldIndex() < 0) newParameters.add(createNewParameter(changeInfo, info, substitutor)); } PsiParameter[] arrayed = newParameters.toArray(new PsiParameter[newParameters.size()]); boolean[] toRemoveParm = new boolean[arrayed.length]; Arrays.fill(toRemoveParm, false); resolveParameterVsFieldsConflicts(arrayed, caller, caller.getParameterList(), toRemoveParm); } if (toInsertThrows) { List<PsiJavaCodeReferenceElement> newThrowns = new ArrayList<PsiJavaCodeReferenceElement>(); final PsiReferenceList throwsList = caller.getThrowsList(); ContainerUtil.addAll(newThrowns, throwsList.getReferenceElements()); final ThrownExceptionInfo[] primaryNewExns = changeInfo.getNewExceptions(); for (ThrownExceptionInfo thrownExceptionInfo : primaryNewExns) { if (thrownExceptionInfo.getOldIndex() < 0) { final PsiClassType type = (PsiClassType) thrownExceptionInfo.createType(caller, caller.getManager()); final PsiJavaCodeReferenceElement ref = JavaPsiFacade.getInstance(caller.getProject()) .getElementFactory() .createReferenceElementByType(type); newThrowns.add(ref); } } PsiJavaCodeReferenceElement[] arrayed = newThrowns.toArray(new PsiJavaCodeReferenceElement[newThrowns.size()]); boolean[] toRemoveParm = new boolean[arrayed.length]; Arrays.fill(toRemoveParm, false); ChangeSignatureUtil.synchronizeList( throwsList, Arrays.asList(arrayed), ThrowsList.INSTANCE, toRemoveParm); } }
private static boolean elementListsEqual(List<Element> l1, List<Element> l2) { if (l1 == null) return l2 == null; if (l2 == null) return false; if (l1.size() != l2.size()) return false; Iterator<Element> i1 = l1.iterator(); for (Element aL2 : l2) { Element elem1 = i1.next(); if (!elementsEqual(elem1, aL2)) return false; } return true; }
private static PsiAnnotationMemberValue[] readFromClass( @NonNls String attributeName, @NotNull PsiAnnotation magic, PsiType type) { PsiAnnotationMemberValue fromClassAttr = magic.findAttributeValue(attributeName); PsiType fromClassType = fromClassAttr instanceof PsiClassObjectAccessExpression ? ((PsiClassObjectAccessExpression) fromClassAttr).getOperand().getType() : null; PsiClass fromClass = fromClassType instanceof PsiClassType ? ((PsiClassType) fromClassType).resolve() : null; if (fromClass == null) return null; String fqn = fromClass.getQualifiedName(); if (fqn == null) return null; List<PsiAnnotationMemberValue> constants = new ArrayList<PsiAnnotationMemberValue>(); for (PsiField field : fromClass.getFields()) { if (!field.hasModifierProperty(PsiModifier.PUBLIC) || !field.hasModifierProperty(PsiModifier.STATIC) || !field.hasModifierProperty(PsiModifier.FINAL)) continue; PsiType fieldType = field.getType(); if (!Comparing.equal(fieldType, type)) continue; PsiAssignmentExpression e = (PsiAssignmentExpression) JavaPsiFacade.getElementFactory(field.getProject()) .createExpressionFromText("x=" + fqn + "." + field.getName(), field); PsiReferenceExpression refToField = (PsiReferenceExpression) e.getRExpression(); constants.add(refToField); } if (constants.isEmpty()) return null; return constants.toArray(new PsiAnnotationMemberValue[constants.size()]); }
private static void logStats(Collection<PsiFile> otherFiles, long start) { long time = System.currentTimeMillis() - start; final Multiset<String> stats = HashMultiset.create(); for (PsiFile file : otherFiles) { stats.add( StringUtil.notNullize(file.getViewProvider().getVirtualFile().getExtension()) .toLowerCase()); } List<String> extensions = ContainerUtil.newArrayList(stats.elementSet()); Collections.sort( extensions, new Comparator<String>() { @Override public int compare(String o1, String o2) { return stats.count(o2) - stats.count(o1); } }); String message = "Search in " + otherFiles.size() + " files with unknown types took " + time + "ms.\n" + "Mapping their extensions to an existing file type (e.g. Plain Text) might speed up the search.\n" + "Most frequent non-indexed file extensions: "; for (int i = 0; i < Math.min(10, extensions.size()); i++) { String extension = extensions.get(i); message += extension + "(" + stats.count(extension) + ") "; } LOG.info(message); }
@NotNull public UsageInfo[] findUsages() { myRenamers.clear(); ArrayList<UsageInfo> result = new ArrayList<UsageInfo>(); List<PsiElement> elements = new ArrayList<PsiElement>(myAllRenames.keySet()); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < elements.size(); i++) { PsiElement element = elements.get(i); final String newName = myAllRenames.get(element); final UsageInfo[] usages = RenameUtil.findUsages( element, newName, mySearchInComments, mySearchTextOccurrences, myAllRenames); final List<UsageInfo> usagesList = Arrays.asList(usages); result.addAll(usagesList); for (AutomaticRenamerFactory factory : myRenamerFactories) { if (factory.isApplicable(element)) { myRenamers.add(factory.createRenamer(element, newName, usagesList)); } } for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) { if (factory.getOptionName() == null && factory.isApplicable(element)) { myRenamers.add(factory.createRenamer(element, newName, usagesList)); } } } UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]); usageInfos = UsageViewUtil.removeDuplicatedUsages(usageInfos); return usageInfos; }
@NotNull @Override public GroovyResolveResult[] getCandidates() { if (!hasCandidates()) return GroovyResolveResult.EMPTY_ARRAY; final GroovyResolveResult[] results = ResolveUtil.filterSameSignatureCandidates(getCandidatesInternal()); List<GroovyResolveResult> list = new ArrayList<GroovyResolveResult>(results.length); myPropertyNames.removeAll(myPreferredFieldNames); Set<String> usedFields = ContainerUtil.newHashSet(); for (GroovyResolveResult result : results) { final PsiElement element = result.getElement(); if (element instanceof PsiField) { final String name = ((PsiField) element).getName(); if (myPropertyNames.contains(name) || myLocalVars.contains(name) || usedFields.contains(name)) { continue; } else { usedFields.add(name); } } list.add(result); } return list.toArray(new GroovyResolveResult[list.size()]); }
@Override @Nullable public PsiClass[] getUnThrownExceptions() { if (getRefManager().isOfflineView()) { LOG.debug("Should not traverse graph offline"); } if (myUnThrownExceptions == null) return null; JavaPsiFacade facade = JavaPsiFacade.getInstance(myManager.getProject()); List<PsiClass> result = new ArrayList<PsiClass>(myUnThrownExceptions.size()); for (String exception : myUnThrownExceptions) { PsiClass element = facade.findClass(exception, GlobalSearchScope.allScope(myManager.getProject())); if (element != null) result.add(element); } return result.toArray(new PsiClass[result.size()]); }
public void updateThrowsList(PsiClassType exceptionType) { if (!getSuperMethods().isEmpty()) { for (RefMethod refSuper : getSuperMethods()) { ((RefMethodImpl) refSuper).updateThrowsList(exceptionType); } } else if (myUnThrownExceptions != null) { if (exceptionType == null) { myUnThrownExceptions = null; return; } PsiClass exceptionClass = exceptionType.resolve(); JavaPsiFacade facade = JavaPsiFacade.getInstance(myManager.getProject()); for (int i = myUnThrownExceptions.size() - 1; i >= 0; i--) { String exceptionFqn = myUnThrownExceptions.get(i); PsiClass classType = facade.findClass( exceptionFqn, GlobalSearchScope.allScope(getRefManager().getProject())); if (InheritanceUtil.isInheritorOrSelf(exceptionClass, classType, true) || InheritanceUtil.isInheritorOrSelf(classType, exceptionClass, true)) { myUnThrownExceptions.remove(i); } } if (myUnThrownExceptions.isEmpty()) myUnThrownExceptions = null; } }
private void processUsagesPerFile(UsageInfo[] usages) { Map<PsiFile, List<EncapsulateFieldUsageInfo>> usagesInFiles = new HashMap<PsiFile, List<EncapsulateFieldUsageInfo>>(); for (UsageInfo usage : usages) { PsiElement element = usage.getElement(); if (element == null) continue; final PsiFile file = element.getContainingFile(); List<EncapsulateFieldUsageInfo> usagesInFile = usagesInFiles.get(file); if (usagesInFile == null) { usagesInFile = new ArrayList<EncapsulateFieldUsageInfo>(); usagesInFiles.put(file, usagesInFile); } usagesInFile.add(((EncapsulateFieldUsageInfo) usage)); } for (List<EncapsulateFieldUsageInfo> usageInfos : usagesInFiles.values()) { // this is to avoid elements to become invalid as a result of processUsage final EncapsulateFieldUsageInfo[] infos = usageInfos.toArray(new EncapsulateFieldUsageInfo[usageInfos.size()]); CommonRefactoringUtil.sortDepthFirstRightLeftOrder(infos); for (EncapsulateFieldUsageInfo info : infos) { EncapsulateFieldHelper helper = EncapsulateFieldHelper.getHelper(info.getElement().getLanguage()); helper.processUsage( info, myDescriptor, myNameToSetter.get(info.getFieldDescriptor().getSetterName()), myNameToGetter.get(info.getFieldDescriptor().getGetterName())); } } }
private static PsiClassType[] filterCheckedExceptions(PsiClassType[] exceptions) { List<PsiClassType> result = new ArrayList<PsiClassType>(); for (PsiClassType exceptionType : exceptions) { if (!ExceptionUtil.isUncheckedException(exceptionType)) result.add(exceptionType); } return result.toArray(new PsiClassType[result.size()]); }
@NotNull private static PsiSubstitutor replaceVariables(Collection<InferenceVariable> inferenceVariables) { final List<InferenceVariable> targetVars = new ArrayList<InferenceVariable>(); PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; final InferenceVariable[] oldVars = inferenceVariables.toArray(new InferenceVariable[inferenceVariables.size()]); for (InferenceVariable variable : oldVars) { final InferenceVariable newVariable = new InferenceVariable( variable.getCallContext(), variable.getParameter(), variable.getName()); substitutor = substitutor.put( variable, JavaPsiFacade.getElementFactory(variable.getProject()).createType(newVariable)); targetVars.add(newVariable); if (variable.isThrownBound()) { newVariable.setThrownBound(); } } for (int i = 0; i < targetVars.size(); i++) { InferenceVariable var = targetVars.get(i); for (InferenceBound boundType : InferenceBound.values()) { for (PsiType bound : oldVars[i].getBounds(boundType)) { var.addBound(substitutor.substitute(bound), boundType, null); } } } return substitutor; }
@NotNull public static String buildStringToFindForIndicesFromRegExp( @NotNull String stringToFind, @NotNull Project project) { if (!Registry.is("idea.regexp.search.uses.indices")) return ""; final AccessToken accessToken = ReadAction.start(); try { final List<PsiElement> topLevelRegExpChars = getTopLevelRegExpChars("a", project); if (topLevelRegExpChars.size() != 1) return ""; // leave only top level regExpChars return StringUtil.join( getTopLevelRegExpChars(stringToFind, project), new Function<PsiElement, String>() { final Class regExpCharPsiClass = topLevelRegExpChars.get(0).getClass(); @Override public String fun(PsiElement element) { return regExpCharPsiClass.isInstance(element) ? element.getText() : " "; } }, ""); } finally { accessToken.finish(); } }
@NotNull public static PsiClassType[] getImplementsListTypes(GrTypeDefinition grType) { Set<PsiClass> visited = new HashSet<PsiClass>(); List<PsiClassType> result = new ArrayList<PsiClassType>(); getImplementListsInner(grType, result, visited); return result.toArray(new PsiClassType[result.size()]); }
@NotNull public static PsiElement[] findSuperElements(@NotNull PsiElement element) { if (element instanceof PsiClass) { PsiClass aClass = (PsiClass) element; List<PsiClass> allSupers = new ArrayList<>(Arrays.asList(aClass.getSupers())); for (Iterator<PsiClass> iterator = allSupers.iterator(); iterator.hasNext(); ) { PsiClass superClass = iterator.next(); if (CommonClassNames.JAVA_LANG_OBJECT.equals(superClass.getQualifiedName())) iterator.remove(); } return allSupers.toArray(new PsiClass[allSupers.size()]); } if (element instanceof PsiMethod) { PsiMethod method = (PsiMethod) element; if (method.isConstructor()) { PsiMethod constructorInSuper = PsiSuperMethodUtil.findConstructorInSuper(method); if (constructorInSuper != null) { return new PsiMethod[] {constructorInSuper}; } } else { PsiMethod[] superMethods = method.findSuperMethods(false); if (superMethods.length == 0) { PsiMethod superMethod = getSiblingInheritedViaSubClass(method); if (superMethod != null) { superMethods = new PsiMethod[] {superMethod}; } } return superMethods; } } return PsiElement.EMPTY_ARRAY; }