Java Code Examples for com.intellij.util.SmartList

The following are top voted examples for showing how to use com.intellij.util.SmartList. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: hybris-integration-intellij-idea-plugin   File: JspPropertyFoldingBuilder.java   Source Code and License 6 votes vote down vote up
@Nullable
private static IProperty getResolvedProperty(@NotNull final XmlAttributeValue codeValue) {
    return CachedValuesManager.getCachedValue(codeValue, KEY, () -> {
        List<IProperty> allProperties = new SmartList<>();
        for (PsiReference nextRef : codeValue.getReferences()) {
            if (nextRef instanceof PsiPolyVariantReference) {
                Arrays.stream(((PsiPolyVariantReference) nextRef).multiResolve(false))
                      .filter(ResolveResult::isValidResult)
                      .map(ResolveResult::getElement)
                      .map(o -> ObjectUtils.tryCast(o, IProperty.class))
                      .filter(Objects::nonNull)
                      .forEach(allProperties::add);
            } else {
                Optional.ofNullable(nextRef.resolve())
                        .map(o -> ObjectUtils.tryCast(o, IProperty.class))
                        .ifPresent(allProperties::add);
            }
        }

        IProperty theChosenOne = chooseForLocale(allProperties);
        return new CachedValueProvider.Result<>(theChosenOne, PsiModificationTracker.MODIFICATION_COUNT);
    });
}
 
Example 2
Project: intellij-ce-playground   File: MatcherImpl.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
protected List<PsiElement> getPsiElementsToProcess() {
  return ApplicationManager.getApplication().runReadAction(new Computable<List<PsiElement>>() {
    @Override
    public List<PsiElement> compute() {
      final PsiFile file = PsiManager.getInstance(project).findFile(myFile);
      if (file == null) {
        return Collections.emptyList();
      }

      final FileViewProvider viewProvider = file.getViewProvider();
      final List<PsiElement> elementsToProcess = new SmartList<PsiElement>();

      for (Language lang : viewProvider.getLanguages()) {
        elementsToProcess.add(viewProvider.getPsi(lang));
      }

      return elementsToProcess;
    }
  });
}
 
Example 3
Project: intellij-ce-playground   File: DomUtil.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("ForLoopReplaceableByForEach")
public static <T extends DomElement> List<T> getChildrenOf(DomElement parent, final Class<T> type) {
  final List<T> list = new SmartList<T>();
  List<? extends AbstractDomChildrenDescription> descriptions = parent.getGenericInfo().getChildrenDescriptions();
  for (int i = 0, descriptionsSize = descriptions.size(); i < descriptionsSize; i++) {
    AbstractDomChildrenDescription description = descriptions.get(i);
    if (description.getType() instanceof Class && type.isAssignableFrom((Class<?>)description.getType())) {
      List<T> values = (List<T>)description.getValues(parent);
      for (int j = 0, valuesSize = values.size(); j < valuesSize; j++) {
        T value = values.get(j);
        if (value.exists()) {
          list.add(value);
        }
      }
    }
  }
  return list;
}
 
Example 4
Project: intellij-ce-playground   File: MergeableLineMarkerInfo.java   Source Code and License 6 votes vote down vote up
@NotNull
public static List<LineMarkerInfo> merge(@NotNull List<MergeableLineMarkerInfo> markers) {
  List<LineMarkerInfo> result = new SmartList<LineMarkerInfo>();
  for (int i = 0; i < markers.size(); i++) {
    MergeableLineMarkerInfo marker = markers.get(i);
    List<MergeableLineMarkerInfo> toMerge = new SmartList<MergeableLineMarkerInfo>();
    for (int k = markers.size() - 1; k > i; k--) {
      MergeableLineMarkerInfo current = markers.get(k);
      if (marker.canMergeWith(current)) {
        toMerge.add(0, current);
        markers.remove(k);
      }
    }
    if (toMerge.isEmpty()) {
      result.add(marker);
    }
    else {
      toMerge.add(0, marker);
      result.add(new MyLineMarkerInfo(toMerge));
    }
  }
  return result;
}
 
Example 5
Project: intellij-ce-playground   File: RunManagerImpl.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public <T extends BeforeRunTask> List<T> getBeforeRunTasks(RunConfiguration settings, Key<T> taskProviderID) {
  if (settings instanceof WrappingRunConfiguration) {
    return getBeforeRunTasks(((WrappingRunConfiguration)settings).getPeer(), taskProviderID);
  }
  List<BeforeRunTask> tasks = myConfigurationToBeforeTasksMap.get(settings);
  if (tasks == null) {
    tasks = getBeforeRunTasks(settings);
    myConfigurationToBeforeTasksMap.put(settings, tasks);
  }
  List<T> result = new SmartList<T>();
  for (BeforeRunTask task : tasks) {
    if (task.getProviderId() == taskProviderID) {
      //noinspection unchecked
      result.add((T)task);
    }
  }
  return result;
}
 
Example 6
Project: intellij-ce-playground   File: TrailingSpacesInPropertyInspection.java   Source Code and License 6 votes vote down vote up
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
  if (!(file instanceof PropertiesFile)) return null;
  final List<IProperty> properties = ((PropertiesFile)file).getProperties();
  final List<ProblemDescriptor> descriptors = new SmartList<ProblemDescriptor>();
  for (IProperty property : properties) {
    ProgressManager.checkCanceled();
    final PropertyImpl propertyImpl = (PropertyImpl)property;
    for (ASTNode node : ContainerUtil.ar(propertyImpl.getKeyNode(), propertyImpl.getValueNode())) {
      if (node != null) {
        PsiElement key = node.getPsi();
        TextRange textRange = getTrailingSpaces(key, myIgnoreVisibleSpaces);
        if (textRange != null) {
          descriptors.add(manager.createProblemDescriptor(key, textRange, "Trailing spaces", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true, new RemoveTrailingSpacesFix(myIgnoreVisibleSpaces)));
        }
      }
    }
  }
  return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
 
Example 7
Project: intellij-ce-playground   File: BaseExternalAnnotationsManager.java   Source Code and License 6 votes vote down vote up
@NotNull
private List<AnnotationData> doCollect(@NotNull PsiModifierListOwner listOwner, boolean onlyWritable) {
  String externalName = getExternalName(listOwner, false);
  if (externalName == null) return NO_DATA;

  List<PsiFile> files = findExternalAnnotationsFiles(listOwner);
  if (files == null) return NO_DATA;

  SmartList<AnnotationData> result = new SmartList<AnnotationData>();
  for (PsiFile file : files) {
    if (!file.isValid()) continue;
    if (onlyWritable && !file.isWritable()) continue;

    MostlySingularMultiMap<String, AnnotationData> fileData = getDataFromFile(file);
    ContainerUtil.addAll(result, fileData.get(externalName));
  }
  if (result.isEmpty()) return NO_DATA;

  result.trimToSize();
  return result;
}
 
Example 8
Project: intellij-ce-playground   File: RunManagerImpl.java   Source Code and License 6 votes vote down vote up
/**
 * Template configuration is not included
 */
@Override
@NotNull
public List<RunConfiguration> getConfigurationsList(@NotNull ConfigurationType type) {
  List<RunConfiguration> result = null;
  for (RunnerAndConfigurationSettings settings : getSortedConfigurations()) {
    RunConfiguration configuration = settings.getConfiguration();
    if (type.getId().equals(configuration.getType().getId())) {
      if (result == null) {
        result = new SmartList<RunConfiguration>();
      }
      result.add(configuration);
    }
  }
  return ContainerUtil.notNullize(result);
}
 
Example 9
Project: intellij-ce-playground   File: VariableResolverProcessor.java   Source Code and License 6 votes vote down vote up
public VariableResolverProcessor(@NotNull PsiJavaCodeReferenceElement place, @NotNull PsiFile placeFile) {
  super(place.getReferenceName(), ourFilter, new PsiConflictResolver[]{new JavaVariableConflictResolver()}, new SmartList<CandidateInfo>(), place, placeFile);

  PsiClass access = null;
  PsiElement qualifier = place.getQualifier();
  if (qualifier instanceof PsiExpression) {
    final JavaResolveResult accessClass = PsiUtil.getAccessObjectClass((PsiExpression)qualifier);
    final PsiElement element = accessClass.getElement();
    if (element instanceof PsiTypeParameter) {
      PsiElementFactory factory = JavaPsiFacade.getInstance(placeFile.getProject()).getElementFactory();
      final PsiClassType type = factory.createType((PsiTypeParameter)element);
      final PsiType accessType = accessClass.getSubstitutor().substitute(type);
      if (accessType instanceof PsiArrayType) {
        LanguageLevel languageLevel = PsiUtil.getLanguageLevel(placeFile);
        access = factory.getArrayClass(languageLevel);
      }
      else if (accessType instanceof PsiClassType) {
        access = ((PsiClassType)accessType).resolve();
      }
    }
    else if (element instanceof PsiClass) {
      access = (PsiClass)element;
    }
  }
  myAccessClass = access;
}
 
Example 10
Project: intellij-ce-playground   File: RunnerAndConfigurationSettingsImpl.java   Source Code and License 6 votes vote down vote up
private void add(@NotNull Element state, @Nullable ProgramRunner runner, @Nullable T data) throws InvalidDataException {
  if (runner == null) {
    if (unloadedSettings == null) {
      unloadedSettings = new SmartList<Element>();
    }
    unloadedSettings.add(state);
    return;
  }

  if (data != null) {
    ((JDOMExternalizable)data).readExternal(state);
  }

  settings.put(runner, data);
  loadedIds.add(runner.getRunnerId());
}
 
Example 11
Project: intellij-ce-playground   File: DebuggerUtilsEx.java   Source Code and License 6 votes vote down vote up
@NotNull
public static List<Pair<Breakpoint, Event>> getEventDescriptors(SuspendContextImpl suspendContext) {
  DebuggerManagerThreadImpl.assertIsManagerThread();
  if(suspendContext == null) {
    return Collections.emptyList();
  }
  final EventSet events = suspendContext.getEventSet();
  if(events == null) {
    return Collections.emptyList();
  }
  final List<Pair<Breakpoint, Event>> eventDescriptors = new SmartList<Pair<Breakpoint, Event>>();

  final RequestManagerImpl requestManager = suspendContext.getDebugProcess().getRequestsManager();
  for (final Event event : events) {
    final Requestor requestor = requestManager.findRequestor(event.request());
    if (requestor instanceof Breakpoint) {
      eventDescriptors.add(Pair.create((Breakpoint)requestor, event));
    }
  }
  return eventDescriptors;
}
 
Example 12
Project: intellij-ce-playground   File: JavaClassNameCompletionContributor.java   Source Code and License 6 votes vote down vote up
public static List<JavaPsiClassReferenceElement> createClassLookupItems(final PsiClass psiClass,
                                                                        boolean withInners,
                                                                        InsertHandler<JavaPsiClassReferenceElement> insertHandler,
                                                                        Condition<PsiClass> condition) {
  List<JavaPsiClassReferenceElement> result = new SmartList<JavaPsiClassReferenceElement>();
  if (condition.value(psiClass)) {
    result.add(AllClassesGetter.createLookupItem(psiClass, insertHandler));
  }
  String name = psiClass.getName();
  if (withInners && name != null) {
    for (PsiClass inner : psiClass.getInnerClasses()) {
      if (inner.hasModifierProperty(PsiModifier.STATIC)) {
        for (JavaPsiClassReferenceElement lookupInner : createClassLookupItems(inner, true, insertHandler, condition)) {
          String forced = lookupInner.getForcedPresentableName();
          String qualifiedName = name + "." + (forced != null ? forced : inner.getName());
          lookupInner.setForcedPresentableName(qualifiedName);
          lookupInner.setLookupString(qualifiedName);
          result.add(lookupInner);
        }
      }
    }
  }
  return result;
}
 
Example 13
Project: intellij-ce-playground   File: VcsContentAnnotationExceptionFilter.java   Source Code and License 6 votes vote down vote up
@Nullable
private static List<PsiMethod> selectMethod(final PsiMethod[] methods, final Trinity<PsiClass, PsiFile, String> previousLineResult) {
  if (previousLineResult == null || previousLineResult.getThird() == null) return null;

  final List<PsiMethod> result = new SmartList<PsiMethod>();
  for (final PsiMethod method : methods) {
    method.accept(new JavaRecursiveElementVisitor() {
      @Override
      public void visitCallExpression(PsiCallExpression callExpression) {
        final PsiMethod resolved = callExpression.resolveMethod();
        if (resolved != null) {
          if (resolved.getName().equals(previousLineResult.getThird())) {
            result.add(method);
          }
        }
      }
    });
  }

  return result;
}
 
Example 14
Project: intellij-ce-playground   File: ArchivedTemplatesFactory.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public ProjectTemplate[] createTemplates(@Nullable String group, WizardContext context) {
  // myGroups contains only not-null keys
  if (group == null) {
    return ProjectTemplate.EMPTY_ARRAY;
  }

  List<ProjectTemplate> templates = null;
  for (Pair<URL, ClassLoader> url : myGroups.getValue().get(group)) {
    try {
      for (String child : UrlUtil.getChildrenRelativePaths(url.first)) {
        if (child.endsWith(ZIP)) {
          if (templates == null) {
            templates = new SmartList<ProjectTemplate>();
          }
          templates.add(new LocalArchivedTemplate(new URL(url.first.toExternalForm() + '/' + child), url.second));
        }
      }
    }
    catch (IOException e) {
      LOG.error(e);
    }
  }
  return ContainerUtil.isEmpty(templates) ? ProjectTemplate.EMPTY_ARRAY : templates.toArray(new ProjectTemplate[templates.size()]);
}
 
Example 15
Project: intellij-ce-playground   File: XLineBreakpointManager.java   Source Code and License 6 votes vote down vote up
private void updateBreakpoints(@NotNull Document document) {
  Collection<XLineBreakpointImpl> breakpoints = myBreakpoints.getKeysByValue(document);
  if (breakpoints == null) {
    return;
  }

  TIntHashSet lines = new TIntHashSet();
  List<XBreakpoint<?>> toRemove = new SmartList<XBreakpoint<?>>();
  for (XLineBreakpointImpl breakpoint : breakpoints) {
    breakpoint.updatePosition();
    if (!breakpoint.isValid() || !lines.add(breakpoint.getLine())) {
      toRemove.add(breakpoint);
    }
  }

  removeBreakpoints(toRemove);
}
 
Example 16
Project: intellij-ce-playground   File: NamedObjectProviderBinding.java   Source Code and License 6 votes vote down vote up
public void registerProvider(@NonNls @NotNull String[] names,
                             @NotNull ElementPattern filter,
                             boolean caseSensitive,
                             @NotNull PsiReferenceProvider provider,
                             final double priority) {
  final Map<String, List<ProviderInfo<ElementPattern>>> map = caseSensitive ? myNamesToProvidersMap : myNamesToProvidersMapInsensitive;

  for (final String attributeName : names) {
    String key = caseSensitive ? attributeName : attributeName.toLowerCase();
    List<ProviderInfo<ElementPattern>> psiReferenceProviders = map.get(key);

    if (psiReferenceProviders == null) {
      map.put(key, psiReferenceProviders = new SmartList<ProviderInfo<ElementPattern>>());
    }

    psiReferenceProviders.add(new ProviderInfo<ElementPattern>(provider, filter, priority));
  }
}
 
Example 17
Project: intellij-ce-playground   File: MavenPluginDescriptor.java   Source Code and License 6 votes vote down vote up
public static Map<String, Map<String, Map<String, List<MavenPluginDescriptor>>>> getDescriptorsMap() {
  Map<String, Map<String, Map<String, List<MavenPluginDescriptor>>>> res = ourDescriptorsMap;
  if (res == null) {
    res = new HashMap<String, Map<String, Map<String, List<MavenPluginDescriptor>>>>();

    for (MavenPluginDescriptor pluginDescriptor : MavenPluginDescriptor.EP_NAME.getExtensions()) {
      Pair<String, String> pluginId = parsePluginId(pluginDescriptor.mavenId);

      Map<String, Map<String, List<MavenPluginDescriptor>>> groupMap = MavenUtil.getOrCreate(res, pluginId.second);// pluginId.second is artifactId

      Map<String, List<MavenPluginDescriptor>> goalsMap = MavenUtil.getOrCreate(groupMap, pluginId.first);// pluginId.first is groupId

      List<MavenPluginDescriptor> descriptorList = goalsMap.get(pluginDescriptor.goal);
      if (descriptorList == null) {
        descriptorList = new SmartList<MavenPluginDescriptor>();
        goalsMap.put(pluginDescriptor.goal, descriptorList);
      }

      descriptorList.add(pluginDescriptor);
    }

    ourDescriptorsMap = res;
  }

  return res;
}
 
Example 18
Project: intellij-ce-playground   File: HgBaseLogParser.java   Source Code and License 6 votes vote down vote up
@NotNull
protected static SmartList<HgRevisionNumber> parseParentRevisions(@NotNull String parentsString, @NotNull String currentRevisionString) {
  SmartList<HgRevisionNumber> parents = new SmartList<HgRevisionNumber>();
  if (StringUtil.isEmptyOrSpaces(parentsString)) {
    // parents shouldn't be empty  only if not supported
    Long revision = Long.valueOf(currentRevisionString);
    HgRevisionNumber parentRevision = HgRevisionNumber.getLocalInstance(String.valueOf(revision - 1));
    parents.add(parentRevision);
    return parents;
  }
  //hg returns parents in the format 'rev:node rev:node ' (note the trailing space)
  List<String> parentStrings = StringUtil.split(parentsString.trim(), " ");
  for (String parentString : parentStrings) {
    List<String> parentParts = StringUtil.split(parentString, ":");
    //if revision has only 1 parent and "--debug" argument were added or if appropriate parent template were used,
    // its second parent has revision number  -1
    if (Integer.valueOf(parentParts.get(0)) >= 0) {
      parents.add(HgRevisionNumber.getInstance(parentParts.get(0), parentParts.get(1)));
    }
  }
  return parents;
}
 
Example 19
Project: intellij-ce-playground   File: ResourceBundleReference.java   Source Code and License 6 votes vote down vote up
@NotNull
public Object[] getVariants() {
  final ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(getElement().getProject());
  final PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(getElement().getProject());

  final Set<String> bundleNames = new HashSet<String>();
  final List<LookupElement> variants = new SmartList<LookupElement>();
  PropertiesFileProcessor processor = new PropertiesFileProcessor() {
    @Override
    public boolean process(String baseName, PropertiesFile propertiesFile) {
      if (!bundleNames.add(baseName)) return true;

      final LookupElementBuilder builder =
        LookupElementBuilder.create(baseName)
          .withIcon(AllIcons.Nodes.ResourceBundle);
      boolean isInContent = projectFileIndex.isInContent(propertiesFile.getVirtualFile());
      variants.add(isInContent ? PrioritizedLookupElement.withPriority(builder, Double.MAX_VALUE) : builder);
      return true;
    }
  };

  referenceManager.processPropertiesFiles(myElement.getResolveScope(), processor, this);
  return variants.toArray(new LookupElement[variants.size()]);
}
 
Example 20
Project: intellij-ce-playground   File: DomStub.java   Source Code and License 6 votes vote down vote up
public List<DomStub> getChildrenByName(final CharSequence name, @Nullable final String nsKey) {
  final List<DomStub> stubs = getChildrenStubs();
  if (stubs.isEmpty()) {
    return Collections.emptyList();
  }

  final String s = nsKey == null ? "" : nsKey;
  final List<DomStub> result = new SmartList<DomStub>();
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0, size = stubs.size(); i < size; i++) {
    final DomStub stub = stubs.get(i);
    if (XmlUtil.getLocalName(stub.getName()).equals(name) &&
        Comparing.equal(s, stub.getNamespaceKey())) {
      result.add(stub);
    }
  }
  return result;
}
 
Example 21
Project: intellij-ce-playground   File: XsltReferenceProvider.java   Source Code and License 6 votes vote down vote up
private static PsiReference[] createPrefixReferences(XmlAttribute attribute, Pattern pattern) {
  final Matcher matcher = pattern.matcher(attribute.getValue());

  if (matcher.find()) {
    final List<PsiReference> refs = new SmartList<PsiReference>();
    do {
      final int start = matcher.start(1);
      if (start >= 0) {
        refs.add(new PrefixReference(attribute, TextRange.create(start, matcher.end(1))));
      }
    }
    while (matcher.find());

    return refs.toArray(new PsiReference[refs.size()]);
  }
  return PsiReference.EMPTY_ARRAY;
}
 
Example 22
Project: intellij-ce-playground   File: RunManagerImpl.java   Source Code and License 6 votes vote down vote up
@NotNull
private List<BeforeRunTask> readStepsBeforeRun(@Nullable Element child, @NotNull RunnerAndConfigurationSettings settings) {
  List<BeforeRunTask> result = null;
  if (child != null) {
    for (Element methodElement : child.getChildren(OPTION)) {
      Key<? extends BeforeRunTask> id = getProviderKey(methodElement.getAttributeValue(NAME_ATTR));
      BeforeRunTask beforeRunTask = getProvider(id).createTask(settings.getConfiguration());
      if (beforeRunTask != null) {
        beforeRunTask.readExternal(methodElement);
        if (result == null) {
          result = new SmartList<BeforeRunTask>();
        }
        result.add(beforeRunTask);
      }
    }
  }
  return ContainerUtil.notNullize(result);
}
 
Example 23
Project: intellij-ce-playground   File: FacetFinderImpl.java   Source Code and License 6 votes vote down vote up
@NotNull
private <F extends Facet&FacetRootsProvider> Map<VirtualFile, List<Facet>> computeRootToFacetsMap(final FacetTypeId<F> type) {
  final Module[] modules = myModuleManager.getModules();
  final HashMap<VirtualFile, List<Facet>> map = new HashMap<VirtualFile, List<Facet>>();
  for (Module module : modules) {
    final Collection<F> facets = FacetManager.getInstance(module).getFacetsByType(type);
    for (F facet : facets) {
      for (VirtualFile root : facet.getFacetRoots()) {
        List<Facet> list = map.get(root);
        if (list == null) {
          list = new SmartList<Facet>();
          map.put(root, list);
        }
        list.add(facet);
      }
    }
  }
  return map;
}
 
Example 24
Project: intellij-ce-playground   File: MavenArtifactIndex.java   Source Code and License 6 votes vote down vote up
@NotNull
public List<MavenArtifact> findArtifacts(@Nullable String groupId, @Nullable String artifactId, @Nullable String version) {
  Map<String, List<MavenArtifact>> groupMap = myData.get(groupId);
  if (groupMap == null) return Collections.emptyList();

  List<MavenArtifact> artifacts = groupMap.get(artifactId);
  if (artifacts == null) return Collections.emptyList();

  List<MavenArtifact> res = new SmartList<MavenArtifact>();
  for (MavenArtifact artifact : artifacts) {
    if (Comparing.equal(version, artifact.getVersion())) {
      res.add(artifact);
    }
  }

  return res;
}
 
Example 25
Project: intellij-ce-playground   File: ExternalizablePropertyContainer.java   Source Code and License 6 votes vote down vote up
@Override
public List<T> readValue(Element dataElement) {
  List<T> list = new SmartList<T>();
  for (Element element : dataElement.getChildren()) {
    if (NULL_ELEMENT.equals(element.getName())) {
      list.add(null);
    }
    else if (myItemTagName.equals(element.getName())) {
      T item = myItemExternalizer.readValue(element);
      if (item == null) {
        LOG.error("Can't create element " + myItemExternalizer);
        return list;
      }
      list.add(item);
    }
  }
  return list;
}
 
Example 26
Project: intellij-ce-playground   File: InjectedLanguageManagerImpl.java   Source Code and License 6 votes vote down vote up
@Override
@Nullable
public List<Pair<PsiElement, TextRange>> getInjectedPsiFiles(@NotNull final PsiElement host) {
  if (!(host instanceof PsiLanguageInjectionHost) || !((PsiLanguageInjectionHost) host).isValidHost()) {
    return null;
  }
  final PsiElement inTree = InjectedLanguageUtil.loadTree(host, host.getContainingFile());
  final List<Pair<PsiElement, TextRange>> result = new SmartList<Pair<PsiElement, TextRange>>();
  InjectedLanguageUtil.enumerate(inTree, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
    @Override
    public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
      for (PsiLanguageInjectionHost.Shred place : places) {
        if (place.getHost() == inTree) {
          result.add(new Pair<PsiElement, TextRange>(injectedPsi, place.getRangeInsideHost()));
        }
      }
    }
  });
  return result.isEmpty() ? null : result;
}
 
Example 27
Project: intellij-ce-playground   File: ArbitraryPlaceUrlReferenceProvider.java   Source Code and License 6 votes vote down vote up
@Override
protected CachedValue<PsiReference[]> compute(final PsiElement element, Object p) {
  return CachedValuesManager.getManager(element.getProject()).createCachedValue(new CachedValueProvider<PsiReference[]>() {
    public Result<PsiReference[]> compute() {
      IssueNavigationConfiguration navigationConfiguration = IssueNavigationConfiguration.getInstance(element.getProject());
      if (navigationConfiguration == null) {
        return Result.create(PsiReference.EMPTY_ARRAY, element);
      }
      
      List<PsiReference> refs = null;
      GlobalPathReferenceProvider provider = myReferenceProvider.get();
      CharSequence commentText = StringUtil.newBombedCharSequence(element.getText(), 500);
      for (IssueNavigationConfiguration.LinkMatch link : navigationConfiguration.findIssueLinks(commentText)) {
        if (refs == null) refs = new SmartList<PsiReference>();
        if (provider == null) {
          provider = (GlobalPathReferenceProvider)PathReferenceManager.getInstance().getGlobalWebPathReferenceProvider();
          myReferenceProvider.lazySet(provider);
        }
        provider.createUrlReference(element, link.getTargetUrl(), link.getRange(), refs);
      }
      PsiReference[] references = refs != null ? refs.toArray(new PsiReference[refs.size()]) : PsiReference.EMPTY_ARRAY;
      return new Result<PsiReference[]>(references, element, navigationConfiguration);
    }
  }, false);
}
 
Example 28
Project: intellij-ce-playground   File: CollectingAsyncResult.java   Source Code and License 6 votes vote down vote up
@NotNull
public AsyncResult<List<T>> create() {
  int size = asyncResults.size();
  if (size == 0) {
    return AsyncResult.doneList();
  }

  final List<T> results = size == 1 ? new SmartList<T>() : new ArrayList<T>(size);
  final AsyncResult<List<T>> totalResult = new AsyncResult<List<T>>(asyncResults.size(), results);
  Consumer<T> resultConsumer = new Consumer<T>() {
    @Override
    public void consume(T result) {
      synchronized (results) {
        results.add(result);
      }
      totalResult.setDone();
    }
  };
  for (AsyncResult<T> subResult : asyncResults) {
    subResult.doWhenDone(resultConsumer).notifyWhenRejected(totalResult);
  }
  return totalResult;
}
 
Example 29
Project: intellij-ce-playground   File: RegistrationProblemsInspection.java   Source Code and License 6 votes vote down vote up
private static String[] makeQualifiedModuleInterfaceNames(XmlTag component, String fqn) {
  final XmlTag[] children = component.findSubTags("option");
  for (XmlTag child : children) {
    if ("type".equals(child.getAttributeValue("name"))) {
      final String value = child.getAttributeValue("value");
      final SmartList<String> names = new SmartList<String>();
      if (value != null) {
        final String[] moduleTypes = value.split(";");
        for (String moduleType : moduleTypes) {
          names.add(fqn + "#" + moduleType);
        }
      }
      return ArrayUtil.toStringArray(names);
    }
  }
  return new String[]{ fqn };
}
 
Example 30
Project: intellij-ce-playground   File: FixedChildDescriptionImpl.java   Source Code and License 6 votes vote down vote up
@Override
@NotNull
public List<? extends DomElement> getValues(@NotNull final DomElement element) {
  final List<DomElement> result = new SmartList<DomElement>();
  final DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(element);
  if (handler != null) {
    for (int i = 0; i < myCount; i++) {
      result.add(handler.getFixedChild(Pair.create(this, i)).getProxy());
    }
  }
  else {
    for (Collection<JavaMethod> methods : myGetterMethods) {
      if (methods != null && !methods.isEmpty()) {
        result.add((DomElement)methods.iterator().next().invoke(element, ArrayUtil.EMPTY_OBJECT_ARRAY));
      }
    }
  }
  return result;
}
 
Example 31
Project: intellij-ce-playground   File: LibraryDetectionManagerImpl.java   Source Code and License 5 votes vote down vote up
private static List<Pair<LibraryKind, LibraryProperties>> computeKinds(List<VirtualFile> files) {
  final SmartList<Pair<LibraryKind, LibraryProperties>> result = new SmartList<Pair<LibraryKind, LibraryProperties>>();
  final LibraryType<?>[] libraryTypes = LibraryType.EP_NAME.getExtensions();
  final LibraryPresentationProvider[] presentationProviders = LibraryPresentationProvider.EP_NAME.getExtensions();
  for (LibraryPresentationProvider provider : ContainerUtil.concat(libraryTypes, presentationProviders)) {
    final LibraryProperties properties = provider.detect(files);
    if (properties != null) {
      result.add(Pair.create(provider.getKind(), properties));
    }
  }
  return result;
}
 
Example 32
Project: intellij-ce-playground   File: PsiTreeUtil.java   Source Code and License 5 votes vote down vote up
@Nullable
public static <T extends PsiElement> T[] getChildrenOfType(@Nullable PsiElement element, @NotNull Class<T> aClass) {
  if (element == null) return null;

  List<T> result = null;
  for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
    if (aClass.isInstance(child)) {
      if (result == null) result = new SmartList<T>();
      //noinspection unchecked
      result.add((T)child);
    }
  }
  return result == null ? null : ArrayUtil.toObjectArray(result, aClass);
}
 
Example 33
Project: intellij-ce-playground   File: ArtifactBuildTarget.java   Source Code and License 5 votes vote down vote up
@Override
public Collection<BuildTarget<?>> computeDependencies(BuildTargetRegistry targetRegistry, final TargetOutputIndex outputIndex) {
  final LinkedHashSet<BuildTarget<?>> dependencies = new LinkedHashSet<BuildTarget<?>>();
  JpsArtifactUtil.processPackagingElements(myArtifact.getRootElement(), new Processor<JpsPackagingElement>() {
    @Override
    public boolean process(JpsPackagingElement element) {
      if (element instanceof JpsArtifactOutputPackagingElement) {
        JpsArtifact included = ((JpsArtifactOutputPackagingElement)element).getArtifactReference().resolve();
        if (included != null && !included.equals(myArtifact)) {
          if (!StringUtil.isEmpty(included.getOutputPath())) {
            dependencies.add(new ArtifactBuildTarget(included));
            return false;
          }
        }
      }
      dependencies.addAll(LayoutElementBuildersRegistry.getInstance().getDependencies(element, outputIndex));
      return true;
    }
  });
  if (!dependencies.isEmpty()) {
    final List<BuildTarget<?>> additional = new SmartList<BuildTarget<?>>();
    for (BuildTarget<?> dependency : dependencies) {
      if (dependency instanceof ModuleBasedTarget<?>) {
        final ModuleBasedTarget target = (ModuleBasedTarget)dependency;
        additional.addAll(targetRegistry.getModuleBasedTargets(target.getModule(), target.isTests()? BuildTargetRegistry.ModuleTargetSelector.TEST : BuildTargetRegistry.ModuleTargetSelector.PRODUCTION));
      }
    }
    dependencies.addAll(additional);
  }
  return dependencies;
}
 
Example 34
Project: intellij-ce-playground   File: ArtifactOutputToSourceMapping.java   Source Code and License 5 votes vote down vote up
@Override
public List<SourcePathAndRootIndex> read(@NotNull DataInput in) throws IOException {
  List<SourcePathAndRootIndex> result = new SmartList<SourcePathAndRootIndex>();
  final DataInputStream stream = (DataInputStream)in;
  while (stream.available() > 0) {
    final String path = IOUtil.readUTF(stream);
    final int index = stream.readInt();
    result.add(new SourcePathAndRootIndex(path, index));
  }
  return result;
}
 
Example 35
Project: intellij-ce-playground   File: IncProjectBuilder.java   Source Code and License 5 votes vote down vote up
public List<BuildChunkTask> markAsFinishedAndGetNextReadyTasks() {
  List<BuildChunkTask> nextTasks = new SmartList<BuildChunkTask>();
  for (BuildChunkTask task : myTasksDependsOnThis) {
    final boolean removed = task.myNotBuiltDependencies.remove(this);
    LOG.assertTrue(removed, task.getChunk().toString() + " didn't have " + getChunk().toString());

    if (task.isReady()) {
      nextTasks.add(task);
    }
  }
  return nextTasks;
}
 
Example 36
Project: intellij-ce-playground   File: UpdatablePkgInfo.java   Source Code and License 5 votes vote down vote up
public List<RemotePkgInfo> getAllRemotes() {
  List<RemotePkgInfo> result = new SmartList<RemotePkgInfo>();
  if (myRemoteInfo != null) {
    result.add(myRemoteInfo);
  }
  if (myRemotePreviewInfo != null) {
    result.add(myRemotePreviewInfo);
  }
  return result;
}
 
Example 37
Project: intellij-ce-playground   File: BuildRootIndexImpl.java   Source Code and License 5 votes vote down vote up
private void registerDescriptor(BuildRootDescriptor descriptor) {
  List<BuildRootDescriptor> list = myRootToDescriptors.get(descriptor.getRootFile());
  if (list == null) {
    list = new SmartList<BuildRootDescriptor>();
    myRootToDescriptors.put(descriptor.getRootFile(), list);
  }
  list.add(descriptor);
}
 
Example 38
Project: intellij-ce-playground   File: JpsElementCollectionImpl.java   Source Code and License 5 votes vote down vote up
private JpsElementCollectionImpl(JpsElementCollectionImpl<E> original) {
  myChildRole = original.myChildRole;
  myElements = new SmartList<E>();
  myCopyToOriginal = new HashMap<E, E>();
  for (E e : original.myElements) {
    //noinspection unchecked
    final E copy = (E)e.getBulkModificationSupport().createCopy();
    setParent(copy, this);
    myElements.add(copy);
    myCopyToOriginal.put(copy, e);
  }
}
 
Example 39
Project: intellij-ce-playground   File: ExternalProjectsDataStorage.java   Source Code and License 5 votes vote down vote up
@NotNull
private static Collection<InternalExternalProjectInfo> load(@NotNull Project project) throws IOException {
  SmartList<InternalExternalProjectInfo> projects = new SmartList<InternalExternalProjectInfo>();
  @SuppressWarnings("unchecked") final File configurationFile = getProjectConfigurationFile(project);
  if (!configurationFile.isFile()) return projects;

  DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(configurationFile)));

  try {
    final String storage_version = in.readUTF();
    if (!STORAGE_VERSION.equals(storage_version)) return projects;
    final int size = in.readInt();

    ObjectInputStream os = new ObjectInputStream(in);
    try {
      for (int i = 0; i < size; i++) {
        //noinspection unchecked
        InternalExternalProjectInfo projectDataDataNode = (InternalExternalProjectInfo)os.readObject();
        projects.add(projectDataDataNode);
      }
    }
    catch (ClassNotFoundException e) {
      IOException ioException = new IOException();
      ioException.initCause(e);
      throw ioException;
    }
    finally {
      os.close();
    }
  }
  finally {
    in.close();
  }
  return projects;
}
 
Example 40
Project: intellij-ce-playground   File: MethodResolverProcessor.java   Source Code and License 5 votes vote down vote up
public MethodResolverProcessor(PsiClass classConstr, @NotNull PsiExpressionList argumentList, @NotNull PsiElement place, @NotNull PsiFile placeFile) {
  super(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(argumentList,
                                                                                    PsiUtil.getLanguageLevel(placeFile))}, new SmartList<CandidateInfo>());
  setIsConstructor(true);
  setAccessClass(classConstr);
  setArgumentList(argumentList);
}
 
Example 41
Project: intellij-ce-playground   File: PsiClassImplUtil.java   Source Code and License 5 votes vote down vote up
@NotNull
private static List<PsiMethod> findMethodsBySignature(@NotNull PsiClass aClass,
                                                      @NotNull PsiMethod patternMethod,
                                                      boolean checkBases,
                                                      boolean stopOnFirst) {
  final PsiMethod[] methodsByName = aClass.findMethodsByName(patternMethod.getName(), checkBases);
  if (methodsByName.length == 0) return Collections.emptyList();
  final List<PsiMethod> methods = new SmartList<PsiMethod>();
  final MethodSignature patternSignature = patternMethod.getSignature(PsiSubstitutor.EMPTY);
  for (final PsiMethod method : methodsByName) {
    final PsiClass superClass = method.getContainingClass();
    final PsiSubstitutor substitutor;
    if (checkBases && !aClass.equals(superClass) && superClass != null) {
      substitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, PsiSubstitutor.EMPTY);
    }
    else {
      substitutor = PsiSubstitutor.EMPTY;
    }
    final MethodSignature signature = method.getSignature(substitutor);
    if (signature.equals(patternSignature)) {
      methods.add(method);
      if (stopOnFirst) {
        break;
      }
    }
  }
  return methods;
}
 
Example 42
Project: intellij-ce-playground   File: StartupManagerImpl.java   Source Code and License 5 votes vote down vote up
private void checkProjectRoots() {
  LocalFileSystem fs = LocalFileSystem.getInstance();
  if (!(fs instanceof LocalFileSystemImpl)) return;
  FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher();
  if (!watcher.isOperational()) return;
  List<String> manualWatchRoots = watcher.getManualWatchRoots();
  if (manualWatchRoots.isEmpty()) return;
  VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentRoots();
  if (roots.length == 0) return;

  List<String> nonWatched = new SmartList<String>();
  for (VirtualFile root : roots) {
    if (!(root.getFileSystem() instanceof LocalFileSystem)) continue;
    String rootPath = root.getPath();
    for (String manualWatchRoot : manualWatchRoots) {
      if (FileUtil.isAncestor(manualWatchRoot, rootPath, false)) {
        nonWatched.add(rootPath);
      }
    }
  }

  if (!nonWatched.isEmpty()) {
    String message = ApplicationBundle.message("watcher.non.watchable.project");
    watcher.notifyOnFailure(message, null);
    LOG.info("unwatched roots: " + nonWatched);
    LOG.info("manual watches: " + manualWatchRoots);
  }
}
 
Example 43
Project: intellij-ce-playground   File: PsiClassReferenceType.java   Source Code and License 5 votes vote down vote up
private static PsiAnnotation[] collectAnnotations(PsiJavaCodeReferenceElement reference) {
  List<PsiAnnotation> result = null;
  for (PsiElement child = reference.getFirstChild(); child != null; child = child.getNextSibling()) {
    if (child instanceof PsiAnnotation) {
      if (result == null) result = new SmartList<PsiAnnotation>();
      result.add((PsiAnnotation)child);
    }
  }
  return result == null ? PsiAnnotation.EMPTY_ARRAY : result.toArray(new PsiAnnotation[result.size()]);
}
 
Example 44
Project: intellij-ce-playground   File: PsiElementFinder.java   Source Code and License 5 votes vote down vote up
@NotNull
public static PsiClass[] filterByName(@NotNull String className, @NotNull PsiClass[] classes) {
  if (classes.length == 0) return PsiClass.EMPTY_ARRAY;
  if (classes.length == 1) {
    return className.equals(classes[0].getName()) ? classes : PsiClass.EMPTY_ARRAY;
  }
  List<PsiClass> foundClasses = new SmartList<PsiClass>();
  for (PsiClass psiClass : classes) {
    if (className.equals(psiClass.getName())) {
      foundClasses.add(psiClass);
    }
  }
  return foundClasses.isEmpty() ? PsiClass.EMPTY_ARRAY : foundClasses.toArray(new PsiClass[foundClasses.size()]);
}
 
Example 45
Project: intellij-ce-playground   File: ModelAnnotator.java   Source Code and License 5 votes vote down vote up
@Override
public void visitDefine(final Define define) {
  final PsiElement element = define.getPsiElement();
  if (element != null) {
    final XmlFile xmlFile = (XmlFile)element.getContainingFile();

    final List<Define> result = new SmartList<Define>();
    final OverriddenDefineSearcher searcher = new OverriddenDefineSearcher(define, xmlFile, result);

    final PsiElementProcessor.FindElement<XmlFile> processor = new PsiElementProcessor.FindElement<XmlFile>() {
      @Override
      public boolean execute(@NotNull XmlFile file) {
        final Grammar grammar = GrammarFactory.getGrammar(file);
        if (grammar == null) return true;

        grammar.acceptChildren(searcher);

        return result.size() == 0 || super.execute(file);
      }
    };
    
    RelaxIncludeIndex.processBackwardDependencies(xmlFile, processor);

    if (processor.isFound()) {
      createGutterAnnotation(define, new OverriddenDefineRenderer(define));
    }
  }
}
 
Example 46
Project: intellij-ce-playground   File: RefMethodImpl.java   Source Code and License 5 votes vote down vote up
private void collectUncaughtExceptions(@NotNull PsiMethod method) {
  if (isExternalOverride()) return;
  if (getRefManager().isOfflineView()) return;
  @NonNls final String name = method.getName();
  if (getOwnerClass().isTestCase() && name.startsWith("test")) return;

  if (getSuperMethods().isEmpty()) {
    PsiClassType[] throwsList = method.getThrowsList().getReferencedTypes();
    if (throwsList.length > 0) {
      myUnThrownExceptions = throwsList.length == 1 ? new SmartList<String>() : new ArrayList<String>(throwsList.length);
      for (final PsiClassType type : throwsList) {
        PsiClass aClass = type.resolve();
        String fqn = aClass == null ? null : aClass.getQualifiedName();
        if (fqn != null) {
          myUnThrownExceptions.add(fqn);
        }
      }
    }
  }

  final PsiCodeBlock body = method.getBody();
  if (body == null) return;

  final Collection<PsiClassType> exceptionTypes = ExceptionUtil.collectUnhandledExceptions(body, method, false);
  for (final PsiClassType exceptionType : exceptionTypes) {
    updateThrowsList(exceptionType);
  }
}
 
Example 47
Project: intellij-ce-playground   File: DomElementAnnotationsManagerImpl.java   Source Code and License 5 votes vote down vote up
public List<DomElementsInspection> getSuitableDomInspections(final DomFileElement fileElement, boolean enabledOnly) {
  Class rootType = fileElement.getRootElementClass();
  final InspectionProfile profile = getInspectionProfile(fileElement);
  final List<DomElementsInspection> inspections = new SmartList<DomElementsInspection>();
  for (final InspectionToolWrapper toolWrapper : profile.getInspectionTools(fileElement.getFile())) {
    if (!enabledOnly || profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), fileElement.getFile())) {
      ContainerUtil.addIfNotNull(getSuitableInspection(toolWrapper.getTool(), rootType), inspections);
    }
  }
  return inspections;
}
 
Example 48
Project: intellij-ce-playground   File: ModuleTestCase.java   Source Code and License 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
  try {
    ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    List<Throwable> errors = null;
    AccessToken token = WriteAction.start();
    try {
      for (Module module : myModulesToDispose) {
        try {
          String moduleName = module.getName();
          if (moduleManager.findModuleByName(moduleName) != null) {
            moduleManager.disposeModule(module);
          }
        }
        catch (Throwable e) {
          if (errors == null) {
            errors = new SmartList<Throwable>();
          }
          errors.add(e);
        }
      }
    }
    finally {
      token.finish();
    }

    CompoundRuntimeException.throwIfNotEmpty(errors);
  }
  finally {
    myModulesToDispose.clear();
    super.tearDown();
  }
}
 
Example 49
Project: intellij-ce-playground   File: ContentManagerImpl.java   Source Code and License 5 votes vote down vote up
@Override
public List<SwitchTarget> getTargets(boolean onlyVisible, boolean originalProvider) {
  if (myUI instanceof SwitchProvider) {
    return ((SwitchProvider)myUI).getTargets(onlyVisible, false);
  }
  return new SmartList<SwitchTarget>();
}
 
Example 50
Project: intellij-ce-playground   File: PackagePrefixIndex.java   Source Code and License 5 votes vote down vote up
private static Collection<String> getAllPackagePrefixes(final GlobalSearchScope scope, final MultiMap<String, Module> map) {
  if (scope == null) return map.keySet();

  List<String> result = new SmartList<String>();
  for (final String prefix : map.keySet()) {
    modules: for (final Module module : map.get(prefix)) {
      if (scope.isSearchInModuleContent(module)) {
        result.add(prefix);
        break modules;
      }
    }
  }
  return result;
}
 
Example 51
Project: intellij-ce-playground   File: PyAssignmentStatementImpl.java   Source Code and License 5 votes vote down vote up
@NotNull
public List<Pair<PyExpression, PyExpression>> getTargetsToValuesMapping() {
  List<Pair<PyExpression, PyExpression>> ret = new SmartList<Pair<PyExpression, PyExpression>>();
  if (!PsiTreeUtil.hasErrorElements(this)) { // no parse errors
    PyExpression[] constituents = PsiTreeUtil.getChildrenOfType(this, PyExpression.class); // "a = b = c" -> [a, b, c]
    if (constituents != null && constituents.length > 1) {
      PyExpression rhs = constituents[constituents.length - 1]; // last
      List<PyExpression> lhses = Lists.newArrayList(constituents);
      if (lhses.size()>0) lhses.remove(lhses.size()-1); // copy all but last; most often it's one element.
      for (PyExpression lhs : lhses) mapToValues(lhs, rhs, ret);
    }
  }
  return ret;
}
 
Example 52
Project: intellij-ce-playground   File: RunManagerImpl.java   Source Code and License 5 votes vote down vote up
@NotNull
private static List<BeforeRunTask> getCopies(@NotNull List<BeforeRunTask> original) {
  List<BeforeRunTask> result = new SmartList<BeforeRunTask>();
  for (BeforeRunTask task : original) {
    if (task.isEnabled()) {
      result.add(task.clone());
    }
  }
  return result;
}
 
Example 53
Project: intellij-ce-playground   File: PropertiesUtil.java   Source Code and License 5 votes vote down vote up
/**
 * @deprecated use PropertiesUtil.findAllProperties(ResourceBundle resourceBundle, String key)
 */
@NotNull
@Deprecated
public static List<IProperty> findAllProperties(Project project, @NotNull ResourceBundle resourceBundle, String key) {
  List<IProperty> result = new SmartList<IProperty>();
  List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
  for (PropertiesFile propertiesFile : propertiesFiles) {
    result.addAll(propertiesFile.findPropertiesByKey(key));
  }
  return result;
}
 
Example 54
Project: intellij-ce-playground   File: XsdEnumerationDescriptor.java   Source Code and License 5 votes vote down vote up
private String[] getEnumeratedValues(boolean forCompletion) {
  final List<String> list = new SmartList<String>();
  processEnumeration(null, new PairProcessor<PsiElement, String>() {
    @Override
    public boolean process(PsiElement element, String s) {
      list.add(s);
      return true;
    }
  }, forCompletion);
  String defaultValue = getDefaultValue();
  if (defaultValue != null) {
    list.add(defaultValue);
  }
  return ArrayUtil.toStringArray(list);
}
 
Example 55
Project: intellij-ce-playground   File: PackagingElementNode.java   Source Code and License 5 votes vote down vote up
public PackagingElementNode(@NotNull E packagingElement, ArtifactEditorContext context, @Nullable CompositePackagingElementNode parentNode,
                            @Nullable CompositePackagingElement<?> parentElement,
                            @NotNull Collection<PackagingNodeSource> nodeSources) {
  super(context, parentNode, packagingElement.createPresentation(context));
  myParentNode = parentNode;
  myParentElements.put(packagingElement, parentElement);
  myNodeSources.putAll(packagingElement, nodeSources);
  myPackagingElements = new SmartList<E>();
  doAddElement(packagingElement);
}
 
Example 56
Project: intellij-ce-playground   File: ColorPickerListenerFactory.java   Source Code and License 5 votes vote down vote up
@NotNull
public static List<ColorPickerListener> createListenersFor(@Nullable PsiElement element) {
  List<ColorPickerListener> listeners = null;
  for (ColorPickerListenerFactory factory : EP_NAME.getExtensions()) {
    ColorPickerListener listener = factory.createListener(element);
    if (listener != null) {
      if (listeners == null) {
        listeners = new SmartList<ColorPickerListener>();
      }
      listeners.add(listener);
    }
  }
  return ContainerUtil.notNullize(listeners);
}
 
Example 57
Project: intellij-ce-playground   File: CachedRelevantStaticMethodSearcher.java   Source Code and License 5 votes vote down vote up
private static List<UsageIndexValue> extractStaticMethods(final TreeSet<UsageIndexValue> indexValues) {
  final List<UsageIndexValue> relevantStaticMethods = new SmartList<UsageIndexValue>();
  for (final UsageIndexValue indexValue : indexValues) {
    if (indexValue.getMethodIncompleteSignature().isStatic()) {
      relevantStaticMethods.add(indexValue);
    }
  }
  return relevantStaticMethods;
}
 
Example 58
Project: intellij-ce-playground   File: BuildManager.java   Source Code and License 5 votes vote down vote up
public Collection<TaskFuture> cancelAutoMakeTasks(Project project) {
  final Collection<TaskFuture> futures = new SmartList<TaskFuture>();
  synchronized (myAutomakeFutures) {
    for (Map.Entry<TaskFuture, Project> entry : myAutomakeFutures.entrySet()) {
      if (entry.getValue().equals(project)) {
        final TaskFuture future = entry.getKey();
        future.cancel(false);
        futures.add(future);
      }
    }
  }
  return futures;
}
 
Example 59
Project: intellij-ce-playground   File: EditorComposite.java   Source Code and License 5 votes vote down vote up
@NotNull
private List<JComponent> getTopBottomComponents(@NotNull FileEditor editor, boolean top) {
  SmartList<JComponent> result = new SmartList<JComponent>();
  JComponent container = top ? myTopComponents.get(editor) : myBottomComponents.get(editor);
  for (Component each : container.getComponents()) {
    if (each instanceof TopBottomComponentWrapper) {
      result.add(((TopBottomComponentWrapper)each).getWrappee());
    }
  }
  return Collections.unmodifiableList(result);
}
 
Example 60
Project: intellij-ce-playground   File: BaseSplitter.java   Source Code and License 5 votes vote down vote up
@NotNull
static protected List<TextRange> excludeByPattern(String text, TextRange range, @NotNull Pattern toExclude, int groupToInclude) {
  List<TextRange> toCheck = new SmartList<TextRange>();
  int from = range.getStartOffset();
  int till;
  boolean addLast = true;
  Matcher matcher = toExclude.matcher(StringUtil.newBombedCharSequence(range.substring(text), 500));
  try {
    while (matcher.find()) {
      checkCancelled();
      TextRange found = matcherRange(range, matcher);
      till = found.getStartOffset();
      if (range.getEndOffset() - found.getEndOffset() < MIN_RANGE_LENGTH) {
        addLast = false;
      }
      if (!badSize(from, till)) {
        toCheck.add(new TextRange(from, till));
      }
      if (groupToInclude > 0) {
        TextRange contentFound = matcherRange(range, matcher, groupToInclude);
        if (badSize(contentFound.getEndOffset(), contentFound.getStartOffset())) {
          toCheck.add(TextRange.create(contentFound));
        }
      }
      from = found.getEndOffset();
    }
    till = range.getEndOffset();
    if (badSize(from, till)) {
      return toCheck;
    }
    if (addLast) {
      toCheck.add(new TextRange(from, till));
    }
    return toCheck;
  }
  catch (ProcessCanceledException e) {
    return Collections.singletonList(range);
  }
}