Java Code Examples for com.intellij.util.SmartList#add()

The following examples show how to use com.intellij.util.SmartList#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtractMethodPanel.java    From IntelliJDeodorant with MIT License 6 votes vote down vote up
/**
 * Collects statements that can be extracted into a separate method.
 */
public SmartList<PsiStatement> getStatementsToExtract(ASTSlice slice) {
    Set<PDGNode> nodes = slice.getSliceNodes();
    SmartList<PsiStatement> statementsToExtract = new SmartList<>();

    for (PDGNode pdgNode : nodes) {
        boolean isNotChild = true;
        for (PDGNode node : nodes) {
            if (isChild(node.getASTStatement(), pdgNode.getASTStatement())) {
                isNotChild = false;
            }
        }
        if (isNotChild) {
            statementsToExtract.add(pdgNode.getASTStatement());
        }
    }
    return statementsToExtract;
}
 
Example 2
Source File: ArtifactCompilerCompileItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ArtifactPackagingItemOutputState computeOutputState() {
  final SmartList<Pair<String, Long>> pairs = new SmartList<Pair<String, Long>>();
  for (DestinationInfo destination : myDestinations) {
    destination.update();
    final VirtualFile outputFile = destination.getOutputFile();
    long timestamp = outputFile != null ? outputFile.getTimeStamp() : -1;
    pairs.add(Pair.create(destination.getOutputPath(), timestamp));
  }
  return new ArtifactPackagingItemOutputState(pairs);
}
 
Example 3
Source File: ArtifactPackagingItemExternalizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ArtifactPackagingItemOutputState read(DataInput in) throws IOException {
  int size = in.readInt();
  SmartList<Pair<String, Long>> destinations = new SmartList<Pair<String, Long>>();
  while (size-- > 0) {
    String path = IOUtil.readUTF(in);
    long outputTimestamp = in.readLong();
    destinations.add(Pair.create(path, outputTimestamp));
  }
  return new ArtifactPackagingItemOutputState(destinations);
}
 
Example 4
Source File: DesktopEditorComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private List<JComponent> getTopBottomComponents(@Nonnull FileEditor editor, boolean top) {
  SmartList<JComponent> result = new SmartList<>();
  JComponent container = top ? myTopComponents.get(editor) : myBottomComponents.get(editor);
  for (Component each : container.getComponents()) {
    if (each instanceof NonOpaquePanel) {
      result.add(((NonOpaquePanel)each).getTargetComponent());
    }
  }
  return Collections.unmodifiableList(result);
}
 
Example 5
Source File: LibraryDetectionManagerImpl.java    From consulo with Apache License 2.0 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 6
Source File: ClassInstanceCreationObject.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
public List<String> getParameterList() {
    SmartList<String> list = new SmartList<>();
    for (TypeObject typeObject : parameterList)
        list.add(typeObject.toString());
    return list;
}
 
Example 7
Source File: DistanceMatrix.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
private List<MoveMethodCandidateRefactoring> identifyConceptualBindings(MyMethod method, Set<String> targetClasses) {
    SmartList<MoveMethodCandidateRefactoring> candidateRefactoringList = new SmartList<>();
    MethodObject methodObject = method.getMethodObject();
    String sourceClass = method.getClassOrigin();
    for (String targetClass : targetClasses) {
        if (!targetClass.equals(sourceClass)) {
            ClassObject targetClassObject = system.getClass(targetClass).getClassObject();
            ListIterator<ParameterObject> parameterIterator = methodObject.getParameterListIterator();
            while (parameterIterator.hasNext()) {
                ParameterObject parameter = parameterIterator.next();
                Association association = system.containsAssociationWithMultiplicityBetweenClasses(targetClass, parameter.getType().getClassType());
                if (association != null) {
                    List<MethodInvocationObject> methodInvocations = methodObject.getMethodInvocations();
                    for (MethodInvocationObject methodInvocation : methodInvocations) {
                        if (methodInvocation.getOriginClassName().equals(targetClass)) {
                            PsiMethodCallExpression invocation = methodInvocation.getMethodInvocation();
                            boolean parameterIsPassedAsArgument = false;
                            PsiExpression[] invocationArguments = invocation.getArgumentList().getExpressions();
                            for (PsiExpression expression : invocationArguments) {
                                if (expression instanceof PsiReferenceExpression) {
                                    PsiReferenceExpression argumentName = (PsiReferenceExpression) expression;
                                    if (parameter.getSingleVariableDeclaration().equals(argumentName.resolve()))
                                        parameterIsPassedAsArgument = true;
                                }
                            }
                            if (parameterIsPassedAsArgument) {
                                MethodObject invokedMethod = targetClassObject.getMethod(methodInvocation);
                                if (invokedMethod != null) {
                                    List<FieldInstructionObject> fieldInstructions = invokedMethod.getFieldInstructions();
                                    boolean containerFieldIsAccessed = false;
                                    for (FieldInstructionObject fieldInstruction : fieldInstructions) {
                                        if (association.getFieldObject().equals(fieldInstruction)) {
                                            containerFieldIsAccessed = true;
                                            break;
                                        }
                                    }
                                    if (containerFieldIsAccessed) {
                                        MyClass mySourceClass = classList.get(classIndexMap.get(sourceClass));
                                        MyClass myTargetClass = classList.get(classIndexMap.get(targetClass));
                                        MoveMethodCandidateRefactoring candidate = new MoveMethodCandidateRefactoring(system, mySourceClass, myTargetClass, method);
                                        Map<PsiMethodCallExpression, PsiMethod> additionalMethodsToBeMoved = candidate.getAdditionalMethodsToBeMoved();
                                        Collection<PsiMethod> values = additionalMethodsToBeMoved.values();
                                        Set<String> methodEntitySet = entityMap.get(method.toString());
                                        Set<String> sourceClassEntitySet = classMap.get(sourceClass);
                                        Set<String> targetClassEntitySet = classMap.get(targetClass);
                                        Set<String> intersectionWithSourceClass = DistanceCalculator.intersection(methodEntitySet, sourceClassEntitySet);
                                        Set<String> intersectionWithTargetClass = DistanceCalculator.intersection(methodEntitySet, targetClassEntitySet);
                                        Set<String> entitiesToRemoveFromIntersectionWithSourceClass = new LinkedHashSet<>();
                                        if (!values.isEmpty()) {
                                            for (String s : intersectionWithSourceClass) {
                                                int entityPosition = entityIndexMap.get(s);
                                                Entity e = entityList.get(entityPosition);
                                                if (e instanceof MyMethod) {
                                                    MyMethod myInvokedMethod = (MyMethod) e;
                                                    if (values.contains(myInvokedMethod.getMethodObject().getMethodDeclaration())) {
                                                        entitiesToRemoveFromIntersectionWithSourceClass.add(s);
                                                    }
                                                }
                                            }
                                            intersectionWithSourceClass.removeAll(entitiesToRemoveFromIntersectionWithSourceClass);
                                        }
                                        if (intersectionWithTargetClass.size() >= intersectionWithSourceClass.size()) {
                                            if (candidate.isApplicable()) {
                                                int sourceClassDependencies = candidate.getDistinctSourceDependencies();
                                                int targetClassDependencies = candidate.getDistinctTargetDependencies();
                                                if (sourceClassDependencies <= maximumNumberOfSourceClassMembersAccessedByMoveMethodCandidate
                                                        && sourceClassDependencies < targetClassDependencies) {
                                                    candidateRefactoringList.add(candidate);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return candidateRefactoringList;
}
 
Example 8
Source File: DuplicatesInspectionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkFile(@Nonnull final PsiFile psiFile, @Nonnull final InspectionManager manager, final boolean isOnTheFly) {
  final VirtualFile virtualFile = psiFile.getVirtualFile();
  if (!(virtualFile instanceof VirtualFileWithId) || /*!isOnTheFly || */!DuplicatesIndex.ourEnabled) return ProblemDescriptor.EMPTY_ARRAY;
  final DuplicatesProfile profile = DuplicatesIndex.findDuplicatesProfile(psiFile.getFileType());
  if (profile == null) return ProblemDescriptor.EMPTY_ARRAY;


  final FileASTNode node = psiFile.getNode();
  boolean usingLightProfile = profile instanceof LightDuplicateProfile &&
                              node.getElementType() instanceof ILightStubFileElementType &&
                              DuplicatesIndex.ourEnabledLightProfiles;
  final Project project = psiFile.getProject();
  DuplicatedCodeProcessor<?> processor;
  if (usingLightProfile) {
    processor = processLightDuplicates(node, virtualFile, (LightDuplicateProfile)profile, project);
  }
  else {
    processor = processPsiDuplicates(psiFile, virtualFile, profile, project);
  }
  if (processor == null) return null;

  final SmartList<ProblemDescriptor> descriptors = new SmartList<>();
  final VirtualFile baseDir = project.getBaseDir();
  for (Map.Entry<Integer, TextRange> entry : processor.reportedRanges.entrySet()) {
    final Integer offset = entry.getKey();
    if (!usingLightProfile && processor.fragmentSize.get(offset) < MIN_FRAGMENT_SIZE) continue;
    final VirtualFile file = processor.reportedFiles.get(offset);
    String path = null;

    if (file.equals(virtualFile)) {
      path = "this file";
    }
    else if (baseDir != null) {
      path = VfsUtilCore.getRelativePath(file, baseDir);
    }
    if (path == null) {
      path = file.getPath();
    }
    String message = "Found duplicated code in " + path;

    PsiElement targetElement = processor.reportedPsi.get(offset);
    TextRange rangeInElement = entry.getValue();
    final int offsetInOtherFile = processor.reportedOffsetInOtherFiles.get(offset);

    LocalQuickFix fix = isOnTheFly ? createNavigateToDupeFix(file, offsetInOtherFile) : null;
    long hash = processor.fragmentHash.get(offset);

    int hash2 = (int)(hash >> 32);
    LocalQuickFix viewAllDupesFix = isOnTheFly && hash != 0 ? createShowOtherDupesFix(virtualFile, offset, (int)hash, hash2) : null;

    boolean onlyExtractable = Registry.is("duplicates.inspection.only.extractable");
    LocalQuickFix extractMethodFix =
      (isOnTheFly || onlyExtractable) && hash != 0 ? createExtractMethodFix(targetElement, rangeInElement, (int)hash, hash2) : null;
    if (onlyExtractable) {
      if (extractMethodFix == null) return null;
      if (!isOnTheFly) extractMethodFix = null;
    }

    ProblemDescriptor descriptor = manager
      .createProblemDescriptor(targetElement, rangeInElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly, fix,
                               viewAllDupesFix, extractMethodFix);
    descriptors.add(descriptor);
  }

  return descriptors.isEmpty() ? null : descriptors.toArray(ProblemDescriptor.EMPTY_ARRAY);
}