当前位置: 首页>>代码示例>>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;未经允许,请勿转载。