當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiUtilBase類代碼示例

本文整理匯總了Java中com.intellij.psi.util.PsiUtilBase的典型用法代碼示例。如果您正苦於以下問題:Java PsiUtilBase類的具體用法?Java PsiUtilBase怎麽用?Java PsiUtilBase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PsiUtilBase類屬於com.intellij.psi.util包,在下文中一共展示了PsiUtilBase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
public void actionPerformed(AnActionEvent event) {
        Project project = event.getData(PlatformDataKeys.PROJECT);
        Editor editor = event.getData(PlatformDataKeys.EDITOR);
        PsiFile mFile = PsiUtilBase.getPsiFileInEditor(editor, project);
        PsiClass psiClass = getTargetClass(editor, mFile);
        GridMain gridMain = new GridMain(psiClass,mFile,project);
        //DBConn dbConn = new DBConn(psiClass,mFile,project);
//        JsonDialog jsonD = new JsonDialog(psiClass, mFile, project);
//        jsonD.setClass(psiClass);
//        jsonD.setFile(mFile);
//        jsonD.setProject(project);
//        jsonD.setSize(600, 400);
//        jsonD.setLocationRelativeTo(null);
//        jsonD.setVisible(true);

    }
 
開發者ID:zeng198821,項目名稱:CodeGenerate,代碼行數:17,代碼來源:MainAction.java

示例2: highlightCurrentColumn

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
@Override
@Contract
public void highlightCurrentColumn(@NotNull final Editor editor) {
    Validate.notNull(editor);

    final Project project = editor.getProject();

    if (null == project) {
        return;
    }

    if (project.isDisposed()) {
        return;
    }

    final Language languageInEditor = PsiUtilBase.getLanguageInEditor(editor, project);

    if (languageInEditor instanceof ImpexLanguage) {
        this.highlightColumnOfValueUnderCaret(editor);
    }
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:22,代碼來源:DefaultImpexColumnHighlighterService.java

示例3: highlightHeader

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
private void highlightHeader(final PsiTreeChangeEvent psiTreeChangeEvent) {
    final PsiFile file = psiTreeChangeEvent.getFile();

    if (null == file) {
        return;
    }

    final Editor editor = PsiUtilBase.findEditor(file);

    if (null == editor) {
        return;
    }

    impexHeaderNameHighlighterService.highlightCurrentHeader(editor);
    impexColumnHighlighterService.highlightCurrentColumn(editor);
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:17,代碼來源:ImpexHeaderHighlighterComponent.java

示例4: highlightCurrentHeader

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
@Override
@Contract(pure = false)
public void highlightCurrentHeader(@NotNull final Editor editor) {
    Validate.notNull(editor);

    final Project project = editor.getProject();

    if (null == project) {
        return;
    }

    if (project.isDisposed()) {
        return;
    }

    final Language languageInEditor = PsiUtilBase.getLanguageInEditor(editor, project);

    if (languageInEditor instanceof ImpexLanguage) {
        this.highlightHeaderOfValueUnderCaret(editor);
    }
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:22,代碼來源:DefaultImpexHeaderNameHighlighterService.java

示例5: getHeaderOfValueGroupUnderCaret

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
public static PsiElement getHeaderOfValueGroupUnderCaret(@NotNull final Editor editor) {
    Validate.notNull(editor);

    final PsiElement psiElementUnderCaret = PsiUtilBase.getElementAtCaret(editor);
    if (null == psiElementUnderCaret) {
        return null;
    }

    final ImpexValueGroup valueGroup = ImpexPsiUtils.getClosestSelectedValueGroupFromTheSameLine(
        psiElementUnderCaret);
    if (null != valueGroup) {

        final PsiElement header = ImpexPsiUtils.getHeaderForValueGroup(valueGroup);
        if (null != header) {

            return header;
        }
    }

    return null;
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:22,代碼來源:ImpexPsiUtils.java

示例6: actionPerformed

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {

    // 獲取編輯器中的文件
    Project project = e.getData(PlatformDataKeys.PROJECT);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);

    // 獲取當前類
    PsiClass targetClass = getTargetClass(editor, file);
    // 獲取元素操作的工廠類
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);

    // 生成代碼
    new LayoutCreator(project, targetClass, factory, file).execute();
}
 
開發者ID:alidili,項目名稱:AndroidStudioPlugin,代碼行數:17,代碼來源:CreateDialogAction.java

示例7: invoke

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  final PsiElement element = PsiUtilBase.getElementAtCaret(editor);
  final PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
  if (psiClass == null) return;

  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
  String annotation = "";
  if (PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5)) {
    annotation = "@SuppressWarnings({\"MethodOverridesStaticMethodOfSuperclass\", \"UnusedDeclaration\"})";
  }
  final PsiMethod createUI = factory.createMethodFromText(annotation +
                                                          "\npublic static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c) {" +
                                                      "\n  return new " + psiClass.getName() + "();\n}", psiClass);
  final PsiMethod newMethod = (PsiMethod)psiClass.add(CodeStyleManager.getInstance(project).reformat(createUI));
  JavaCodeStyleManager.getInstance(project).shortenClassReferences(newMethod);
  final PsiReturnStatement returnStatement = PsiTreeUtil.findChildOfType(newMethod, PsiReturnStatement.class);
  if (returnStatement != null) {
    final int offset = returnStatement.getTextRange().getEndOffset();
    editor.getCaretModel().moveToOffset(offset - 2);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:GenerateCreateUIHandler.java

示例8: processText

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
@Override
public void processText(Project project,
                        Template template,
                        Document document,
                        RangeMarker templateRange,
                        Editor editor) {
  if (!template.isToReformat()) return;

  PsiDocumentManager.getInstance(project).commitDocument(document);
  PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (!(file instanceof PsiJavaFile)) return;

  CharSequence text = document.getImmutableCharSequence();
  int prevChar = CharArrayUtil.shiftBackward(text, templateRange.getStartOffset() - 1, " \t");
  int nextChar = CharArrayUtil.shiftForward(text, templateRange.getEndOffset(), " \t");
  if (prevChar > 0 && text.charAt(prevChar) == '{' && nextChar < text.length() && text.charAt(nextChar) == '}') {
    PsiCodeBlock codeBlock = PsiTreeUtil.findElementOfClassAtOffset(file, prevChar, PsiCodeBlock.class, false);
    if (codeBlock != null && codeBlock.getTextRange().getStartOffset() == prevChar) {
      PsiJavaToken rBrace = codeBlock.getRBrace();
      if (rBrace != null && rBrace.getTextRange().getStartOffset() == nextChar) {
        CodeEditUtil.markToReformat(rBrace.getNode(), true);
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:CodeBlockReformattingProcessor.java

示例9: actionPerformedImpl

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
public void actionPerformedImpl(@NotNull final Project project, final Editor editor) {
  if (editor == null) return;
  //final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (psiFile == null) return;
  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final CodeInsightActionHandler handler = getHandler();
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing()) return;
          handler.invoke(project, editor, psiFile);
        }
      };
      if (handler.startInWriteAction()) {
        ApplicationManager.getApplication().runWriteAction(action);
      }
      else {
        action.run();
      }
    }
  }, getCommandName(), DocCommandGroupId.noneGroupId(editor.getDocument()));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:CodeInsightAction.java

示例10: update

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
@Override
public void update(AnActionEvent e) {
  Presentation presentation = e.getPresentation();

  Project project = e.getProject();
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }

  final DataContext dataContext = e.getDataContext();
  Editor editor = getEditor(dataContext, project);
  if (editor == null) {
    presentation.setEnabled(false);
    return;
  }

  final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (file == null) {
    presentation.setEnabled(false);
    return;
  }

  update(presentation, project, editor, file, dataContext, e.getPlace());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:CodeInsightAction.java

示例11: update

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
@Override
public void update(AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  e.getPresentation().setEnabled(false);
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) return;

  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (editor == null) return;

  final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (psiFile == null) return;

  if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing()) return;
  e.getPresentation().setEnabled(true);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:BaseCodeCompletionAction.java

示例12: addCompletionChar

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
private static void addCompletionChar(Project project,
                                      CompletionAssertions.WatchingInsertionContext context,
                                      LookupElement item,
                                      Editor editor, CompletionProgressIndicator indicator, char completionChar) {
  int tailOffset = context.getTailOffset();
  if (tailOffset < 0) {
    LOG.info("tailOffset<0 after inserting " + item + " of " + item.getClass() + "; invalidated at: " + context.invalidateTrace + "\n--------");
  }
  else {
    editor.getCaretModel().moveToOffset(tailOffset);
  }
  if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
    final Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    if (language != null) {
      for (SmartEnterProcessor processor : SmartEnterProcessors.INSTANCE.forKey(language)) {
        if (processor.processAfterCompletion(editor, indicator.getParameters().getOriginalFile())) break;
      }
    }
  }
  else if (!editor.getCaretModel().supportsMultipleCarets()) { // this will be done outside of runForEach caret context
    DataContext dataContext = DataManager.getInstance().getDataContext(editor.getContentComponent());
    EditorActionManager.getInstance().getTypedAction().getHandler().execute(editor, completionChar, dataContext);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:CodeCompletionHandlerBase.java

示例13: repaintTrafficIcon

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
private void repaintTrafficIcon(@NotNull final PsiFile file, final Editor editor, double progress) {
  if (ApplicationManager.getApplication().isCommandLine()) return;

  if (repaintIconAlarm.isEmpty() || progress >= 1) {
    repaintIconAlarm.addRequest(new Runnable() {
      @Override
      public void run() {
        Project myProject = file.getProject();
        if (myProject.isDisposed()) return;
        Editor myeditor = editor;
        if (myeditor == null) {
          myeditor = PsiUtilBase.findEditor(file);
        }
        if (myeditor == null || myeditor.isDisposed()) return;
        EditorMarkupModelImpl markup = (EditorMarkupModelImpl)myeditor.getMarkupModel();
        markup.repaintTrafficLightIcon();
        DaemonListeners.repaintErrorStripeRenderer(myeditor, myProject);
      }
    }, 50, null);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:DefaultHighlightInfoProcessor.java

示例14: setHighlightingSettingForRoot

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
public void setHighlightingSettingForRoot(@NotNull PsiElement root, @NotNull FileHighlightingSetting setting) {
  final PsiFile containingFile = root.getContainingFile();
  final VirtualFile virtualFile = containingFile.getVirtualFile();
  if (virtualFile == null) return;
  FileHighlightingSetting[] defaults = myHighlightSettings.get(virtualFile);
  int rootIndex = PsiUtilBase.getRootIndex(root);
  if (defaults != null && rootIndex >= defaults.length) defaults = null;
  if (defaults == null) defaults = getDefaults(containingFile);
  defaults[rootIndex] = setting;
  boolean toRemove = true;
  for (FileHighlightingSetting aDefault : defaults) {
    if (aDefault != FileHighlightingSetting.NONE) toRemove = false;
  }
  if (toRemove) {
    myHighlightSettings.remove(virtualFile);
  }
  else {
    myHighlightSettings.put(virtualFile, defaults);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:HighlightingSettingsPerFile.java

示例15: iterateOverCarets

import com.intellij.psi.util.PsiUtilBase; //導入依賴的package包/類
private static void iterateOverCarets(@NotNull final Project project,
                               @NotNull final Editor hostEditor,
                               @NotNull final MultiCaretCodeInsightActionHandler handler) {
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final PsiFile psiFile = documentManager.getCachedPsiFile(hostEditor.getDocument());
  documentManager.commitAllDocuments();

  hostEditor.getCaretModel().runForEachCaret(new CaretAction() {
    @Override
    public void perform(Caret caret) {
      Editor editor = hostEditor;
      if (psiFile != null) {
        Caret injectedCaret = InjectedLanguageUtil.getCaretForInjectedLanguageNoCommit(caret, psiFile);
        if (injectedCaret != null) {
          caret = injectedCaret;
          editor = caret.getEditor();
        }
      }
      final PsiFile file = PsiUtilBase.getPsiFileInEditor(caret, project);
      if (file != null) {
        handler.invoke(project, editor, caret, file);
      }
    }
  });
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:MultiCaretCodeInsightAction.java


注:本文中的com.intellij.psi.util.PsiUtilBase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。