private synchronized void assertAllPointersDisposed() { for (Map.Entry<VirtualFilePointerListener, FilePointerPartNode> entry : myPointers.entrySet()) { FilePointerPartNode root = entry.getValue(); ArrayList<FilePointerPartNode> left = new ArrayList<FilePointerPartNode>(); root.getPointersUnder(null, false, "", left); if (!left.isEmpty()) { VirtualFilePointerImpl p = left.get(0).leaf; try { p.throwDisposalError("Not disposed pointer: " + p); } finally { for (FilePointerPartNode pair : left) { VirtualFilePointerImpl pointer = pair.leaf; pointer.dispose(); } } } } synchronized (myContainers) { if (!myContainers.isEmpty()) { VirtualFilePointerContainerImpl container = myContainers.iterator().next(); container.throwDisposalError("Not disposed container"); } } }
@Override public Object findElement(String s) { List<ObjectWithWeight> elements = new ArrayList<ObjectWithWeight>(); s = s.trim(); final ListIterator<Object> it = getElementIterator(0); while (it.hasNext()) { final ObjectWithWeight o = new ObjectWithWeight(it.next(), s, getComparator()); if (!o.weights.isEmpty()) { elements.add(o); } } ObjectWithWeight cur = null; ArrayList<ObjectWithWeight> current = new ArrayList<ObjectWithWeight>(); for (ObjectWithWeight element : elements) { if (cur == null) { cur = element; current.add(cur); continue; } final int i = element.compareWith(cur); if (i == 0) { current.add(element); } else if (i < 0) { cur = element; current.clear(); current.add(cur); } } return current.isEmpty() ? null : findClosestTo(myInitialPsiElement, current); }
@NotNull public List<Pair<TaskInfo, ProgressIndicator>> getBackgroundProcesses() { synchronized (myOriginals) { if (myOriginals.isEmpty()) return Collections.emptyList(); List<Pair<TaskInfo, ProgressIndicator>> result = new ArrayList<Pair<TaskInfo, ProgressIndicator>>(myOriginals.size()); for (int i = 0; i < myOriginals.size(); i++) { result.add(Pair.<TaskInfo, ProgressIndicator>create(myInfos.get(i), myOriginals.get(i))); } return Collections.unmodifiableList(result); } }
/** * Import from another configuration (e.g. imported file). Returns the number of imported items. * * @param cfg configuration to import from * @return added injections count */ public int importFrom(final Configuration cfg) { final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>(); final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>(); for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { importInjections( getInjections(supportId), cfg.getInjections(supportId), originalInjections, newInjections); } if (!newInjections.isEmpty()) configurationModified(); replaceInjections(newInjections, originalInjections); return newInjections.size(); }
@Nullable private Object findClosestTo(PsiElement path, ArrayList<ObjectWithWeight> paths) { if (path == null || myInitialPsiElement == null) { return paths.get(0).node; } final Set<PsiElement> parents = getAllParents(myInitialPsiElement); ArrayList<ObjectWithWeight> cur = new ArrayList<ObjectWithWeight>(); int max = -1; for (ObjectWithWeight p : paths) { final Object last = ((TreePath) p.node).getLastPathComponent(); final List<PsiElement> elements = new ArrayList<PsiElement>(); final Object object = ((DefaultMutableTreeNode) last).getUserObject(); if (object instanceof FilteringTreeStructure.FilteringNode) { FilteringTreeStructure.FilteringNode node = (FilteringTreeStructure.FilteringNode) object; FilteringTreeStructure.FilteringNode candidate = node; while (node != null) { elements.add(getPsi(node)); node = node.getParentNode(); } final int size = ContainerUtil.intersection(parents, elements).size(); if (size == elements.size() - 1 && size == parents.size() - (myInitialNodeIsLeaf ? 1 : 0) && candidate.children().isEmpty()) { return p.node; } if (size > max) { max = size; cur.clear(); cur.add(p); } else if (size == max) { cur.add(p); } } } Collections.sort( cur, new Comparator<ObjectWithWeight>() { @Override public int compare(ObjectWithWeight o1, ObjectWithWeight o2) { final int i = o1.compareWith(o2); return i != 0 ? i : ((TreePath) o2.node).getPathCount() - ((TreePath) o1.node).getPathCount(); } }); return cur.isEmpty() ? null : cur.get(0).node; }
public boolean setHostInjectionEnabled( final PsiLanguageInjectionHost host, final Collection<String> languages, final boolean enabled) { final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>(); final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>(); for (String supportId : getAllInjectorIds()) { for (BaseInjection injection : getInjections(supportId)) { if (!languages.contains(injection.getInjectedLanguageId())) continue; boolean replace = false; final ArrayList<InjectionPlace> newPlaces = new ArrayList<InjectionPlace>(); for (InjectionPlace place : injection.getInjectionPlaces()) { if (place.isEnabled() != enabled && place.getElementPattern() != null && (place.getElementPattern().accepts(host) || place.getElementPattern().accepts(host.getParent()))) { newPlaces.add(new InjectionPlace(place.getText(), place.getElementPattern(), enabled)); replace = true; } else newPlaces.add(place); } if (replace) { originalInjections.add(injection); final BaseInjection newInjection = injection.copy(); newInjection.getInjectionPlaces().clear(); newInjection.getInjectionPlaces().addAll(newPlaces); newInjections.add(newInjection); } } } if (!originalInjections.isEmpty()) { replaceInjectionsWithUndo( host.getProject(), newInjections, originalInjections, Collections.<PsiElement>emptyList()); return true; } return false; }
private int importPlaces(final List<BaseInjection> injections) { final Map<String, Set<BaseInjection>> map = ContainerUtil.classify( injections.iterator(), new Convertor<BaseInjection, String>() { @Override public String convert(final BaseInjection o) { return o.getSupportId(); } }); final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>(); final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>(); for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { final Set<BaseInjection> importingInjections = map.get(supportId); if (importingInjections == null) continue; importInjections( getInjections(supportId), importingInjections, originalInjections, newInjections); } if (!newInjections.isEmpty()) configurationModified(); replaceInjections(newInjections, originalInjections, true); return newInjections.size(); }
private boolean hasProgressIndicators() { synchronized (myOriginals) { return !myOriginals.isEmpty(); } }
@NotNull private GroovyResolveResult[] resolveTypeOrPropertyInner() { PsiElement nameElement = getReferenceNameElement(); String name = getReferenceName(); if (name == null || nameElement == null) return GroovyResolveResult.EMPTY_ARRAY; IElementType nameType = nameElement.getNode().getElementType(); if (nameType == GroovyTokenTypes.kTHIS) { GroovyResolveResult[] results = GrThisReferenceResolver.resolveThisExpression(this); if (results != null) { return results; } } else if (nameType == GroovyTokenTypes.kSUPER) { GroovyResolveResult[] results = GrSuperReferenceResolver.resolveSuperExpression(this); if (results != null) { return results; } } EnumSet<ClassHint.ResolveKind> kinds = getParent() instanceof GrReferenceExpression ? ClassHint.RESOLVE_KINDS_CLASS_PACKAGE : ClassHint.RESOLVE_KINDS_CLASS; GroovyResolveResult[] classCandidates = null; GrReferenceResolveRunner resolveRunner = new GrReferenceResolveRunner(this); ResolverProcessor processor = new PropertyResolverProcessor(name, this); resolveRunner.resolveImpl(processor); final GroovyResolveResult[] fieldCandidates = processor.getCandidates(); if (hasAt()) { return fieldCandidates; } boolean canBeClassOrPackage = ResolveUtil.canBeClassOrPackage(this); if (canBeClassOrPackage && findClassOrPackageAtFirst()) { ResolverProcessor classProcessor = new ClassResolverProcessor(name, this, kinds); resolveRunner.resolveImpl(classProcessor); classCandidates = classProcessor.getCandidates(); if (classCandidates.length > 0 && containsPackage(classCandidates)) { final PsiElement firstNonReferenceExprParent = PsiTreeUtil.skipParentsOfType(this, GrReferenceExpressionImpl.class); final GrReferenceExpressionImpl topRef = (GrReferenceExpressionImpl) PsiTreeUtil.findFirstParent( this, new Condition<PsiElement>() { @Override public boolean value(PsiElement parent) { return parent.getParent() == firstNonReferenceExprParent && parent instanceof GrReferenceExpressionImpl; } }); if (topRef != null) { final String fqn = topRef.getTextSkipWhiteSpaceAndComments(); if (JavaPsiFacade.getInstance(getProject()).findClass(fqn, getResolveScope()) != null) { return classCandidates; } } } } // if reference expression is in class we need to return field instead of accessor method for (GroovyResolveResult candidate : fieldCandidates) { final PsiElement element = candidate.getElement(); if (element instanceof PsiField) { final PsiClass containingClass = ((PsiField) element).getContainingClass(); if (containingClass != null && PsiUtil.getContextClass(this) == containingClass) return fieldCandidates; } else if (!(element instanceof GrBindingVariable)) { return fieldCandidates; } } if (classCandidates != null && classCandidates.length > 0) return classCandidates; final boolean isLValue = PsiUtil.isLValue(this); String[] accessorNames = isLValue ? GroovyPropertyUtils.suggestSettersName(name) : GroovyPropertyUtils.suggestGettersName(name); List<GroovyResolveResult> accessorResults = new ArrayList<GroovyResolveResult>(); for (String accessorName : accessorNames) { AccessorResolverProcessor accessorResolver = new AccessorResolverProcessor( accessorName, name, this, !isLValue, false, PsiImplUtil.getQualifierType(this), getTypeArguments()); resolveRunner.resolveImpl(accessorResolver); final GroovyResolveResult[] candidates = accessorResolver.getCandidates(); // can be only one correct candidate or some incorrect if (candidates.length == 1 && candidates[0].isStaticsOK() && candidates[0].isAccessible()) { return candidates; } else { ContainerUtil.addAll(accessorResults, candidates); } } final ArrayList<GroovyResolveResult> fieldList = ContainerUtil.newArrayList(fieldCandidates); filterOutBindings(fieldList); if (!fieldList.isEmpty()) { return fieldList.toArray(new GroovyResolveResult[fieldList.size()]); } if (classCandidates == null && canBeClassOrPackage) { ResolverProcessor classProcessor = new ClassResolverProcessor(name, this, kinds); resolveRunner.resolveImpl(classProcessor); classCandidates = classProcessor.getCandidates(); } if (classCandidates != null && classCandidates.length > 0) return classCandidates; if (!accessorResults.isEmpty()) return new GroovyResolveResult[] {accessorResults.get(0)}; return GroovyResolveResult.EMPTY_ARRAY; }