@NotNull
 @Override
 protected ElementPattern<PsiElement> compute() {
   return psiElement()
       .andNot(psiElement().afterLeaf("@", "."))
       .andOr(
           psiElement()
               .and(new FilterPattern(CLASS_BODY.getValue()))
               .andOr(
                   new FilterPattern(END_OF_BLOCK.getValue()),
                   psiElement()
                       .afterLeaf(
                           or(
                               psiElement().inside(PsiModifierList.class),
                               psiElement()
                                   .withElementType(JavaTokenType.GT)
                                   .inside(PsiTypeParameterList.class)))),
           psiElement()
               .withParents(
                   PsiJavaCodeReferenceElement.class, PsiTypeElement.class, PsiMember.class),
           psiElement()
               .withParents(
                   PsiJavaCodeReferenceElement.class,
                   PsiTypeElement.class,
                   PsiClassLevelDeclarationStatement.class));
 }
 @Nullable
 public RelativePoint getHyperlinkLocation(HyperlinkInfo info) {
   Editor editor = myLogEditor.getValue();
   Project project = editor.getProject();
   RangeHighlighter range = myHyperlinkSupport.getValue().findHyperlinkRange(info);
   Window window = NotificationsManagerImpl.findWindowForBalloon(project);
   if (range != null && window != null) {
     Point point =
         editor.visualPositionToXY(editor.offsetToVisualPosition(range.getStartOffset()));
     return new RelativePoint(
         window, SwingUtilities.convertPoint(editor.getContentComponent(), point, window));
   }
   return null;
 }
  private void declareCompletionSpaces() {
    declareFinalScope(PsiFile.class);

    {
      // Class body
      final CompletionVariant variant = new CompletionVariant(CLASS_BODY.getValue());
      variant.includeScopeClass(PsiClass.class, true);
      registerVariant(variant);
    }
    {
      // Method body
      final CompletionVariant variant =
          new CompletionVariant(
              new AndFilter(
                  new InsideElementFilter(new ClassFilter(PsiCodeBlock.class)),
                  new NotFilter(
                      new InsideElementFilter(
                          new ClassFilter(JspClassLevelDeclarationStatement.class)))));
      variant.includeScopeClass(PsiMethod.class, true);
      variant.includeScopeClass(PsiClassInitializer.class, true);
      registerVariant(variant);
    }

    {
      // Field initializer
      final CompletionVariant variant =
          new CompletionVariant(new AfterElementFilter(new TextFilter("=")));
      variant.includeScopeClass(PsiField.class, true);
      registerVariant(variant);
    }

    declareFinalScope(PsiLiteralExpression.class);
    declareFinalScope(PsiComment.class);
  }
  private static boolean isStatementPosition(PsiElement position) {
    if (PsiTreeUtil.getNonStrictParentOfType(position, PsiLiteralExpression.class, PsiComment.class)
        != null) {
      return false;
    }

    if (psiElement()
        .withSuperParent(2, PsiConditionalExpression.class)
        .andNot(psiElement().insideStarting(psiElement(PsiConditionalExpression.class)))
        .accepts(position)) {
      return false;
    }

    if (END_OF_BLOCK.getValue().isAcceptable(position, position)
        && PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, true, PsiMember.class)
            != null) {
      return true;
    }

    if (psiElement()
        .withParents(
            PsiReferenceExpression.class, PsiExpressionStatement.class, PsiIfStatement.class)
        .andNot(psiElement().afterLeaf("."))
        .accepts(position)) {
      PsiElement stmt = position.getParent().getParent();
      PsiIfStatement ifStatement = (PsiIfStatement) stmt.getParent();
      if (ifStatement.getElseBranch() == stmt || ifStatement.getThenBranch() == stmt) {
        return true;
      }
    }

    return false;
  }
  public static boolean isSuitableForClass(PsiElement position) {
    if (psiElement().afterLeaf("@").accepts(position)
        || PsiTreeUtil.getNonStrictParentOfType(
                position,
                PsiLiteralExpression.class,
                PsiComment.class,
                PsiExpressionCodeFragment.class)
            != null) {
      return false;
    }

    PsiElement prev = PsiTreeUtil.prevVisibleLeaf(position);
    if (prev == null) {
      return true;
    }
    if (psiElement()
            .withoutText(".")
            .inside(
                psiElement(PsiModifierList.class)
                    .withParent(
                        not(psiElement(PsiParameter.class))
                            .andNot(psiElement(PsiParameterList.class))))
            .accepts(prev)
        && !psiElement().inside(PsiAnnotationParameterList.class).accepts(prev)) {
      return true;
    }

    return END_OF_BLOCK.getValue().isAcceptable(position, position);
  }
 public void updateDataModel() {
   final Sdk chosenJdk = myPanel.getValue().getChosenJdk();
   if (chosenJdk != null && chosenJdk.getSdkType().equals(LuaSdkType.getInstance())) {
     if (myContext.getProjectJdk() == null) {
       myContext.setProjectJdk(chosenJdk);
     } else {
       myModuleBuilder.setSdk(chosenJdk);
     }
   }
 }
 @Nullable
 public static CompletionData getCompletionDataByFileType(FileType fileType) {
   for (CompletionDataEP ep : Extensions.getExtensions(CompletionDataEP.EP_NAME)) {
     if (ep.fileType.equals(fileType.getName())) {
       return ep.getHandler();
     }
   }
   final NotNullLazyValue<CompletionData> lazyValue = ourCustomCompletionDatas.get(fileType);
   return lazyValue == null ? null : lazyValue.getValue();
 }
  private void highlightNotification(
      final Notification notification, String message, final int line1, final int line2) {

    final MarkupModel markupModel = myLogEditor.getValue().getMarkupModel();
    TextAttributes bold = new TextAttributes(null, null, null, null, Font.BOLD);
    final List<RangeHighlighter> lineColors = new ArrayList<RangeHighlighter>();
    for (int line = line1; line < line2; line++) {
      final RangeHighlighter lineHighlighter =
          markupModel.addLineHighlighter(line, HighlighterLayer.CARET_ROW + 1, bold);
      Color color =
          notification.getType() == NotificationType.ERROR
              ? JBColor.RED
              : notification.getType() == NotificationType.WARNING ? JBColor.YELLOW : JBColor.GREEN;
      lineHighlighter.setErrorStripeMarkColor(color);
      lineHighlighter.setErrorStripeTooltip(message);
      lineColors.add(lineHighlighter);
    }

    final Runnable removeHandler =
        new Runnable() {
          @Override
          public void run() {
            for (RangeHighlighter color : lineColors) {
              markupModel.removeHighlighter(color);
            }

            TextAttributes attributes =
                EditorColorsManager.getInstance()
                    .getGlobalScheme()
                    .getAttributes(ConsoleViewContentType.LOG_EXPIRED_ENTRY);
            for (int line = line1; line < line2; line++) {
              markupModel.addLineHighlighter(line, HighlighterLayer.CARET_ROW + 1, attributes);
            }

            TextAttributes italic = new TextAttributes(null, null, null, null, Font.ITALIC);
            for (int line = line1; line < line2; line++) {
              for (RangeHighlighter highlighter :
                  myHyperlinkSupport.getValue().findAllHyperlinksOnLine(line)) {
                markupModel.addRangeHighlighter(
                    highlighter.getStartOffset(),
                    highlighter.getEndOffset(),
                    HighlighterLayer.CARET_ROW + 2,
                    italic,
                    HighlighterTargetArea.EXACT_RANGE);
                myHyperlinkSupport.getValue().removeHyperlink(highlighter);
              }
            }
          }
        };
    if (!notification.isExpired()) {
      myProjectModel.removeHandlers.put(notification, removeHandler);
    } else {
      removeHandler.run();
    }
  }
Esempio n. 9
0
  private void reportIOErrorWithJars(File original, File target, IOException e) {
    LOG.warn(e);

    String path = original.getPath();
    myFileSystem.setNoCopyJarForPath(path);

    String message =
        VfsBundle.message("jar.copy.error.message", path, target.getPath(), e.getMessage());
    ERROR_COPY_NOTIFICATION
        .getValue()
        .createNotification(message, NotificationType.ERROR)
        .notify(null);
  }
  /** aClass == null for JspDeclaration scope */
  protected void initVariantsInClassScope() {
    // Completion for extends keyword
    // position
    {
      final ElementFilter position =
          new AndFilter(
              new NotFilter(CLASS_BODY.getValue()),
              new NotFilter(
                  new AfterElementFilter(new ContentFilter(new TextFilter(PsiKeyword.EXTENDS)))),
              new NotFilter(
                  new AfterElementFilter(new ContentFilter(new TextFilter(PsiKeyword.IMPLEMENTS)))),
              new NotFilter(new LeftNeighbour(new LeftNeighbour(new TextFilter("<", ",")))),
              new NotFilter(new ScopeFilter(new EnumOrAnnotationTypeFilter())),
              new LeftNeighbour(
                  new OrFilter(new ClassFilter(PsiIdentifier.class), new TextFilter(">"))));
      // completion
      final CompletionVariant variant = new CompletionVariant(position);
      variant.includeScopeClass(PsiClass.class, true);
      variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE_BEFORE_WORD);
      variant.excludeScopeClass(PsiAnonymousClass.class);
      variant.excludeScopeClass(PsiTypeParameter.class);

      registerVariant(variant);
    }
    // Completion for implements keyword
    // position
    {
      final ElementFilter position =
          new AndFilter(
              new NotFilter(CLASS_BODY.getValue()),
              new NotFilter(
                  new BeforeElementFilter(new ContentFilter(new TextFilter(PsiKeyword.EXTENDS)))),
              new NotFilter(
                  new AfterElementFilter(new ContentFilter(new TextFilter(PsiKeyword.IMPLEMENTS)))),
              new NotFilter(new LeftNeighbour(new LeftNeighbour(new TextFilter("<", ",")))),
              new LeftNeighbour(
                  new OrFilter(new ClassFilter(PsiIdentifier.class), new TextFilter(">"))),
              new NotFilter(new ScopeFilter(new InterfaceFilter())));
      // completion
      final CompletionVariant variant = new CompletionVariant(position);
      variant.includeScopeClass(PsiClass.class, true);
      variant.addCompletion(PsiKeyword.IMPLEMENTS, TailType.HUMBLE_SPACE_BEFORE_WORD);
      variant.excludeScopeClass(PsiAnonymousClass.class);

      registerVariant(variant);
    }

    {
      final CompletionVariant variant =
          new CompletionVariant(
              PsiElement.class,
              psiElement()
                  .afterLeaf(
                      psiElement(PsiIdentifier.class)
                          .afterLeaf(
                              psiElement()
                                  .withText(string().oneOf(",", "<"))
                                  .withParent(PsiTypeParameterList.class))));
      // variant.includeScopeClass(PsiClass.class, true);
      variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE_BEFORE_WORD);
      registerVariant(variant);
    }
  }
 public JComponent getComponent() {
   return myPanel.getValue();
 }
 @NotNull
 private static String getScriptingLines() {
   return MY_SCRIPTING_LINES.getValue();
 }
 public Editor getConsoleEditor() {
   return myLogEditor.getValue();
 }
  void doPrintNotification(final Notification notification) {
    Editor editor = myLogEditor.getValue();
    if (editor.isDisposed()) {
      return;
    }

    Document document = editor.getDocument();
    boolean scroll =
        document.getTextLength() == editor.getCaretModel().getOffset()
            || !editor.getContentComponent().hasFocus();

    Long notificationTime = myProjectModel.getNotificationTime(notification);
    if (notificationTime == null) {
      return;
    }

    String date = DateFormatUtil.formatTimeWithSeconds(notificationTime) + " ";
    append(document, date);

    int startLine = document.getLineCount() - 1;

    EventLog.LogEntry pair =
        EventLog.formatForLog(notification, StringUtil.repeatSymbol(' ', date.length()));

    final NotificationType type = notification.getType();
    TextAttributesKey key =
        type == NotificationType.ERROR
            ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY
            : type == NotificationType.INFORMATION
                ? ConsoleViewContentType.NORMAL_OUTPUT_KEY
                : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY;

    int msgStart = document.getTextLength();
    String message = pair.message;
    append(document, message);

    TextAttributes attributes =
        EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
    int layer = HighlighterLayer.CARET_ROW + 1;
    editor
        .getMarkupModel()
        .addRangeHighlighter(
            msgStart,
            document.getTextLength(),
            layer,
            attributes,
            HighlighterTargetArea.EXACT_RANGE);

    for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
      myHyperlinkSupport
          .getValue()
          .addHyperlink(
              link.first.getStartOffset() + msgStart,
              link.first.getEndOffset() + msgStart,
              null,
              link.second);
    }

    append(document, "\n");

    if (scroll) {
      editor.getCaretModel().moveToOffset(document.getTextLength());
      editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    }

    if (notification.isImportant()) {
      highlightNotification(notification, pair.status, startLine, document.getLineCount() - 1);
    }
  }
Esempio n. 15
0
 @Override
 public Icon getIcon() {
   return myIcon.getValue();
 }
  public void fillCompletions(
      CompletionParameters parameters, final Consumer<LookupElement> result) {
    final PsiElement position = parameters.getPosition();
    if (PsiTreeUtil.getParentOfType(position, PsiComment.class, false) != null) {
      return;
    }

    PsiStatement statement = PsiTreeUtil.getParentOfType(position, PsiExpressionStatement.class);
    if (statement == null) {
      statement = PsiTreeUtil.getParentOfType(position, PsiDeclarationStatement.class);
    }
    PsiElement prevLeaf = PsiTreeUtil.prevVisibleLeaf(position);
    if (statement != null
        && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
      if (!psiElement()
          .withSuperParent(2, PsiSwitchStatement.class)
          .afterLeaf("{")
          .accepts(statement)) {
        PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(prevLeaf, PsiTryStatement.class);
        if (tryStatement == null
            || tryStatement.getCatchSections().length > 0
            || tryStatement.getFinallyBlock() != null) {
          result.consume(
              new OverrideableSpace(
                  createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
        }
      }
    }

    if (isStatementPosition(position)) {
      if (PsiTreeUtil.getParentOfType(position, PsiSwitchStatement.class, false, PsiMember.class)
          != null) {
        result.consume(
            new OverrideableSpace(createKeyword(position, PsiKeyword.CASE), TailType.INSERT_SPACE));
        result.consume(
            new OverrideableSpace(
                createKeyword(position, PsiKeyword.DEFAULT), TailType.CASE_COLON));
        if (START_SWITCH.accepts(position)) {
          return;
        }
      }

      addBreakContinue(result, position);
      addStatementKeywords(result, position);
    }

    if (SUPER_OR_THIS_PATTERN.accepts(position)) {
      final boolean afterDot = AFTER_DOT.accepts(position);
      final boolean insideQualifierClass = isInsideQualifierClass(position);
      final boolean insideInheritorClass =
          PsiUtil.isLanguageLevel8OrHigher(position) && isInsideInheritorClass(position);
      if (!afterDot || insideQualifierClass || insideInheritorClass) {
        if (!afterDot || insideQualifierClass) {
          result.consume(createKeyword(position, PsiKeyword.THIS));
        }

        final LookupItem superItem = (LookupItem) createKeyword(position, PsiKeyword.SUPER);
        if (psiElement()
            .afterLeaf(psiElement().withText("{").withSuperParent(2, psiMethod().constructor(true)))
            .accepts(position)) {
          final PsiMethod method =
              PsiTreeUtil.getParentOfType(position, PsiMethod.class, false, PsiClass.class);
          assert method != null;
          final boolean hasParams = superConstructorHasParameters(method);
          superItem.setInsertHandler(
              new ParenthesesInsertHandler<LookupElement>() {
                @Override
                protected boolean placeCaretInsideParentheses(
                    InsertionContext context, LookupElement item) {
                  return hasParams;
                }

                @Override
                public void handleInsert(InsertionContext context, LookupElement item) {
                  super.handleInsert(context, item);
                  TailType.insertChar(context.getEditor(), context.getTailOffset(), ';');
                }
              });
        }

        result.consume(superItem);
      }
    }

    if (isExpressionPosition(position)) {
      if (PsiTreeUtil.getParentOfType(position, PsiAnnotation.class) == null) {
        result.consume(
            TailTypeDecorator.withTail(
                createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
        result.consume(createKeyword(position, PsiKeyword.NULL));
      }
      if (mayExpectBoolean(parameters)) {
        result.consume(createKeyword(position, PsiKeyword.TRUE));
        result.consume(createKeyword(position, PsiKeyword.FALSE));
      }
    }

    PsiFile file = position.getContainingFile();
    if (!(file instanceof PsiExpressionCodeFragment)
        && !(file instanceof PsiJavaCodeReferenceCodeFragment)
        && !(file instanceof PsiTypeCodeFragment)) {
      if (prevLeaf == null) {
        result.consume(
            new OverrideableSpace(
                createKeyword(position, PsiKeyword.PACKAGE), TailType.HUMBLE_SPACE_BEFORE_WORD));
        result.consume(
            new OverrideableSpace(
                createKeyword(position, PsiKeyword.IMPORT), TailType.HUMBLE_SPACE_BEFORE_WORD));
      } else if (END_OF_BLOCK.getValue().isAcceptable(position, position)
          && PsiTreeUtil.getParentOfType(position, PsiMember.class) == null) {
        result.consume(
            new OverrideableSpace(
                createKeyword(position, PsiKeyword.IMPORT), TailType.HUMBLE_SPACE_BEFORE_WORD));
      }
    }

    if ((isInsideParameterList(position)
            || isAtResourceVariableStart(position)
            || isAtCatchVariableStart(position))
        && !psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position)
        && !AFTER_DOT.accepts(position)) {
      result.consume(
          TailTypeDecorator.withTail(
              createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
    }

    if (isInstanceofPlace(position)) {
      result.consume(
          LookupElementDecorator.withInsertHandler(
              createKeyword(position, PsiKeyword.INSTANCEOF),
              new InsertHandler<LookupElementDecorator<LookupElement>>() {
                @Override
                public void handleInsert(
                    InsertionContext context, LookupElementDecorator<LookupElement> item) {
                  TailType tailType = TailType.HUMBLE_SPACE_BEFORE_WORD;
                  if (tailType.isApplicable(context)) {
                    tailType.processTail(context.getEditor(), context.getTailOffset());
                  }

                  if ('!' == context.getCompletionChar()) {
                    context.setAddCompletionChar(false);
                    context.commitDocument();
                    PsiInstanceOfExpression expr =
                        PsiTreeUtil.findElementOfClassAtOffset(
                            context.getFile(),
                            context.getStartOffset(),
                            PsiInstanceOfExpression.class,
                            false);
                    if (expr != null) {
                      String space =
                          context.getCodeStyleSettings().SPACE_WITHIN_PARENTHESES ? " " : "";
                      context
                          .getDocument()
                          .insertString(expr.getTextRange().getStartOffset(), "!(" + space);
                      context.getDocument().insertString(context.getTailOffset(), space + ")");
                    }
                  }
                }
              }));
    }

    if (isSuitableForClass(position)) {
      for (String s : ModifierChooser.getKeywords(position)) {
        result.consume(
            new OverrideableSpace(createKeyword(position, s), TailType.HUMBLE_SPACE_BEFORE_WORD));
      }
      result.consume(
          new OverrideableSpace(
              createKeyword(position, PsiKeyword.CLASS), TailType.HUMBLE_SPACE_BEFORE_WORD));
      if (PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, true, PsiMember.class)
          == null) {
        result.consume(
            new OverrideableSpace(
                createKeyword(position, PsiKeyword.INTERFACE), TailType.HUMBLE_SPACE_BEFORE_WORD));
        if (PsiUtil.getLanguageLevel(position).isAtLeast(LanguageLevel.JDK_1_5)) {
          result.consume(
              new OverrideableSpace(
                  createKeyword(position, PsiKeyword.ENUM), TailType.INSERT_SPACE));
        }
      }
    }

    addPrimitiveTypes(result, position);

    if (isAfterTypeDot(position)) {
      result.consume(createKeyword(position, PsiKeyword.CLASS));
    }

    addUnfinishedMethodTypeParameters(position, result);

    if (JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN.accepts(position)) {
      result.consume(
          new OverrideableSpace(
              createKeyword(position, PsiKeyword.EXTENDS), TailType.HUMBLE_SPACE_BEFORE_WORD));
      result.consume(
          new OverrideableSpace(
              createKeyword(position, PsiKeyword.SUPER), TailType.HUMBLE_SPACE_BEFORE_WORD));
    }
  }
 @NotNull
 @Override
 protected EditorHyperlinkSupport compute() {
   return new EditorHyperlinkSupport(myLogEditor.getValue(), myProjectModel.getProject());
 }
 @Override
 public JComponent getPreferredFocusedComponent() {
   return myPanel.getValue().getPreferredFocusedComponent();
 }
 public static boolean isGradleAvailable(@Nullable Project project) {
   return LIBRARY_MANAGER.getValue().getGradleHome(project) != null;
 }
Esempio n. 20
0
 @NotNull
 private ITypeSystemStartupContributor[] getStartupContributors() {
   return PLUGIN_LISTENERS.getValue();
 }