本文整理匯總了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);
}
示例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);
}
}
}
示例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);
}
}
示例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());
}
示例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);
}
示例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));
}
}
示例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());
}
}
}
示例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;");
}
示例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;
}
示例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;
}
示例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);
}
示例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");
}
示例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();
}
示例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);
}