Example #1
0
  @Override
  public int getId(
      @NotNull VirtualFile parent, @NotNull String childName, @NotNull NewVirtualFileSystem fs) {
    int parentId = getFileId(parent);
    int[] children = FSRecords.list(parentId);

    if (children.length > 0) {
      // fast path, check that some child has same nameId as given name, this avoid O(N) on
      // retrieving names for processing non-cached children
      int nameId = FSRecords.getNameId(childName);
      for (final int childId : children) {
        if (nameId == FSRecords.getNameId(childId)) {
          return childId;
        }
      }
      // for case sensitive system the above check is exhaustive in consistent state of vfs
    }

    for (final int childId : children) {
      if (namesEqual(fs, childName, FSRecords.getName(childId))) return childId;
    }

    final VirtualFile fake = new FakeVirtualFile(parent, childName);
    final FileAttributes attributes = fs.getAttributes(fake);
    if (attributes != null) {
      final int child = createAndFillRecord(fs, fake, parentId, attributes);
      FSRecords.updateList(parentId, ArrayUtil.append(children, child));
      return child;
    }

    return 0;
  }
  private void reportNullableArgumentsPassedToNonAnnotated(
      DataFlowInstructionVisitor visitor, ProblemsHolder holder, Set<PsiElement> reportedAnchors) {
    for (PsiElement expr :
        visitor.getProblems(NullabilityProblem.passingNullableArgumentToNonAnnotatedParameter)) {
      if (reportedAnchors.contains(expr)) continue;

      final String text =
          isNullLiteralExpression(expr)
              ? "Passing <code>null</code> argument to non annotated parameter"
              : "Argument <code>#ref</code> #loc might be null but passed to non annotated parameter";
      LocalQuickFix[] fixes =
          createNPEFixes((PsiExpression) expr, (PsiExpression) expr, holder.isOnTheFly());
      final PsiElement parent = expr.getParent();
      if (parent instanceof PsiExpressionList) {
        final int idx = ArrayUtilRt.find(((PsiExpressionList) parent).getExpressions(), expr);
        if (idx > -1) {
          final PsiElement gParent = parent.getParent();
          if (gParent instanceof PsiCallExpression) {
            final PsiMethod psiMethod = ((PsiCallExpression) gParent).resolveMethod();
            if (psiMethod != null
                && psiMethod.getManager().isInProject(psiMethod)
                && AnnotationUtil.isAnnotatingApplicable(psiMethod)) {
              final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
              if (idx < parameters.length) {
                final AddNullableAnnotationFix addNullableAnnotationFix =
                    new AddNullableAnnotationFix(parameters[idx]);
                fixes =
                    fixes == null
                        ? new LocalQuickFix[] {addNullableAnnotationFix}
                        : ArrayUtil.append(fixes, addNullableAnnotationFix);
                holder.registerProblem(expr, text, fixes);
                reportedAnchors.add(expr);
              }
            }
          }
        }
      }
    }
  }
Example #3
0
 private static void appendIdToParentList(final int parentId, final int childId) {
   int[] childrenList = FSRecords.list(parentId);
   childrenList = ArrayUtil.append(childrenList, childId);
   FSRecords.updateList(parentId, childrenList);
 }
  private ColumnInfo[] createInjectionColumnInfos() {
    final TableCellRenderer booleanCellRenderer = createBooleanCellRenderer();
    final TableCellRenderer displayNameCellRenderer = createDisplayNameCellRenderer();
    final TableCellRenderer languageCellRenderer = createLanguageCellRenderer();
    final Comparator<InjInfo> languageComparator =
        new Comparator<InjInfo>() {
          public int compare(final InjInfo o1, final InjInfo o2) {
            return Comparing.compare(
                o1.injection.getInjectedLanguageId(), o2.injection.getInjectedLanguageId());
          }
        };
    final Comparator<InjInfo> displayNameComparator =
        new Comparator<InjInfo>() {
          public int compare(final InjInfo o1, final InjInfo o2) {
            final int support =
                Comparing.compare(o1.injection.getSupportId(), o2.injection.getSupportId());
            if (support != 0) return support;
            return Comparing.compare(o1.injection.getDisplayName(), o2.injection.getDisplayName());
          }
        };
    final ColumnInfo[] columnInfos = {
      new ColumnInfo<InjInfo, Boolean>(" ") {
        @Override
        public Class getColumnClass() {
          return Boolean.class;
        }

        @Override
        public Boolean valueOf(final InjInfo o) {
          return o.injection.isEnabled();
        }

        @Override
        public boolean isCellEditable(final InjInfo injection) {
          return true;
        }

        @Override
        public void setValue(final InjInfo injection, final Boolean value) {
          injection.injection.setPlaceEnabled(null, value.booleanValue());
        }

        @Override
        public TableCellRenderer getRenderer(final InjInfo injection) {
          return booleanCellRenderer;
        }
      },
      new ColumnInfo<InjInfo, InjInfo>("Name") {
        @Override
        public InjInfo valueOf(final InjInfo info) {
          return info;
        }

        @Override
        public Comparator<InjInfo> getComparator() {
          return displayNameComparator;
        }

        @Override
        public TableCellRenderer getRenderer(final InjInfo injection) {
          return displayNameCellRenderer;
        }
      },
      new ColumnInfo<InjInfo, InjInfo>("Language") {
        @Override
        public InjInfo valueOf(final InjInfo info) {
          return info;
        }

        @Override
        public Comparator<InjInfo> getComparator() {
          return languageComparator;
        }

        @Override
        public TableCellRenderer getRenderer(final InjInfo info) {
          return languageCellRenderer;
        }
      }
    };
    if (myInfos.length > 1) {
      final TableCellRenderer typeRenderer = createTypeRenderer();
      return ArrayUtil.append(
          columnInfos,
          new ColumnInfo<InjInfo, String>("Scope") {
            @Override
            public String valueOf(final InjInfo info) {
              return info.bundled ? "Built-in" : info.cfgInfo.title;
            }

            @Override
            public TableCellRenderer getRenderer(final InjInfo injInfo) {
              return typeRenderer;
            }

            @Override
            public int getWidth(final JTable table) {
              return table
                  .getFontMetrics(table.getFont())
                  .stringWidth(StringUtil.repeatSymbol('m', 6));
            }

            @Override
            public Comparator<InjInfo> getComparator() {
              return new Comparator<InjInfo>() {
                @Override
                public int compare(final InjInfo o1, final InjInfo o2) {
                  return Comparing.compare(valueOf(o1), valueOf(o2));
                }
              };
            }
          });
    }
    return columnInfos;
  }