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


Java CodeStyleManager類代碼示例

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


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

示例1: fromTemplate

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
/**
 * @param templateFile        Name of the generated file
 * @param destinationPath     Relative path to the target file system entry
 * @param extensionDefinition Extension definition containing all relevant metadata
 * @param context             Template Context variables
 * @param project             Project in context
 */
public static PsiElement fromTemplate(@NotNull String templateFile, @NotNull String destinationPath, @NotNull String destinationFileName, @NotNull TYPO3ExtensionDefinition extensionDefinition, @NotNull Map<String, String> context, Project project) {
    String template = readTemplateToString(templateFile, context);

    VirtualFile targetDirectory = getOrCreateDestinationPath(extensionDefinition.getRootDirectory(), destinationPath);

    LanguageFileType fileType = FileTypes.PLAIN_TEXT;
    if (templateFile.endsWith(".php")) {
        fileType = PhpFileType.INSTANCE;
    }

    PsiFile fileFromText = PsiFileFactory.getInstance(project).createFileFromText(destinationFileName, fileType, template);
    CodeStyleManager.getInstance(project).reformat(fileFromText);
    return PsiDirectoryFactory
            .getInstance(project)
            .createDirectory(targetDirectory)
            .add(fileFromText);
}
 
開發者ID:cedricziel,項目名稱:idea-php-typo3-plugin,代碼行數:25,代碼來源:ExtensionFileGenerationUtil.java

示例2: execute

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
  myOriginalHandler.execute(editor, charTyped, dataContext);
  if (isMatchForClosingTag(editor, charTyped)) {
    int offset = editor.getCaretModel().getOffset();
    PsiFile file = dataContext.getData(LangDataKeys.PSI_FILE);
    if (file == null) {
      return;
    }
    PsiElement el = file.findElementAt(offset - 1);
    TagBlockElement block = (TagBlockElement) PsiTreeUtil
        .findFirstParent(el,
            parent -> parent instanceof TagBlockElement && !(parent instanceof SoyChoiceClause));
    if (block == null) {
      return;
    }
    String closingTag = block.getOpeningTag().generateClosingTag();
    insertClosingTag(editor, offset, closingTag);
    if (editor.getProject() != null) {
      PsiDocumentManager.getInstance(editor.getProject()).commitDocument(editor.getDocument());
      CodeStyleManager.getInstance(editor.getProject()).reformat(block);
    }
  }
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:24,代碼來源:ClosingTagHandler.java

示例3: run

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
@Override
protected void run(@NotNull Result<PsiFile> result) throws Throwable {
    final PsiPackage packageElement = directoryService.getPackage(directory);
    if (packageElement == null) {
        throw new InvalidDirectoryException("Target directory does not provide a package");
    }

    final String fileName = Extensions.append(name, StdFileTypes.JAVA);
    final PsiFile found = directory.findFile(fileName);
    if (found != null) {
        throw new ClassAlreadyExistsException("Class '" + name + "'already exists in " + packageElement.getName());
    }

    final String packageName = packageElement.getQualifiedName();
    final String className = Extensions.remove(this.name, StdFileTypes.JAVA);
    try {
        final String java = converter.convert(packageName, className, json);
        final PsiFile classFile = fileFactory.createFileFromText(fileName, JavaFileType.INSTANCE, java);
        CodeStyleManager.getInstance(classFile.getProject()).reformat(classFile);
        JavaCodeStyleManager.getInstance(classFile.getProject()).optimizeImports(classFile);
        final PsiFile created = (PsiFile) directory.add(classFile);
        result.setResult(created);
    } catch (IOException e) {
        throw new ClassCreationException("Failed to create new class from JSON", e);
    }
}
 
開發者ID:t28hub,項目名稱:json2java4idea,代碼行數:27,代碼來源:NewClassCommandAction.java

示例4: addAnnotation

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
public void addAnnotation(Project project) {
    for (FieldEntity entity : getFieldList()) {
        entity.addAnnotation(project);
    }

    editTableAnnotation(project, tablePsiAnnotation, getSelectedEntities().size() == 0);

    PsiJavaFile javaFile = (PsiJavaFile) psiClass.getContainingFile();
    Utils.saveDocument(javaFile);

    Utils.addImport(project, javaFile, null, AormConstants.tableQName, AormConstants.columnQName);
    Utils.optimizeImport(project, psiClass);

    CodeStyleManager.getInstance(project).reformat(psiClass);
    Utils.saveDocument(psiClass.getContainingFile());
}
 
開發者ID:Jamling,項目名稱:Android-ORM-ASPlugin,代碼行數:17,代碼來源:ClassEntity.java

示例5: run

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
@Override
public void run() {
    // deleting old fields
    Stream.of(sourceJavaPsiClass.getAllFields())
            .peek(psiField -> System.out.println("going to delete field: " + psiField.getText()))
            .forEach(psiField -> psiField.delete());

    // deleting orphanage COMMAs
    Stream.of(sourceJavaPsiClass.getChildren())
            .filter(psiElement -> psiElement instanceof PsiJavaToken)
            .map(psiElement -> (PsiJavaToken) psiElement)
            .filter(psiJavaToken -> "COMMA".equals(psiJavaToken.getTokenType().toString()))
            .peek(psiJavaToken -> System.out.println("going to delete token:" + psiJavaToken))
            .forEach(psiElement -> psiElement.delete());

    // start of additions
    new ValueClass(extractedVariables, sourceClass).getGeneratedPsiElements(project).forEach(
            psiElement -> sourceJavaPsiClass.add(psiElement)
    );
    CodeStyleManager.getInstance(project).reformat(rootPsiFile);
    JavaCodeStyleManager.getInstance(project).shortenClassReferences(rootPsiFile);
}
 
開發者ID:Ingwersaft,項目名稱:ValueClassGenerator,代碼行數:23,代碼來源:GeneratedValueWriter.java

示例6: executeTestConfiguration

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
private void executeTestConfiguration(int binarySettings, String relativeTargetPath, boolean checkResults) {
    if (relativeTargetPath == null || relativeTargetPath.isEmpty()) {
        relativeTargetPath = ".";
    }

    myFixture.configureByFiles(relativeTargetPath + "/TestData.csv");

    initCsvCodeStyleSettings(binarySettings);

    new WriteCommandAction.Simple(getProject()) {
        @Override
        protected void run() throws Throwable {
            CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
                    ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
        }
    }.execute();
    if (checkResults) {
        myFixture.checkResultByFile(relativeTargetPath + String.format("/TestResult%08d.csv", binarySettings));
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:21,代碼來源:CsvFormatterTest.java

示例7: _testResultGenerator

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
/**
 * This function should be executed (remove the underscore) if the current results are correct (manual testing).
 *
 * @throws Exception
 */
public void _testResultGenerator() throws Exception {
    for (int binarySettings = 0; binarySettings < 128; ++binarySettings) {
        tearDown();
        setUp();

        myFixture.configureByFiles("/generated/TestData.csv");

        initCsvCodeStyleSettings(binarySettings);

        new WriteCommandAction.Simple(getProject()) {
            @Override
            protected void run() throws Throwable {
                CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
                        ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
            }
        }.execute();

        try (PrintWriter writer = new PrintWriter(getTestDataPath() + String.format("/generated/TestResult%08d.csv", binarySettings))
        ) {
            writer.print(myFixture.getFile().getText());
        }
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:29,代碼來源:CsvFormatterTest.java

示例8: processIntention

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
@Override
public void processIntention(@NotNull PsiElement element) {
  final PsiReturnStatement returnStatement = (PsiReturnStatement)element;
  final PsiExpression returnValue = returnStatement.getReturnValue();
  if (returnValue == null || ErrorUtil.containsDeepError(returnValue)) {
    return;
  }
  final String newStatementText = buildIf(returnValue, true, new StringBuilder()).toString();
  final Project project = returnStatement.getProject();
  final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
  final PsiBlockStatement blockStatement = (PsiBlockStatement)elementFactory.createStatementFromText("{" + newStatementText + "}", returnStatement);
  final PsiElement parent = returnStatement.getParent();
  for (PsiStatement st : blockStatement.getCodeBlock().getStatements()) {
    CodeStyleManager.getInstance(project).reformat(parent.addBefore(st, returnStatement));
  }
  PsiReplacementUtil.replaceStatement(returnStatement, "return false;");
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:ConvertToNestedIfIntention.java

示例9: addAfter

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
@Override
public PsiElement addAfter(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
    List<LuaExpression> exprs = getLuaExpressions();

    if (exprs.size() == 0) {
        add(element);
    } else {
        element = super.addAfter(element, anchor);
        final ASTNode astNode = getNode();
        if (anchor != null) {
            astNode.addLeaf(COMMA, ",", element.getNode());
        } else {
            astNode.addLeaf(COMMA, ",", element.getNextSibling().getNode());
        }
        CodeStyleManager.getInstance(getManager().getProject()).reformat(this);
    }

    return element;
}
 
開發者ID:internetisalie,項目名稱:lua-for-idea,代碼行數:20,代碼來源:LuaExpressionListImpl.java

示例10: addBefore

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
@Override
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
    List<LuaExpression> exprs = getLuaExpressions();

    if (exprs.size() == 0) {
        add(element);
    } else {
        element = super.addBefore(element, anchor);
        final ASTNode astNode = getNode();
        if (anchor != null) {
            astNode.addLeaf(COMMA, ",", anchor.getNode());
        } else {
            astNode.addLeaf(COMMA, ",", element.getNode());
        }
        CodeStyleManager.getInstance(getManager().getProject()).reformat(this);
    }

    return element;
}
 
開發者ID:internetisalie,項目名稱:lua-for-idea,代碼行數:20,代碼來源:LuaExpressionListImpl.java

示例11: qualifyReference

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
public static GrReferenceExpression qualifyReference(GrReferenceExpression referenceExpression,
                                                      final PsiMember member,
                                                      @Nullable final PsiClass qualifyingClass) throws IncorrectOperationException {
  PsiManager manager = referenceExpression.getManager();
  GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(manager.getProject());

  GrReferenceExpression expressionFromText;
  if (qualifyingClass == null) {
    final PsiClass parentClass = PsiTreeUtil.getParentOfType(referenceExpression, PsiClass.class);
    final PsiClass containingClass = member.getContainingClass();
    if (parentClass != null && !InheritanceUtil.isInheritorOrSelf(parentClass, containingClass, true)) {
      expressionFromText = (GrReferenceExpression)factory.createExpressionFromText(containingClass.getQualifiedName()+ ".this." + member.getName());
    }
    else {
      expressionFromText = (GrReferenceExpression)factory.createExpressionFromText("this." + member.getName());
    }
  }
  else {
    expressionFromText = (GrReferenceExpression)factory.createExpressionFromText(qualifyingClass.getQualifiedName()+ '.' + member.getName());
  }
  CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject());
  expressionFromText = (GrReferenceExpression)codeStyleManager.reformat(expressionFromText);
  return (GrReferenceExpression)referenceExpression.replace(expressionFromText);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:FieldConflictsResolver.java

示例12: surroundExpression

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
@Override
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
    PsiManager manager = expr.getManager();
    PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

    @NonNls String text = "if(a){\nst;\n}elseif(){else{\n}";
    PsiIfStatement ifStatement = (PsiIfStatement)factory.createStatementFromText(text, null);
    ifStatement = (PsiIfStatement)codeStyleManager.reformat(ifStatement);

    ifStatement.getCondition().replace(expr);

    PsiExpressionStatement statement = (PsiExpressionStatement)expr.getParent();
    ifStatement = (PsiIfStatement)statement.replace(ifStatement);

    PsiCodeBlock block = ((PsiBlockStatement)ifStatement.getThenBranch()).getCodeBlock();

    PsiStatement afterStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(block.getStatements()[0]);

    TextRange range = afterStatement.getTextRange();
    editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
    return new TextRange(range.getStartOffset(), range.getStartOffset());
}
 
開發者ID:cesards,項目名稱:HakunaMatataIntelliJPlugin,代碼行數:24,代碼來源:JavaWithIfElseIfExpressionSurrounder.java

示例13: testFormatterTurnedOff

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
public void testFormatterTurnedOff() {
    myFixture.configureByFiles("FormatterTestData.dot");

    // everything is turned off test
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_ASSIGNMENT_OPERATORS = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_SEMICOLON = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_EQUALITY_OPERATORS = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_CLASS_LBRACE = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_METHOD_LBRACE = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_BRACKETS= false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_CLASS_LBRACE = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_METHOD_LBRACE = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_BRACKETS= false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_SEMICOLON = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_SEMICOLON = false;
    CodeStyleSettingsManager.getSettings(getProject()).SPACE_AFTER_COLON = false;
    new WriteCommandAction.Simple(getProject()) {
        @Override
        protected void run() throws Throwable {
            CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
                    ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
        }
    }.execute();
    myFixture.checkResultByFile("FormatterTestDataTurnedOff.dot");
}
 
開發者ID:bzixilu,項目名稱:dotplugin,代碼行數:26,代碼來源:DotFormatterTest.java

示例14: onProcessItemViewBinder

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
private void onProcessItemViewBinder(final PsiDirectory dir, final String typeName, final PsiClass itemClass) {
    PsiFile file = itemClass.getContainingFile();
    final PsiDocumentManager manager = PsiDocumentManager.getInstance(itemClass.getProject());
    final Document document = manager.getDocument(file);
    if (document == null) {
        return;
    }

    new WriteCommandAction.Simple(itemClass.getProject()) {
        @Override
        protected void run() throws Throwable {
            manager.doPostponedOperationsAndUnblockDocument(document);
            document.setText(document.getText()
                .replace("MTI_CLASS", typeName)
                .replace("MTI_LOWER_NAME", CaseFormat.UPPER_CAMEL.to(LOWER_UNDERSCORE, typeName))
                .replace("MTI_NAME", CaseFormat.UPPER_CAMEL.to(LOWER_CAMEL, typeName)));
            CodeStyleManager.getInstance(itemClass.getProject()).reformat(itemClass);
        }
    }.execute();
}
 
開發者ID:drakeet,項目名稱:MultiTypeTemplates,代碼行數:21,代碼來源:CreateItemFilesAction.java

示例15: doFix

import com.intellij.psi.codeStyle.CodeStyleManager; //導入依賴的package包/類
@Override
public void doFix(Project project, ProblemDescriptor descriptor)
  throws IncorrectOperationException {
  final PsiElement methodName = descriptor.getPsiElement();
  final PsiMethod method = (PsiMethod)methodName.getParent();
  if (method == null) {
    return;
  }
  final PsiCodeBlock body = method.getBody();
  if (body == null) {
    return;
  }
  final PsiElementFactory factory =
    JavaPsiFacade.getElementFactory(project);
  final PsiStatement newStatement =
    factory.createStatementFromText("super.tearDown();", null);
  final CodeStyleManager styleManager =
    CodeStyleManager.getInstance(project);
  final PsiJavaToken brace = body.getRBrace();
  body.addBefore(newStatement, brace);
  styleManager.reformat(body);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:TeardownCallsSuperTeardownInspection.java


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