From f416f02ce28db758e7aa8266f86b65ef13851b5d Mon Sep 17 00:00:00 2001 From: Breandan Considine Date: Mon, 21 Mar 2016 16:08:47 -0400 Subject: [PATCH] Tidy up code samples and wrap at 80 chars #IJSDK-24 --- .../source/META-INF/plugin.xml | 6 +- .../ComparingReferencesInspection.java | 66 ++-- .../ComparingReferencesProvider.java | 2 +- .../testSource/testPlugin/TestThisPlugin.java | 73 ++-- .../META-INF/plugin.xml | 44 +-- .../ConditionalOperatorConvertor.java | 36 +- .../description.html | 2 +- .../testData/before.template.after.java | 14 +- .../testData/before.template.java | 4 +- .../testSource/testPlugin/YourTest.java | 66 ++-- .../resources/META-INF/plugin.xml | 18 +- .../editor/basics/EditorAreaIllustration.java | 39 ++- .../basics/EditorHandlerIllustration.java | 32 +- .../editor/basics/EditorIllustration.java | 69 ++-- .../editor/basics/MyTypedHandler.java | 24 +- .../resources/META-INF/plugin.xml | 50 +-- .../intellij/tutorials/facet/DemoFacet.java | 12 +- .../facet/DemoFacetConfiguration.java | 103 +++--- .../tutorials/facet/DemoFacetType.java | 46 +-- .../tutorials/framework/DemoFramework.java | 89 ++--- code_samples/gradle_plugin_demo/build.gradle | 2 +- .../src/main/java/HelloAction.java | 14 +- .../src/main/resources/META-INF/plugin.xml | 4 +- .../inspection/resources/META-INF/plugin.xml | 38 +-- .../inspection/DemoCodeInspection.java | 22 +- .../DemoInspectionToolProvider.java | 6 +- .../inspection/DemoInspectionVisitor.java | 16 +- .../kotlin_demo/resources/META-INF/plugin.xml | 4 +- .../resources/liveTemplates/Markdown.xml | 18 +- .../live_templates/src/MarkdownContext.java | 17 +- .../src/MarkdownTemplateProvider.java | 19 +- .../resources/META-INF/plugin.xml | 12 +- .../src/MyPackage/MaxProject.java | 67 ++-- .../src/MyPackage/MyCounter.java | 27 +- .../module/resources/META-INF/plugin.xml | 50 +-- .../tutorials/module/DemoModuleBuilder.java | 24 +- .../tutorials/module/DemoModuleType.java | 72 ++-- .../module/DemoModuleWizardStep.java | 16 +- .../resources/META-INF/plugin.xml | 243 +++++++------- .../sample/DummyApplicationComponent.java | 2 +- .../sample/DummyApplicationComponentImpl.java | 22 +- .../sample/DummyModuleComponent.java | 2 +- .../sample/DummyModuleComponentImpl.java | 40 +-- .../sample/DummyProjectComponent.java | 2 +- .../sample/DummyProjectComponentImpl.java | 34 +- .../sample/actions/DummyActionGroup.java | 10 +- .../sample/actions/GroupedAction.java | 6 +- .../actions/GroupedToDefaultAction.java | 6 +- .../sample/actions/SimpleAction.java | 22 +- .../resources/META-INF/plugin.xml | 92 +++--- .../project/model/LibrariesAction.java | 79 ++--- .../project/model/ModificationAction.java | 48 +-- .../model/ProjectFileIndexSampleAction.java | 62 ++-- .../project/model/ProjectSdkAction.java | 32 +- .../project/model/ShowSourceRootsActions.java | 35 +- .../resources/META-INF/plugin.xml | 42 +-- .../view/pane/ImagesProjectNode.java | 246 +++++++------- .../view/pane/ImagesProjectViewPane.java | 144 ++++---- .../resources/META-INF/plugin.xml | 4 +- .../project/wizard/DemoModuleWizardStep.java | 35 +- .../resources/META-INF/plugin.xml | 90 ++--- .../tutorials/actions/BaseActionGroup.java | 26 +- .../actions/CustomDefaultActionGroup.java | 14 +- .../actions/CustomGroupedAction.java | 8 +- .../tutorials/actions/GroupedAction.java | 16 +- .../tutorials/actions/SimpleAction.java | 28 +- .../resources/META-INF/plugin.xml | 40 +-- .../DemoConfigurationFactory.java | 24 +- .../configuration/DemoRunConfiguration.java | 33 +- .../DemoRunConfigurationType.java | 42 +-- .../run/configuration/DemoSettingsEditor.java | 34 +- .../com/simpleplugin/parser/SimpleParser.java | 15 +- .../com/simpleplugin/psi/SimpleProperty.java | 4 +- .../gen/com/simpleplugin/psi/SimpleTypes.java | 8 +- .../com/simpleplugin/psi/SimpleVisitor.java | 4 +- .../psi/impl/SimplePropertyImpl.java | 12 +- .../resources/META-INF/plugin.xml | 38 ++- .../simpleplugin/CreatePropertyQuickFix.java | 119 +++---- .../src/com/simpleplugin/SimpleAnnotator.java | 42 +-- .../src/com/simpleplugin/SimpleBlock.java | 72 ++-- .../SimpleChooseByNameContributor.java | 36 +- .../simpleplugin/SimpleCodeStyleSettings.java | 6 +- .../SimpleCodeStyleSettingsProvider.java | 56 ++-- .../simpleplugin/SimpleColorSettingsPage.java | 102 +++--- .../src/com/simpleplugin/SimpleCommenter.java | 50 +-- .../SimpleCompletionContributor.java | 24 +- .../src/com/simpleplugin/SimpleFileType.java | 48 +-- .../simpleplugin/SimpleFileTypeFactory.java | 10 +- .../com/simpleplugin/SimpleFilterLexer.java | 18 +- .../SimpleFindUsagesProvider.java | 80 ++--- .../simpleplugin/SimpleFoldingBuilder.java | 75 +++-- .../SimpleFormattingModelBuilder.java | 41 ++- .../src/com/simpleplugin/SimpleIcons.java | 2 +- .../src/com/simpleplugin/SimpleIdIndexer.java | 14 +- .../src/com/simpleplugin/SimpleLanguage.java | 8 +- ...mpleLanguageCodeStyleSettingsProvider.java | 62 ++-- .../src/com/simpleplugin/SimpleLexer.java | 312 ++++++++++-------- .../com/simpleplugin/SimpleLexerAdapter.java | 6 +- .../SimpleLineMarkerProvider.java | 33 +- .../simpleplugin/SimpleParserDefinition.java | 79 ++--- .../SimpleRefactoringSupportProvider.java | 8 +- .../src/com/simpleplugin/SimpleReference.java | 72 ++-- .../SimpleReferenceContributor.java | 36 +- .../SimpleStructureViewElement.java | 88 ++--- .../SimpleStructureViewFactory.java | 22 +- .../SimpleStructureViewModel.java | 32 +- .../simpleplugin/SimpleSyntaxHighlighter.java | 71 ++-- .../SimpleSyntaxHighlighterFactory.java | 10 +- .../com/simpleplugin/SimpleTodoIndexer.java | 8 +- .../src/com/simpleplugin/SimpleUtil.java | 66 ++-- .../psi/SimpleElementFactory.java | 34 +- .../simpleplugin/psi/SimpleElementType.java | 6 +- .../src/com/simpleplugin/psi/SimpleFile.java | 32 +- .../com/simpleplugin/psi/SimpleTokenType.java | 14 +- .../psi/impl/SimpleNamedElementImpl.java | 6 +- .../psi/impl/SimplePsiImplUtil.java | 109 +++--- .../testData/AnnotatorTestData.java | 10 +- .../testData/CompleteTestData.java | 6 +- .../testData/FindUsagesTestData.java | 6 +- .../testData/FoldingTestData.java | 42 ++- .../testData/ReferenceTestData.java | 6 +- .../testData/RenameTestData.java | 6 +- .../simpleplugin/SimpleCodeInsightTest.java | 116 +++---- .../com/simpleplugin/SimpleParsingTest.java | 36 +- .../tool_window/resources/META-INF/plugin.xml | 42 +-- .../src/myToolWindow/MyToolWindowFactory.java | 103 +++--- .../TextOnlyTreeStructureProvider.java | 38 ++- 127 files changed, 2659 insertions(+), 2528 deletions(-) diff --git a/code_samples/comparing_references_inspection/source/META-INF/plugin.xml b/code_samples/comparing_references_inspection/source/META-INF/plugin.xml index 36bf3d61f..f7cecc03a 100644 --- a/code_samples/comparing_references_inspection/source/META-INF/plugin.xml +++ b/code_samples/comparing_references_inspection/source/META-INF/plugin.xml @@ -3,9 +3,9 @@ Inspection for (probably) inappropriate use of equality relation operation. 1.0 JetBrains - + diff --git a/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesInspection.java b/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesInspection.java index 941fc702c..e952f2a11 100644 --- a/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesInspection.java +++ b/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesInspection.java @@ -3,7 +3,6 @@ package com.intellij.codeInspection; import com.intellij.codeInsight.daemon.GroupNames; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; import com.intellij.ui.DocumentAdapter; @@ -14,8 +13,6 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.DocumentEvent; import java.awt.*; -import java.util.ArrayList; -import java.util.Arrays; import java.util.StringTokenizer; /** @@ -26,13 +23,17 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool { private final LocalQuickFix myQuickFix = new MyQuickFix(); - @SuppressWarnings({"WeakerAccess"}) @NonNls public String CHECKED_CLASSES = "java.lang.String;java.util.Date"; - @NonNls private static final String DESCRIPTION_TEMPLATE = InspectionsBundle.message("inspection.comparing.references.problem.descriptor"); + @SuppressWarnings({"WeakerAccess"}) + @NonNls + public String CHECKED_CLASSES = "java.lang.String;java.util.Date"; + @NonNls + private static final String DESCRIPTION_TEMPLATE = + InspectionsBundle.message("inspection.comparing.references.problem.descriptor"); @NotNull public String getDisplayName() { - return "'==' or '!=' instead of 'equals()'"; + return "'==' or '!=' instead of 'equals()'"; } @NotNull @@ -57,32 +58,33 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool { return false; } - @NotNull - @Override - public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { - return new JavaElementVisitor() { + @NotNull + @Override + public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { + return new JavaElementVisitor() { - @Override - public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) { - } + @Override + public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) { + } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { - super.visitBinaryExpression(expression); + @Override + public void visitBinaryExpression(PsiBinaryExpression expression) { + super.visitBinaryExpression(expression); IElementType opSign = expression.getOperationTokenType(); - if (opSign == JavaTokenType.EQEQ || opSign == JavaTokenType.NE) { - PsiExpression lOperand = expression.getLOperand(); - PsiExpression rOperand = expression.getROperand(); - if (rOperand == null || isNullLiteral(lOperand) || isNullLiteral(rOperand)) return; + if (opSign == JavaTokenType.EQEQ || opSign == JavaTokenType.NE) { + PsiExpression lOperand = expression.getLOperand(); + PsiExpression rOperand = expression.getROperand(); + if (rOperand == null || isNullLiteral(lOperand) || isNullLiteral(rOperand)) return; - PsiType lType = lOperand.getType(); - PsiType rType = rOperand.getType(); + PsiType lType = lOperand.getType(); + PsiType rType = rOperand.getType(); - if (isCheckedType(lType) || isCheckedType(rType)) { - holder.registerProblem(expression, - DESCRIPTION_TEMPLATE, myQuickFix); - } + if (isCheckedType(lType) || isCheckedType(rType)) { + holder.registerProblem(expression, + DESCRIPTION_TEMPLATE, myQuickFix); } + } } }; } @@ -94,14 +96,14 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool { private static class MyQuickFix implements LocalQuickFix { @NotNull public String getName() { - // The test (see the TestThisPlugin class) uses this string to identify the quick fix action. + // The test (see the TestThisPlugin class) uses this string to identify the quick fix action. return InspectionsBundle.message("inspection.comparing.references.use.quickfix"); } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { - PsiBinaryExpression binaryExpression = (PsiBinaryExpression)descriptor.getPsiElement(); + PsiBinaryExpression binaryExpression = (PsiBinaryExpression) descriptor.getPsiElement(); IElementType opSign = binaryExpression.getOperationTokenType(); PsiExpression lExpr = binaryExpression.getLOperand(); PsiExpression rExpr = binaryExpression.getROperand(); @@ -109,20 +111,20 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool { return; PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory(); - PsiMethodCallExpression equalsCall = (PsiMethodCallExpression)factory.createExpressionFromText("a.equals(b)", null); + PsiMethodCallExpression equalsCall = + (PsiMethodCallExpression) factory.createExpressionFromText("a.equals(b)", null); equalsCall.getMethodExpression().getQualifierExpression().replace(lExpr); equalsCall.getArgumentList().getExpressions()[0].replace(rExpr); - PsiExpression result = (PsiExpression)binaryExpression.replace(equalsCall); + PsiExpression result = (PsiExpression) binaryExpression.replace(equalsCall); if (opSign == JavaTokenType.NE) { - PsiPrefixExpression negation = (PsiPrefixExpression)factory.createExpressionFromText("!a", null); + PsiPrefixExpression negation = (PsiPrefixExpression) factory.createExpressionFromText("!a", null); negation.getOperand().replace(result); result.replace(negation); } - } - catch (IncorrectOperationException e) { + } catch (IncorrectOperationException e) { LOG.error(e); } } diff --git a/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesProvider.java b/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesProvider.java index 37f091454..980777846 100644 --- a/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesProvider.java +++ b/code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesProvider.java @@ -5,6 +5,6 @@ package com.intellij.codeInspection; */ public class ComparingReferencesProvider implements InspectionToolProvider { public Class[] getInspectionClasses() { - return new Class[] { ComparingReferencesInspection.class}; + return new Class[]{ComparingReferencesInspection.class}; } } diff --git a/code_samples/comparing_references_inspection/testSource/testPlugin/TestThisPlugin.java b/code_samples/comparing_references_inspection/testSource/testPlugin/TestThisPlugin.java index bf3769c2a..42d7a5d48 100644 --- a/code_samples/comparing_references_inspection/testSource/testPlugin/TestThisPlugin.java +++ b/code_samples/comparing_references_inspection/testSource/testPlugin/TestThisPlugin.java @@ -17,51 +17,52 @@ import java.util.List; */ public class TestThisPlugin extends UsefulTestCase { - protected CodeInsightTestFixture myFixture; - // Specify path to your test data directory - // e.g. final String dataPath = "c:\\users\\john.doe\\idea\\community\\samples\\ComparingReferences/testData"; - final String dataPath = "c:\\users\\John.Doe\\idea\\community\\samples\\comparingReferences/testData"; + protected CodeInsightTestFixture myFixture; + // Specify path to your test data directory + // e.g. final String dataPath = "c:\\users\\john.doe\\idea\\community\\samples\\ComparingReferences/testData"; + final String dataPath = "c:\\users\\John.Doe\\idea\\community\\samples\\comparingReferences/testData"; - public void setUp() throws Exception { + public void setUp() throws Exception { - final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory(); - final TestFixtureBuilder testFixtureBuilder = fixtureFactory.createFixtureBuilder(getName()); - myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture()); - myFixture.setTestDataPath(dataPath); - final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class); + final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory(); + final TestFixtureBuilder testFixtureBuilder = + fixtureFactory.createFixtureBuilder(getName()); + myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture()); + myFixture.setTestDataPath(dataPath); + final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class); - builder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot(""); - builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15); - myFixture.setUp(); - } + builder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot(""); + builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15); + myFixture.setUp(); + } - public void tearDown() throws Exception { - myFixture.tearDown(); - myFixture = null; - } + public void tearDown() throws Exception { + myFixture.tearDown(); + myFixture = null; + } - protected void doTest(String testName, String hint) throws Throwable { - myFixture.configureByFile(testName + ".java"); - myFixture.enableInspections(ComparingReferencesInspection.class); - List highlightInfos = myFixture.doHighlighting(); - Assert.assertTrue(!highlightInfos.isEmpty()); + protected void doTest(String testName, String hint) throws Throwable { + myFixture.configureByFile(testName + ".java"); + myFixture.enableInspections(ComparingReferencesInspection.class); + List highlightInfos = myFixture.doHighlighting(); + Assert.assertTrue(!highlightInfos.isEmpty()); - final IntentionAction action = myFixture.findSingleIntention(hint); + final IntentionAction action = myFixture.findSingleIntention(hint); - Assert.assertNotNull(action); - myFixture.launchAction(action); - myFixture.checkResultByFile(testName + ".after.java"); - } + Assert.assertNotNull(action); + myFixture.launchAction(action); + myFixture.checkResultByFile(testName + ".after.java"); + } - // Test the "==" case - public void test() throws Throwable { - doTest("before", "Use equals()"); - } + // Test the "==" case + public void test() throws Throwable { + doTest("before", "Use equals()"); + } - // Test the "!=" case - public void test1() throws Throwable { - doTest("before1", "Use equals()"); - } + // Test the "!=" case + public void test1() throws Throwable { + doTest("before1", "Use equals()"); + } } diff --git a/code_samples/conditional_operator_intention/META-INF/plugin.xml b/code_samples/conditional_operator_intention/META-INF/plugin.xml index 17c55b92a..b46464358 100644 --- a/code_samples/conditional_operator_intention/META-INF/plugin.xml +++ b/code_samples/conditional_operator_intention/META-INF/plugin.xml @@ -1,27 +1,27 @@ - Conditional Operator Converter - ConditionalOperatorConverter - Intention action that suggests to convert a conditional operator into - 'if' block. - - 1.3 - JetBrains - + Conditional Operator Converter + ConditionalOperatorConverter + Intention action that suggests to convert a conditional operator into + 'if' block. + + 1.3 + JetBrains + - - - com.intellij.codeInsight.intention.ConditionalOperatorConvertor - Conditional Operator - ConditionalOperatorConvertor + + + com.intellij.codeInsight.intention.ConditionalOperatorConvertor + Conditional Operator + ConditionalOperatorConvertor - - + + - - - com.intellij.codeInsight.intention.ConditionalOperatorConvertor - - + + + com.intellij.codeInsight.intention.ConditionalOperatorConvertor + + diff --git a/code_samples/conditional_operator_intention/source/com/intellij/codeInsight/intention/ConditionalOperatorConvertor.java b/code_samples/conditional_operator_intention/source/com/intellij/codeInsight/intention/ConditionalOperatorConvertor.java index ffee0ad54..2d8532164 100644 --- a/code_samples/conditional_operator_intention/source/com/intellij/codeInsight/intention/ConditionalOperatorConvertor.java +++ b/code_samples/conditional_operator_intention/source/com/intellij/codeInsight/intention/ConditionalOperatorConvertor.java @@ -13,7 +13,8 @@ import org.jetbrains.annotations.Nullable; /** * @author dsl */ -@NonNls public class ConditionalOperatorConvertor extends PsiElementBaseIntentionAction implements IntentionAction { +@NonNls +public class ConditionalOperatorConvertor extends PsiElementBaseIntentionAction implements IntentionAction { @NotNull public String getText() { @@ -30,10 +31,10 @@ import org.jetbrains.annotations.Nullable; if (!element.isWritable()) return false; if (element instanceof PsiJavaToken) { - final PsiJavaToken token = (PsiJavaToken)element; + final PsiJavaToken token = (PsiJavaToken) element; if (token.getTokenType() != JavaTokenType.QUEST) return false; if (token.getParent() instanceof PsiConditionalExpression) { - final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)token.getParent(); + final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression) token.getParent(); if (conditionalExpression.getThenExpression() == null || conditionalExpression.getElseExpression() == null) { return false; @@ -63,12 +64,13 @@ import org.jetbrains.annotations.Nullable; // Maintain declrations if (originalStatement instanceof PsiDeclarationStatement) { - final PsiDeclarationStatement declaration = (PsiDeclarationStatement)originalStatement; + final PsiDeclarationStatement declaration = (PsiDeclarationStatement) originalStatement; final PsiElement[] declaredElements = declaration.getDeclaredElements(); PsiLocalVariable variable = null; for (PsiElement declaredElement : declaredElements) { - if (declaredElement instanceof PsiLocalVariable && PsiTreeUtil.isAncestor(declaredElement, conditionalExpression, true)) { - variable = (PsiLocalVariable)declaredElement; + if (declaredElement instanceof PsiLocalVariable && + PsiTreeUtil.isAncestor(declaredElement, conditionalExpression, true)) { + variable = (PsiLocalVariable) declaredElement; break; } } @@ -77,31 +79,31 @@ import org.jetbrains.annotations.Nullable; final Object marker = new Object(); PsiTreeUtil.mark(conditionalExpression, marker); PsiExpressionStatement statement = - (PsiExpressionStatement)factory.createStatementFromText(variable.getName() + " = 0;", null); - statement = (PsiExpressionStatement)CodeStyleManager.getInstance(project).reformat(statement); - ((PsiAssignmentExpression)statement.getExpression()).getRExpression().replace(variable.getInitializer()); + (PsiExpressionStatement) factory.createStatementFromText(variable.getName() + " = 0;", null); + statement = (PsiExpressionStatement) CodeStyleManager.getInstance(project).reformat(statement); + ((PsiAssignmentExpression) statement.getExpression()).getRExpression().replace(variable.getInitializer()); variable.getInitializer().delete(); final PsiElement variableParent = variable.getParent(); originalStatement = variableParent.getParent().addAfter(statement, variableParent); - conditionalExpression = (PsiConditionalExpression)PsiTreeUtil.releaseMark(originalStatement, marker); + conditionalExpression = (PsiConditionalExpression) PsiTreeUtil.releaseMark(originalStatement, marker); } // create then and else branches final PsiElement[] originalElements = new PsiElement[]{originalStatement, conditionalExpression}; - final PsiExpression condition = (PsiExpression)conditionalExpression.getCondition().copy(); + final PsiExpression condition = (PsiExpression) conditionalExpression.getCondition().copy(); final PsiElement[] thenElements = PsiTreeUtil.copyElements(originalElements); final PsiElement[] elseElements = PsiTreeUtil.copyElements(originalElements); thenElements[1].replace(conditionalExpression.getThenExpression()); elseElements[1].replace(conditionalExpression.getElseExpression()); - PsiIfStatement statement = (PsiIfStatement)factory.createStatementFromText("if (true) { a = b } else { c = d }", - null); - statement = (PsiIfStatement)CodeStyleManager.getInstance(project).reformat(statement); + PsiIfStatement statement = (PsiIfStatement) factory.createStatementFromText("if (true) { a = b } else { c = d }", + null); + statement = (PsiIfStatement) CodeStyleManager.getInstance(project).reformat(statement); statement.getCondition().replace(condition); - statement = (PsiIfStatement)originalStatement.replace(statement); + statement = (PsiIfStatement) originalStatement.replace(statement); - ((PsiBlockStatement)statement.getThenBranch()).getCodeBlock().getStatements()[0].replace(thenElements[0]); - ((PsiBlockStatement)statement.getElseBranch()).getCodeBlock().getStatements()[0].replace(elseElements[0]); + ((PsiBlockStatement) statement.getThenBranch()).getCodeBlock().getStatements()[0].replace(thenElements[0]); + ((PsiBlockStatement) statement.getElseBranch()).getCodeBlock().getStatements()[0].replace(elseElements[0]); } public boolean startInWriteAction() { diff --git a/code_samples/conditional_operator_intention/source/intentionDescriptions/ConditionalOperatorConvertor/description.html b/code_samples/conditional_operator_intention/source/intentionDescriptions/ConditionalOperatorConvertor/description.html index 3d6efdd8d..6ae92607a 100644 --- a/code_samples/conditional_operator_intention/source/intentionDescriptions/ConditionalOperatorConvertor/description.html +++ b/code_samples/conditional_operator_intention/source/intentionDescriptions/ConditionalOperatorConvertor/description.html @@ -1,5 +1,5 @@ - This intention converts a ternary operator to a corresponding if statement.
+This intention converts a ternary operator to a corresponding if statement.
\ No newline at end of file diff --git a/code_samples/conditional_operator_intention/testData/before.template.after.java b/code_samples/conditional_operator_intention/testData/before.template.after.java index 6682628f7..227866498 100644 --- a/code_samples/conditional_operator_intention/testData/before.template.after.java +++ b/code_samples/conditional_operator_intention/testData/before.template.after.java @@ -1,11 +1,11 @@ public class X { void f(boolean isMale) { String title; - if (isMale) { - title = "Mr."; - } else { - title = "Ms."; - } - System.out.println("title = " + title); - } + if (isMale) { + title = "Mr."; + } else { + title = "Ms."; + } + System.out.println("title = " + title); + } } \ No newline at end of file diff --git a/code_samples/conditional_operator_intention/testData/before.template.java b/code_samples/conditional_operator_intention/testData/before.template.java index 74107ea2d..9d5f5bc71 100644 --- a/code_samples/conditional_operator_intention/testData/before.template.java +++ b/code_samples/conditional_operator_intention/testData/before.template.java @@ -1,6 +1,6 @@ public class X { void f(boolean isMale) { - String title = isMale ? "Mr." : "Ms."; + String title = isMale < caret > ? "Mr." : "Ms."; System.out.println("title = " + title); - } + } } \ No newline at end of file diff --git a/code_samples/conditional_operator_intention/testSource/testPlugin/YourTest.java b/code_samples/conditional_operator_intention/testSource/testPlugin/YourTest.java index 1b2114b71..4e6a85d55 100644 --- a/code_samples/conditional_operator_intention/testSource/testPlugin/YourTest.java +++ b/code_samples/conditional_operator_intention/testSource/testPlugin/YourTest.java @@ -1,7 +1,6 @@ package testPlugin; import com.intellij.codeInsight.intention.IntentionAction; - import com.intellij.testFramework.builders.JavaModuleFixtureBuilder; import com.intellij.testFramework.fixtures.*; import junit.framework.Assert; @@ -18,45 +17,46 @@ import org.junit.Test; */ public class YourTest { - protected CodeInsightTestFixture myFixture; - // Specify path to your test data - // e.g. final String dataPath = "c:\\users\\john.doe\\idea\\community\\samples\\conditionalOperatorConvertor/testData"; - final String dataPath = "c:\\users\\John.Doe\\idea\\community\\samples\\conditionalOperatorConvertor/testData"; + protected CodeInsightTestFixture myFixture; + // Specify path to your test data + // e.g. final String dataPath = "c:\\users\\john + // .doe\\idea\\community\\samples\\conditionalOperatorConvertor/testData"; + final String dataPath = "c:\\users\\John.Doe\\idea\\community\\samples\\conditionalOperatorConvertor/testData"; - @Before + @Before - public void setUp() throws Exception { + public void setUp() throws Exception { - final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory(); - final TestFixtureBuilder testFixtureBuilder = fixtureFactory.createFixtureBuilder(); - myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture()); - myFixture.setTestDataPath(dataPath); - final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class); + final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory(); + final TestFixtureBuilder testFixtureBuilder = fixtureFactory.createFixtureBuilder(); + myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture()); + myFixture.setTestDataPath(dataPath); + final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class); - builder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot(""); - builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15); - myFixture.setUp(); + builder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot(""); + builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15); + myFixture.setUp(); - } + } - @After - public void tearDown() throws Exception { - myFixture.tearDown(); - myFixture = null; - } + @After + public void tearDown() throws Exception { + myFixture.tearDown(); + myFixture = null; + } - protected void doTest(String testName, String hint) throws Throwable { - // Messages.showInfoMessage("Test started", "Info"); - myFixture.configureByFile(testName + ".java"); - final IntentionAction action = myFixture.findSingleIntention(hint); - Assert.assertNotNull(action); - myFixture.launchAction(action); - myFixture.checkResultByFile(testName + ".after.java"); - } + protected void doTest(String testName, String hint) throws Throwable { + // Messages.showInfoMessage("Test started", "Info"); + myFixture.configureByFile(testName + ".java"); + final IntentionAction action = myFixture.findSingleIntention(hint); + Assert.assertNotNull(action); + myFixture.launchAction(action); + myFixture.checkResultByFile(testName + ".after.java"); + } - @Test - public void test() throws Throwable { - doTest("before.template", "Convert ternary operator to if statement"); - } + @Test + public void test() throws Throwable { + doTest("before.template", "Convert ternary operator to if statement"); + } } diff --git a/code_samples/editor_basics/resources/META-INF/plugin.xml b/code_samples/editor_basics/resources/META-INF/plugin.xml index b25400a7d..ec459c251 100644 --- a/code_samples/editor_basics/resources/META-INF/plugin.xml +++ b/code_samples/editor_basics/resources/META-INF/plugin.xml @@ -25,15 +25,21 @@ - - - - - + + + diff --git a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorAreaIllustration.java b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorAreaIllustration.java index f8efe3eaf..da1d09269 100644 --- a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorAreaIllustration.java +++ b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorAreaIllustration.java @@ -3,7 +3,10 @@ package org.jetbrains.tutorials.editor.basics; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.CaretModel; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.editor.VisualPosition; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -11,22 +14,22 @@ import com.intellij.openapi.ui.Messages; * @author Anna Bulenkova */ public class EditorAreaIllustration extends AnAction { - @Override - public void actionPerformed(AnActionEvent anActionEvent) { - final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR); - CaretModel caretModel = editor.getCaretModel(); - LogicalPosition logicalPosition = caretModel.getLogicalPosition(); - VisualPosition visualPosition = caretModel.getVisualPosition(); - int offset = caretModel.getOffset(); - Messages.showInfoMessage(logicalPosition.toString() + "\n" + - visualPosition.toString() + "\n" + - "Offset: " + offset, "Caret Parameters Inside The Editor"); - } + @Override + public void actionPerformed(AnActionEvent anActionEvent) { + final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR); + CaretModel caretModel = editor.getCaretModel(); + LogicalPosition logicalPosition = caretModel.getLogicalPosition(); + VisualPosition visualPosition = caretModel.getVisualPosition(); + int offset = caretModel.getOffset(); + Messages.showInfoMessage(logicalPosition.toString() + "\n" + + visualPosition.toString() + "\n" + + "Offset: " + offset, "Caret Parameters Inside The Editor"); + } - @Override - public void update(AnActionEvent e) { - final Project project = e.getData(CommonDataKeys.PROJECT); - final Editor editor = e.getData(CommonDataKeys.EDITOR); - e.getPresentation().setVisible(project != null && editor != null); - } + @Override + public void update(AnActionEvent e) { + final Project project = e.getData(CommonDataKeys.PROJECT); + final Editor editor = e.getData(CommonDataKeys.EDITOR); + e.getPresentation().setVisible(project != null && editor != null); + } } diff --git a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorHandlerIllustration.java b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorHandlerIllustration.java index 5232bb09a..56c283668 100644 --- a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorHandlerIllustration.java +++ b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorHandlerIllustration.java @@ -14,19 +14,21 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class EditorHandlerIllustration extends AnAction { - @Override - public void actionPerformed(@NotNull AnActionEvent anActionEvent) { - final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR); - EditorActionManager actionManager = EditorActionManager.getInstance(); - //Insert one more caret below the active caret - EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW); - actionHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), anActionEvent.getDataContext()); - } - @Override - public void update(@NotNull final AnActionEvent anActionEvent) { - //Set visible if at least one caret is available - final Project project = anActionEvent.getData(CommonDataKeys.PROJECT); - final Editor editor = anActionEvent.getData(CommonDataKeys.EDITOR); - anActionEvent.getPresentation().setVisible((project != null && editor != null && !editor.getCaretModel().getAllCarets().isEmpty())); - } + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR); + EditorActionManager actionManager = EditorActionManager.getInstance(); + //Insert one more caret below the active caret + EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW); + actionHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), anActionEvent.getDataContext()); + } + + @Override + public void update(@NotNull final AnActionEvent anActionEvent) { + //Set visible if at least one caret is available + final Project project = anActionEvent.getData(CommonDataKeys.PROJECT); + final Editor editor = anActionEvent.getData(CommonDataKeys.EDITOR); + anActionEvent.getPresentation() + .setVisible((project != null && editor != null && !editor.getCaretModel().getAllCarets().isEmpty())); + } } diff --git a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorIllustration.java b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorIllustration.java index 8185cd324..af530bb57 100644 --- a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorIllustration.java +++ b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/EditorIllustration.java @@ -16,40 +16,41 @@ import com.intellij.openapi.project.Project; */ public class EditorIllustration extends AnAction { - static { - final EditorActionManager actionManager = EditorActionManager.getInstance(); - final TypedAction typedAction = actionManager.getTypedAction(); - typedAction.setupHandler(new MyTypedHandler()); - } + static { + final EditorActionManager actionManager = EditorActionManager.getInstance(); + final TypedAction typedAction = actionManager.getTypedAction(); + typedAction.setupHandler(new MyTypedHandler()); + } - @Override - public void actionPerformed(final AnActionEvent anActionEvent) { - //Get all the required data from data keys - final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR); - final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT); - //Access document, caret, and selection - final Document document = editor.getDocument(); - final SelectionModel selectionModel = editor.getSelectionModel(); + @Override + public void actionPerformed(final AnActionEvent anActionEvent) { + //Get all the required data from data keys + final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR); + final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT); + //Access document, caret, and selection + final Document document = editor.getDocument(); + final SelectionModel selectionModel = editor.getSelectionModel(); - final int start = selectionModel.getSelectionStart(); - final int end = selectionModel.getSelectionEnd(); - //New instance of Runnable to make a replacement - Runnable runnable = new Runnable() { - @Override - public void run() { - document.replaceString(start, end, "Replacement"); - } - }; - //Making the replacement - WriteCommandAction.runWriteCommandAction(project, runnable); - selectionModel.removeSelection(); - } - @Override - public void update(final AnActionEvent e) { - //Get required data keys - final Project project = e.getData(CommonDataKeys.PROJECT); - final Editor editor = e.getData(CommonDataKeys.EDITOR); - //Set visibility only in case of existing project and editor and if some text in the editor is selected - e.getPresentation().setVisible((project != null && editor != null && editor.getSelectionModel().hasSelection())); - } + final int start = selectionModel.getSelectionStart(); + final int end = selectionModel.getSelectionEnd(); + //New instance of Runnable to make a replacement + Runnable runnable = new Runnable() { + @Override + public void run() { + document.replaceString(start, end, "Replacement"); + } + }; + //Making the replacement + WriteCommandAction.runWriteCommandAction(project, runnable); + selectionModel.removeSelection(); + } + + @Override + public void update(final AnActionEvent e) { + //Get required data keys + final Project project = e.getData(CommonDataKeys.PROJECT); + final Editor editor = e.getData(CommonDataKeys.EDITOR); + //Set visibility only in case of existing project and editor and if some text in the editor is selected + e.getPresentation().setVisible((project != null && editor != null && editor.getSelectionModel().hasSelection())); + } } diff --git a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/MyTypedHandler.java b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/MyTypedHandler.java index 56f8218cf..c757c0abe 100644 --- a/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/MyTypedHandler.java +++ b/code_samples/editor_basics/src/org/jetbrains/tutorials/editor/basics/MyTypedHandler.java @@ -12,16 +12,16 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class MyTypedHandler implements TypedActionHandler { - @Override - public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) { - final Document document = editor.getDocument(); - Project project = editor.getProject(); - Runnable runnable = new Runnable() { - @Override - public void run() { - document.insertString(0, "Typed\n"); - } - }; - WriteCommandAction.runWriteCommandAction(project, runnable); - } + @Override + public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) { + final Document document = editor.getDocument(); + Project project = editor.getProject(); + Runnable runnable = new Runnable() { + @Override + public void run() { + document.insertString(0, "Typed\n"); + } + }; + WriteCommandAction.runWriteCommandAction(project, runnable); + } } diff --git a/code_samples/facet_basics/resources/META-INF/plugin.xml b/code_samples/facet_basics/resources/META-INF/plugin.xml index 5b15982c7..182fdcf97 100644 --- a/code_samples/facet_basics/resources/META-INF/plugin.xml +++ b/code_samples/facet_basics/resources/META-INF/plugin.xml @@ -1,36 +1,36 @@ - com.intellij.tutorials.facet - Facet Demo - 1.0 - JetBrains + com.intellij.tutorials.facet + Facet Demo + 1.0 + JetBrains - Basic example of working with facets + Basic example of working with facets - Initial commit + Initial commit - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + \ No newline at end of file diff --git a/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacet.java b/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacet.java index 804f6d1a4..cbf7c4c11 100644 --- a/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacet.java +++ b/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacet.java @@ -8,9 +8,13 @@ import com.intellij.openapi.module.Module; * @author Anna Bulenkova */ public class DemoFacet extends Facet { - public static final String ID = "DEMO_FACET_ID"; + public static final String ID = "DEMO_FACET_ID"; - public DemoFacet(FacetType facetType, Module module, String name, DemoFacetConfiguration configuration, Facet underlyingFacet) { - super(facetType, module, name, configuration, underlyingFacet); - } + public DemoFacet(FacetType facetType, + Module module, + String name, + DemoFacetConfiguration configuration, + Facet underlyingFacet) { + super(facetType, module, name, configuration, underlyingFacet); + } } diff --git a/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetConfiguration.java b/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetConfiguration.java index 8ba2f450b..d21a20c3a 100644 --- a/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetConfiguration.java +++ b/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetConfiguration.java @@ -17,63 +17,64 @@ import java.awt.*; * @author Anna Bulenkova */ public class DemoFacetConfiguration implements FacetConfiguration { - public static final String DEMO_FACET_TAG_NAME = "DemoFacet"; - public static final String PATH_TO_SDK_ATTR_NAME = "pathToSdk"; - private String myPathToSdk = ""; - JTextField myPath = new JTextField(myPathToSdk); - @Override - public FacetEditorTab[] createEditorTabs(FacetEditorContext context, FacetValidatorsManager manager) { - return new FacetEditorTab[] { - new FacetEditorTab() { + public static final String DEMO_FACET_TAG_NAME = "DemoFacet"; + public static final String PATH_TO_SDK_ATTR_NAME = "pathToSdk"; + private String myPathToSdk = ""; + JTextField myPath = new JTextField(myPathToSdk); - @NotNull - @Override - public JComponent createComponent() { - JPanel top = new JPanel(new BorderLayout()); - top.add(new JLabel("Path to SDK: "), BorderLayout.WEST); - top.add(myPath); - JPanel panel = new JPanel(new BorderLayout()); - panel.add(top, BorderLayout.NORTH); - return panel; - } + @Override + public FacetEditorTab[] createEditorTabs(FacetEditorContext context, FacetValidatorsManager manager) { + return new FacetEditorTab[]{ + new FacetEditorTab() { - @Nls - @Override - public String getDisplayName() { - return "Demo Framework"; - } + @NotNull + @Override + public JComponent createComponent() { + JPanel top = new JPanel(new BorderLayout()); + top.add(new JLabel("Path to SDK: "), BorderLayout.WEST); + top.add(myPath); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(top, BorderLayout.NORTH); + return panel; + } - @Override - public boolean isModified() { - return myPath.getText().equalsIgnoreCase(myPathToSdk); + @Nls + @Override + public String getDisplayName() { + return "Demo Framework"; + } + + @Override + public boolean isModified() { + return myPath.getText().equalsIgnoreCase(myPathToSdk); // return !StringUtil.equalsIgnoreWhitespaces(myPath.getText(), myPathToSdk); - } + } - @Override - public void reset() { - myPath.setText(myPathToSdk); - } - - @Override - public void disposeUIResources() { - } - } - }; - } - - @Override - public void readExternal(Element element) throws InvalidDataException { - Element facet = element.getChild(DEMO_FACET_TAG_NAME); - if (facet != null) { - myPathToSdk = facet.getAttributeValue(PATH_TO_SDK_ATTR_NAME, ""); + @Override + public void reset() { myPath.setText(myPathToSdk); - } - } + } - @Override - public void writeExternal(Element element) throws WriteExternalException { - Element facet = new Element(DEMO_FACET_TAG_NAME); - facet.setAttribute(PATH_TO_SDK_ATTR_NAME, myPathToSdk); - element.addContent(facet); + @Override + public void disposeUIResources() { + } + } + }; + } + + @Override + public void readExternal(Element element) throws InvalidDataException { + Element facet = element.getChild(DEMO_FACET_TAG_NAME); + if (facet != null) { + myPathToSdk = facet.getAttributeValue(PATH_TO_SDK_ATTR_NAME, ""); + myPath.setText(myPathToSdk); } + } + + @Override + public void writeExternal(Element element) throws WriteExternalException { + Element facet = new Element(DEMO_FACET_TAG_NAME); + facet.setAttribute(PATH_TO_SDK_ATTR_NAME, myPathToSdk); + element.addContent(facet); + } } diff --git a/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetType.java b/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetType.java index f1664fd45..c8ae2356a 100644 --- a/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetType.java +++ b/code_samples/facet_basics/src/com/intellij/tutorials/facet/DemoFacetType.java @@ -15,29 +15,33 @@ import javax.swing.*; * @author Anna Bulenkova */ public class DemoFacetType extends FacetType { - private static final FacetTypeId TYPE_ID = new FacetTypeId(DemoFacet.ID); - public DemoFacetType() { - super(TYPE_ID, DemoFacet.ID, "Demo Facet"); - } + private static final FacetTypeId TYPE_ID = new FacetTypeId(DemoFacet.ID); - @Override - public DemoFacetConfiguration createDefaultConfiguration() { - return new DemoFacetConfiguration(); - } + public DemoFacetType() { + super(TYPE_ID, DemoFacet.ID, "Demo Facet"); + } - @Override - public DemoFacet createFacet(@NotNull Module module, String s, @NotNull DemoFacetConfiguration configuration, Facet facet) { - return new DemoFacet(this, module, s, configuration, facet); - } + @Override + public DemoFacetConfiguration createDefaultConfiguration() { + return new DemoFacetConfiguration(); + } - @Override - public boolean isSuitableModuleType(ModuleType type) { - return true; - } + @Override + public DemoFacet createFacet(@NotNull Module module, + String s, + @NotNull DemoFacetConfiguration configuration, + Facet facet) { + return new DemoFacet(this, module, s, configuration, facet); + } - @Nullable - @Override - public Icon getIcon() { - return AllIcons.General.Information; - } + @Override + public boolean isSuitableModuleType(ModuleType type) { + return true; + } + + @Nullable + @Override + public Icon getIcon() { + return AllIcons.General.Information; + } } diff --git a/code_samples/framework/src/com/intellij/tutorials/framework/DemoFramework.java b/code_samples/framework/src/com/intellij/tutorials/framework/DemoFramework.java index 6c4db74e7..c226edfcf 100644 --- a/code_samples/framework/src/com/intellij/tutorials/framework/DemoFramework.java +++ b/code_samples/framework/src/com/intellij/tutorials/framework/DemoFramework.java @@ -18,54 +18,57 @@ import javax.swing.*; * @author Anna Bulenkova */ public class DemoFramework extends FrameworkTypeEx { - public static final String FRAMEWORK_ID = "Demo"; - protected DemoFramework() { - super(FRAMEWORK_ID); - } + public static final String FRAMEWORK_ID = "Demo"; - @NotNull - @Override - public FrameworkSupportInModuleProvider createProvider() { - return new FrameworkSupportInModuleProvider() { - @NotNull - @Override - public FrameworkTypeEx getFrameworkType() { - return DemoFramework.this; - } + protected DemoFramework() { + super(FRAMEWORK_ID); + } - @NotNull - @Override - public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull FrameworkSupportModel model) { - return new FrameworkSupportInModuleConfigurable() { - @Nullable - @Override - public JComponent createComponent() { - return new JCheckBox("Extra Option"); - } + @NotNull + @Override + public FrameworkSupportInModuleProvider createProvider() { + return new FrameworkSupportInModuleProvider() { + @NotNull + @Override + public FrameworkTypeEx getFrameworkType() { + return DemoFramework.this; + } - @Override - public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ModifiableModelsProvider provider) { - //do what you want here: setup a library, generate a specific file, etc - } - }; - } + @NotNull + @Override + public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull FrameworkSupportModel model) { + return new FrameworkSupportInModuleConfigurable() { + @Nullable + @Override + public JComponent createComponent() { + return new JCheckBox("Extra Option"); + } - @Override - public boolean isEnabledForModuleType(@NotNull ModuleType type) { - return true; - } + @Override + public void addSupport(@NotNull Module module, + @NotNull ModifiableRootModel model, + @NotNull ModifiableModelsProvider provider) { + //do what you want here: setup a library, generate a specific file, etc + } }; - } + } - @NotNull - @Override - public String getPresentableName() { - return "Demo Framework"; - } + @Override + public boolean isEnabledForModuleType(@NotNull ModuleType type) { + return true; + } + }; + } - @NotNull - @Override - public Icon getIcon() { - return AllIcons.Providers.Apache; - } + @NotNull + @Override + public String getPresentableName() { + return "Demo Framework"; + } + + @NotNull + @Override + public Icon getIcon() { + return AllIcons.Providers.Apache; + } } diff --git a/code_samples/gradle_plugin_demo/build.gradle b/code_samples/gradle_plugin_demo/build.gradle index 33e6bee8d..91f275cb3 100644 --- a/code_samples/gradle_plugin_demo/build.gradle +++ b/code_samples/gradle_plugin_demo/build.gradle @@ -27,5 +27,5 @@ group 'org.jetbrains' version '0.0.1-SNAPSHOT' repositories { - mavenCentral () + mavenCentral() } \ No newline at end of file diff --git a/code_samples/gradle_plugin_demo/src/main/java/HelloAction.java b/code_samples/gradle_plugin_demo/src/main/java/HelloAction.java index b0462638a..56e28c138 100644 --- a/code_samples/gradle_plugin_demo/src/main/java/HelloAction.java +++ b/code_samples/gradle_plugin_demo/src/main/java/HelloAction.java @@ -8,12 +8,12 @@ import com.intellij.openapi.ui.Messages; * Created by breandan on 11/25/2015. */ public class HelloAction extends AnAction { - public HelloAction() { - super("Hello"); - } + public HelloAction() { + super("Hello"); + } - public void actionPerformed(AnActionEvent event) { - Project project = event.getData(PlatformDataKeys.PROJECT); - Messages.showMessageDialog(project, "Hello world!", "Greeting", Messages.getInformationIcon()); - } + public void actionPerformed(AnActionEvent event) { + Project project = event.getData(PlatformDataKeys.PROJECT); + Messages.showMessageDialog(project, "Hello world!", "Greeting", Messages.getInformationIcon()); + } } \ No newline at end of file diff --git a/code_samples/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml b/code_samples/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml index 6ff607a5a..a7dbef57b 100644 --- a/code_samples/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml +++ b/code_samples/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml @@ -33,8 +33,8 @@ - - + + diff --git a/code_samples/inspection/resources/META-INF/plugin.xml b/code_samples/inspection/resources/META-INF/plugin.xml index f978c00de..cbd49478c 100644 --- a/code_samples/inspection/resources/META-INF/plugin.xml +++ b/code_samples/inspection/resources/META-INF/plugin.xml @@ -1,30 +1,30 @@ - com.intellij.tutorials.inspection - Inspection Demo - 1.0 - JetBrains + com.intellij.tutorials.inspection + Inspection Demo + 1.0 + JetBrains - Basic example of working with code inspections + Basic example of working with code inspections - Initial commit + Initial commit - + - - + + - + - - - + + + - - - + + + - - - + + + \ No newline at end of file diff --git a/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoCodeInspection.java b/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoCodeInspection.java index 7b88a1055..c20cfeb81 100644 --- a/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoCodeInspection.java +++ b/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoCodeInspection.java @@ -9,16 +9,16 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class DemoCodeInspection extends LocalInspectionTool { - @Nls - @NotNull - @Override - public String getDisplayName() { - return "Demo Inspection"; - } + @Nls + @NotNull + @Override + public String getDisplayName() { + return "Demo Inspection"; + } - @NotNull - @Override - public DemoInspectionVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { - return new DemoInspectionVisitor(); - } + @NotNull + @Override + public DemoInspectionVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { + return new DemoInspectionVisitor(); + } } diff --git a/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionToolProvider.java b/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionToolProvider.java index aad593a5c..342f2c42a 100644 --- a/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionToolProvider.java +++ b/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionToolProvider.java @@ -6,7 +6,7 @@ import com.intellij.codeInspection.InspectionToolProvider; * @author Anna Bulenkova */ public class DemoInspectionToolProvider implements InspectionToolProvider { - public Class[] getInspectionClasses() { - return new Class[] { DemoCodeInspection.class}; - } + public Class[] getInspectionClasses() { + return new Class[]{DemoCodeInspection.class}; + } } diff --git a/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionVisitor.java b/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionVisitor.java index 96e73fe5c..f824a540b 100644 --- a/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionVisitor.java +++ b/code_samples/inspection/src/com/intellij/tutorials/inspection/DemoInspectionVisitor.java @@ -8,13 +8,13 @@ import com.intellij.psi.PsiPlainTextFile; * @author Anna Bulenkova */ public class DemoInspectionVisitor extends PsiElementVisitor { - @Override - public void visitElement(PsiElement element) { - super.visitElement(element); - } + @Override + public void visitElement(PsiElement element) { + super.visitElement(element); + } - @Override - public void visitPlainTextFile(PsiPlainTextFile file) { - super.visitPlainTextFile(file); - } + @Override + public void visitPlainTextFile(PsiPlainTextFile file) { + super.visitPlainTextFile(file); + } } diff --git a/code_samples/kotlin_demo/resources/META-INF/plugin.xml b/code_samples/kotlin_demo/resources/META-INF/plugin.xml index a61f95cc8..87959dce2 100644 --- a/code_samples/kotlin_demo/resources/META-INF/plugin.xml +++ b/code_samples/kotlin_demo/resources/META-INF/plugin.xml @@ -30,8 +30,8 @@ - - + + diff --git a/code_samples/live_templates/resources/liveTemplates/Markdown.xml b/code_samples/live_templates/resources/liveTemplates/Markdown.xml index c7788d82b..2f96a90da 100644 --- a/code_samples/live_templates/resources/liveTemplates/Markdown.xml +++ b/code_samples/live_templates/resources/liveTemplates/Markdown.xml @@ -1,9 +1,13 @@ - + \ No newline at end of file diff --git a/code_samples/live_templates/src/MarkdownContext.java b/code_samples/live_templates/src/MarkdownContext.java index 1c1c05a6d..193983316 100644 --- a/code_samples/live_templates/src/MarkdownContext.java +++ b/code_samples/live_templates/src/MarkdownContext.java @@ -1,17 +1,14 @@ -import com.intellij.codeInsight.template.EverywhereContextType; import com.intellij.codeInsight.template.TemplateContextType; import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class MarkdownContext extends TemplateContextType { - protected MarkdownContext() { - super("MARKDOWN", "Markdown"); - } + protected MarkdownContext() { + super("MARKDOWN", "Markdown"); + } - @Override - public boolean isInContext(@NotNull PsiFile file, int offset) { - return file.getName().endsWith(".md"); - } + @Override + public boolean isInContext(@NotNull PsiFile file, int offset) { + return file.getName().endsWith(".md"); + } } diff --git a/code_samples/live_templates/src/MarkdownTemplateProvider.java b/code_samples/live_templates/src/MarkdownTemplateProvider.java index c113accb3..8aba8d720 100644 --- a/code_samples/live_templates/src/MarkdownTemplateProvider.java +++ b/code_samples/live_templates/src/MarkdownTemplateProvider.java @@ -2,15 +2,14 @@ import com.intellij.codeInsight.template.impl.DefaultLiveTemplatesProvider; import org.jetbrains.annotations.Nullable; public class MarkdownTemplateProvider implements DefaultLiveTemplatesProvider { - @Override - public String[] getDefaultLiveTemplateFiles() - { - return new String[] {"liveTemplates/Markdown"}; - } + @Override + public String[] getDefaultLiveTemplateFiles() { + return new String[]{"liveTemplates/Markdown"}; + } - @Nullable - @Override - public String[] getHiddenLiveTemplateFiles() { - return new String[0]; - } + @Nullable + @Override + public String[] getHiddenLiveTemplateFiles() { + return new String[0]; + } } diff --git a/code_samples/max_opened_projects/resources/META-INF/plugin.xml b/code_samples/max_opened_projects/resources/META-INF/plugin.xml index d844bd01e..f5adecf24 100644 --- a/code_samples/max_opened_projects/resources/META-INF/plugin.xml +++ b/code_samples/max_opened_projects/resources/META-INF/plugin.xml @@ -11,9 +11,9 @@ - - MyPackage.MaxProject - + + MyPackage.MaxProject + @@ -22,8 +22,8 @@ - - - + + + \ No newline at end of file diff --git a/code_samples/max_opened_projects/src/MyPackage/MaxProject.java b/code_samples/max_opened_projects/src/MyPackage/MaxProject.java index dbf179d55..5062fd91a 100644 --- a/code_samples/max_opened_projects/src/MyPackage/MaxProject.java +++ b/code_samples/max_opened_projects/src/MyPackage/MaxProject.java @@ -15,40 +15,41 @@ import org.jetbrains.annotations.NotNull; * To change this template use File | Settings | File Templates. */ public class MaxProject implements ProjectComponent { - public MaxProject(Project project) { + public MaxProject(Project project) { + } + + public void initComponent() { + // TODO: insert component initialization logic here + } + + public void disposeComponent() { + // TODO: insert component disposal logic here + } + + @NotNull + public String getComponentName() { + return "MaxProject"; + } + + public void projectOpened() { + // called when project is opened + MyCounter CommandCounter = ServiceManager.getService(MyCounter.class); + + if (CommandCounter.IncreaseCounter() == -1) { + Messages.showMessageDialog( + "The maximum number of opened projects exceeds " + String.valueOf(CommandCounter.MaxCount) + + " projects!", "Error", Messages.getErrorIcon()); + ProjectManager PM = ProjectManager.getInstance(); + Project[] AllProjects = PM.getOpenProjects(); + Project project = AllProjects[AllProjects.length - 1]; + PM.closeProject(project); } - - public void initComponent() { - // TODO: insert component initialization logic here - } - - public void disposeComponent() { - // TODO: insert component disposal logic here - } - - @NotNull - public String getComponentName() { - return "MaxProject"; - } - - public void projectOpened() { - // called when project is opened - MyCounter CommandCounter = ServiceManager.getService(MyCounter.class); - - if (CommandCounter.IncreaseCounter() == -1) { - Messages.showMessageDialog("The maximum number of opened projects exceeds " + String.valueOf(CommandCounter.MaxCount) + - " projects!", "Error", Messages.getErrorIcon()); - ProjectManager PM=ProjectManager.getInstance(); - Project[] AllProjects = PM.getOpenProjects(); - Project project = AllProjects[AllProjects.length-1]; - PM.closeProject(project); - } - } + } - public void projectClosed() { - // called when project is being closed - MyCounter CommandCounter = ServiceManager.getService(MyCounter.class); - CommandCounter.DecreaseCounter(); - } + public void projectClosed() { + // called when project is being closed + MyCounter CommandCounter = ServiceManager.getService(MyCounter.class); + CommandCounter.DecreaseCounter(); + } } diff --git a/code_samples/max_opened_projects/src/MyPackage/MyCounter.java b/code_samples/max_opened_projects/src/MyPackage/MyCounter.java index f2e5417a8..fa5af32b2 100644 --- a/code_samples/max_opened_projects/src/MyPackage/MyCounter.java +++ b/code_samples/max_opened_projects/src/MyPackage/MyCounter.java @@ -8,22 +8,23 @@ package MyPackage; * To change this template use File | Settings | File Templates. */ public class MyCounter { - private int Count = 0; - // Sets the maximum allowed number of opened projects. - public final int MaxCount = 3; - public MyCounter(){ + private int Count = 0; + // Sets the maximum allowed number of opened projects. + public final int MaxCount = 3; + + public MyCounter() { - } + } - public int IncreaseCounter() { - Count++; - return (Count > MaxCount) ? -1:Count; - } + public int IncreaseCounter() { + Count++; + return (Count > MaxCount) ? -1 : Count; + } - public int DecreaseCounter() { - Count--; - return (Count > MaxCount) ? -1:Count; - } + public int DecreaseCounter() { + Count--; + return (Count > MaxCount) ? -1 : Count; + } } diff --git a/code_samples/module/resources/META-INF/plugin.xml b/code_samples/module/resources/META-INF/plugin.xml index 2b6c1bab7..4fd69b8f3 100644 --- a/code_samples/module/resources/META-INF/plugin.xml +++ b/code_samples/module/resources/META-INF/plugin.xml @@ -1,36 +1,36 @@ - com.intellij.tutorials.module - Module Type Demo - 1.0 - JetBrains + com.intellij.tutorials.module + Module Type Demo + 1.0 + JetBrains - Basic example of working with module types + Basic example of working with module types - Initial commit + Initial commit - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + \ No newline at end of file diff --git a/code_samples/module/src/com/intellij/tutorials/module/DemoModuleBuilder.java b/code_samples/module/src/com/intellij/tutorials/module/DemoModuleBuilder.java index 23417dcbc..194545b6b 100644 --- a/code_samples/module/src/com/intellij/tutorials/module/DemoModuleBuilder.java +++ b/code_samples/module/src/com/intellij/tutorials/module/DemoModuleBuilder.java @@ -13,19 +13,19 @@ import org.jetbrains.annotations.Nullable; * @author Anna Bulenkova */ public class DemoModuleBuilder extends ModuleBuilder { - @Override - public void setupRootModel(ModifiableRootModel model) throws ConfigurationException { + @Override + public void setupRootModel(ModifiableRootModel model) throws ConfigurationException { - } + } - @Override - public ModuleType getModuleType() { - return DemoModuleType.getInstance(); - } + @Override + public ModuleType getModuleType() { + return DemoModuleType.getInstance(); + } - @Nullable - @Override - public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) { - return new DemoModuleWizardStep(); - } + @Nullable + @Override + public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) { + return new DemoModuleWizardStep(); + } } diff --git a/code_samples/module/src/com/intellij/tutorials/module/DemoModuleType.java b/code_samples/module/src/com/intellij/tutorials/module/DemoModuleType.java index e43e92f80..0e2272cc6 100644 --- a/code_samples/module/src/com/intellij/tutorials/module/DemoModuleType.java +++ b/code_samples/module/src/com/intellij/tutorials/module/DemoModuleType.java @@ -14,47 +14,49 @@ import javax.swing.*; * @author Anna Bulenkova */ public class DemoModuleType extends ModuleType { - private static final String ID = "DEMO_MODULE_TYPE"; + private static final String ID = "DEMO_MODULE_TYPE"; - public DemoModuleType() { - super(ID); - } + public DemoModuleType() { + super(ID); + } - public static DemoModuleType getInstance() { - return (DemoModuleType) ModuleTypeManager.getInstance().findByID(ID); - } + public static DemoModuleType getInstance() { + return (DemoModuleType) ModuleTypeManager.getInstance().findByID(ID); + } - @NotNull - @Override - public DemoModuleBuilder createModuleBuilder() { - return new DemoModuleBuilder(); - } + @NotNull + @Override + public DemoModuleBuilder createModuleBuilder() { + return new DemoModuleBuilder(); + } - @NotNull - @Override - public String getName() { - return "Demo Module Type"; - } + @NotNull + @Override + public String getName() { + return "Demo Module Type"; + } - @NotNull - @Override - public String getDescription() { - return "Demo Module Type"; - } + @NotNull + @Override + public String getDescription() { + return "Demo Module Type"; + } - @Override - public Icon getBigIcon() { - return AllIcons.General.Information; - } + @Override + public Icon getBigIcon() { + return AllIcons.General.Information; + } - @Override - public Icon getNodeIcon(@Deprecated boolean b) { - return AllIcons.General.Information; - } + @Override + public Icon getNodeIcon(@Deprecated boolean b) { + return AllIcons.General.Information; + } - @NotNull - @Override - public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull DemoModuleBuilder moduleBuilder, @NotNull ModulesProvider modulesProvider) { - return super.createWizardSteps(wizardContext, moduleBuilder, modulesProvider); - } + @NotNull + @Override + public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, + @NotNull DemoModuleBuilder moduleBuilder, + @NotNull ModulesProvider modulesProvider) { + return super.createWizardSteps(wizardContext, moduleBuilder, modulesProvider); + } } diff --git a/code_samples/module/src/com/intellij/tutorials/module/DemoModuleWizardStep.java b/code_samples/module/src/com/intellij/tutorials/module/DemoModuleWizardStep.java index 4227d9e4d..d65923c22 100644 --- a/code_samples/module/src/com/intellij/tutorials/module/DemoModuleWizardStep.java +++ b/code_samples/module/src/com/intellij/tutorials/module/DemoModuleWizardStep.java @@ -8,13 +8,13 @@ import javax.swing.*; * @author Anna Bulenkova */ public class DemoModuleWizardStep extends ModuleWizardStep { - @Override - public JComponent getComponent() { - return new JLabel("Provide some setting here"); - } + @Override + public JComponent getComponent() { + return new JLabel("Provide some setting here"); + } - @Override - public void updateDataModel() { - //todo update model according to UI - } + @Override + public void updateDataModel() { + //todo update model according to UI + } } diff --git a/code_samples/plugin_sample/resources/META-INF/plugin.xml b/code_samples/plugin_sample/resources/META-INF/plugin.xml index 96ef64d6c..1a34656b4 100644 --- a/code_samples/plugin_sample/resources/META-INF/plugin.xml +++ b/code_samples/plugin_sample/resources/META-INF/plugin.xml @@ -1,140 +1,143 @@ - org.jetbrains.plugins.sample.PluginSample - Basic plugin example - 1.0 - JetBrains - Samples - org.jetbrains.plugins.sample.PluginSample + Basic plugin example + 1.0 + JetBrains + Samples + most HTML tags may be used ]]> - most HTML tags may be used ]]> - + - - - - com.intellij.modules.lang - - + + + + com.intellij.modules.lang + + - - + + - - + + - - org.jetbrains.tutorials.sample.PluginSampleBundle + + org.jetbrains.tutorials.sample.PluginSampleBundle - - - - - org.jetbrains.tutorials.sample.DummyApplicationComponent - - org.jetbrains.tutorials.sample.DummyApplicationComponentImpl - - + + + + + org.jetbrains.tutorials.sample.DummyApplicationComponent + + org.jetbrains.tutorials.sample.DummyApplicationComponentImpl + + - - - - - org.jetbrains.tutorials.sample.DummyProjectComponent - org.jetbrains.tutorials.sample.DummyProjectComponentImpl - + + + + + org.jetbrains.tutorials.sample.DummyProjectComponent + org.jetbrains.tutorials.sample.DummyProjectComponentImpl + - - + + - - - - org.jetbrains.tutorials.sample.DummyModuleComponent - org.jetbrains.tutorials.sample.DummyModuleComponentImpl - - + + + + org.jetbrains.tutorials.sample.DummyModuleComponent + org.jetbrains.tutorials.sample.DummyModuleComponentImpl + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + + + - - - - + + + + \ No newline at end of file diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponent.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponent.java index 9dc24acde..3142023c9 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponent.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponent.java @@ -5,5 +5,5 @@ import com.intellij.openapi.components.ApplicationComponent; /** * @author Anna Bulenkova */ -interface DummyApplicationComponent extends ApplicationComponent{ +interface DummyApplicationComponent extends ApplicationComponent { } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponentImpl.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponentImpl.java index 2f4f7330b..85c2bc07a 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponentImpl.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyApplicationComponentImpl.java @@ -6,19 +6,19 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class DummyApplicationComponentImpl implements DummyApplicationComponent { - @Override - public void initComponent() { + @Override + public void initComponent() { - } + } - @Override - public void disposeComponent() { + @Override + public void disposeComponent() { - } + } - @NotNull - @Override - public String getComponentName() { - return "DummyApplicationComponent"; - } + @NotNull + @Override + public String getComponentName() { + return "DummyApplicationComponent"; + } } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponent.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponent.java index ae065c9c4..1e53762cb 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponent.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponent.java @@ -5,5 +5,5 @@ import com.intellij.openapi.module.ModuleComponent; /** * @author Anna Bulenkova */ -public interface DummyModuleComponent extends ModuleComponent{ +public interface DummyModuleComponent extends ModuleComponent { } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponentImpl.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponentImpl.java index 22231fd71..5a178a96a 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponentImpl.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyModuleComponentImpl.java @@ -6,34 +6,34 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class DummyModuleComponentImpl implements DummyModuleComponent { - @Override - public void projectOpened() { + @Override + public void projectOpened() { - } + } - @Override - public void projectClosed() { + @Override + public void projectClosed() { - } + } - @Override - public void moduleAdded() { + @Override + public void moduleAdded() { - } + } - @Override - public void initComponent() { + @Override + public void initComponent() { - } + } - @Override - public void disposeComponent() { + @Override + public void disposeComponent() { - } + } - @NotNull - @Override - public String getComponentName() { - return "DummyModuleComponent"; - } + @NotNull + @Override + public String getComponentName() { + return "DummyModuleComponent"; + } } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponent.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponent.java index b49347acd..3713d6889 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponent.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponent.java @@ -5,5 +5,5 @@ import com.intellij.openapi.components.ProjectComponent; /** * @author Anna Bulenkova */ -public interface DummyProjectComponent extends ProjectComponent{ +public interface DummyProjectComponent extends ProjectComponent { } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponentImpl.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponentImpl.java index fac9b6bd0..f7325927b 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponentImpl.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/DummyProjectComponentImpl.java @@ -6,29 +6,29 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class DummyProjectComponentImpl implements DummyProjectComponent { - @Override - public void projectOpened() { + @Override + public void projectOpened() { - } + } - @Override - public void projectClosed() { + @Override + public void projectClosed() { - } + } - @Override - public void initComponent() { + @Override + public void initComponent() { - } + } - @Override - public void disposeComponent() { + @Override + public void disposeComponent() { - } + } - @NotNull - @Override - public String getComponentName() { - return "DummyProjectComponent"; - } + @NotNull + @Override + public String getComponentName() { + return "DummyProjectComponent"; + } } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/DummyActionGroup.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/DummyActionGroup.java index f55cfa613..598f781da 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/DummyActionGroup.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/DummyActionGroup.java @@ -9,9 +9,9 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class DummyActionGroup extends ActionGroup { - @NotNull - @Override - public AnAction[] getChildren(AnActionEvent anActionEvent) { - return new GroupedAction[0]; - } + @NotNull + @Override + public AnAction[] getChildren(AnActionEvent anActionEvent) { + return new GroupedAction[0]; + } } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedAction.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedAction.java index 7e665e74d..b7e58af75 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedAction.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedAction.java @@ -8,8 +8,8 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class GroupedAction extends AnAction { - @Override - public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { - } + } } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedToDefaultAction.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedToDefaultAction.java index 7f99e2f10..8355ed120 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedToDefaultAction.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/GroupedToDefaultAction.java @@ -8,8 +8,8 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class GroupedToDefaultAction extends AnAction { - @Override - public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { - } + } } diff --git a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/SimpleAction.java b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/SimpleAction.java index 6484c780c..db0cf0a60 100644 --- a/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/SimpleAction.java +++ b/code_samples/plugin_sample/src/org/jetbrains/tutorials/sample/actions/SimpleAction.java @@ -9,16 +9,16 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class SimpleAction extends AnAction { - @Override - public void actionPerformed(@NotNull AnActionEvent anActionEvent) { - } + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + } - @Override - public void update(@NotNull AnActionEvent e) { - //Make action visible and available only when project is defined - final Project project = e.getProject(); - boolean isAvailable = project != null; - e.getPresentation().setVisible(isAvailable); - e.getPresentation().setEnabled(isAvailable); - } + @Override + public void update(@NotNull AnActionEvent e) { + //Make action visible and available only when project is defined + final Project project = e.getProject(); + boolean isAvailable = project != null; + e.getPresentation().setVisible(isAvailable); + e.getPresentation().setEnabled(isAvailable); + } } diff --git a/code_samples/project_model/resources/META-INF/plugin.xml b/code_samples/project_model/resources/META-INF/plugin.xml index 0de45090a..a009ad983 100644 --- a/code_samples/project_model/resources/META-INF/plugin.xml +++ b/code_samples/project_model/resources/META-INF/plugin.xml @@ -1,55 +1,55 @@ - org.jetbrains.plugins.sample.ProjectModel - Editor basics - 1.0 - JetBrains + org.jetbrains.plugins.sample.ProjectModel + Editor basics + 1.0 + JetBrains - Project model illustration + Project model illustration - Initial commit + Initial commit - - - com.intellij.modules.lang + + + com.intellij.modules.lang - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code_samples/project_model/src/com/intellij/tutorials/project/model/LibrariesAction.java b/code_samples/project_model/src/com/intellij/tutorials/project/model/LibrariesAction.java index dd53d59dd..e921cf609 100644 --- a/code_samples/project_model/src/com/intellij/tutorials/project/model/LibrariesAction.java +++ b/code_samples/project_model/src/com/intellij/tutorials/project/model/LibrariesAction.java @@ -17,47 +17,48 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class LibrariesAction extends AnAction { - @Override - public void update(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - if (project == null) return; - Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); - if (element instanceof PsiClass) { - PsiFile psiFile = ((PsiClass) element).getContainingFile(); - if (psiFile == null) return; - VirtualFile virtualFile = psiFile.getVirtualFile(); - if (virtualFile == null) return; - event.getPresentation().setEnabledAndVisible(true); - } + @Override + public void update(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + if (project == null) return; + Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); + if (element instanceof PsiClass) { + PsiFile psiFile = ((PsiClass) element).getContainingFile(); + if (psiFile == null) return; + VirtualFile virtualFile = psiFile.getVirtualFile(); + if (virtualFile == null) return; + event.getPresentation().setEnabledAndVisible(true); } + } - @Override - public void actionPerformed(@NotNull AnActionEvent event) { - Project project = event.getProject(); - if (project == null) return; - Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); - if (element instanceof PsiClass) { - PsiFile psiFile = ((PsiClass) element).getContainingFile(); - if (psiFile == null) return; - VirtualFile virtualFile = psiFile.getVirtualFile(); - if (virtualFile == null) return; - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - StringBuilder jars = new StringBuilder(); - for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) { - if (orderEntry instanceof LibraryOrderEntry) { - final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) orderEntry; - final Library library = libraryEntry.getLibrary(); - if (library == null) continue; - VirtualFile[] files = library.getFiles(OrderRootType.CLASSES); - if (files.length == 0) continue; - for (VirtualFile jar : files) { - jars.append(jar.getName()).append(", "); - } - } - } - if (jars.length() > 0) { - Messages.showInfoMessage("Libraries for file " + virtualFile.getName() + ": " + jars.toString(), "Libraries Info"); - } + @Override + public void actionPerformed(@NotNull AnActionEvent event) { + Project project = event.getProject(); + if (project == null) return; + Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); + if (element instanceof PsiClass) { + PsiFile psiFile = ((PsiClass) element).getContainingFile(); + if (psiFile == null) return; + VirtualFile virtualFile = psiFile.getVirtualFile(); + if (virtualFile == null) return; + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + StringBuilder jars = new StringBuilder(); + for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) { + if (orderEntry instanceof LibraryOrderEntry) { + final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) orderEntry; + final Library library = libraryEntry.getLibrary(); + if (library == null) continue; + VirtualFile[] files = library.getFiles(OrderRootType.CLASSES); + if (files.length == 0) continue; + for (VirtualFile jar : files) { + jars.append(jar.getName()).append(", "); + } } + } + if (jars.length() > 0) { + Messages.showInfoMessage("Libraries for file " + virtualFile.getName() + ": " + jars.toString(), + "Libraries Info"); + } } + } } diff --git a/code_samples/project_model/src/com/intellij/tutorials/project/model/ModificationAction.java b/code_samples/project_model/src/com/intellij/tutorials/project/model/ModificationAction.java index f3919faa6..6a48952e7 100644 --- a/code_samples/project_model/src/com/intellij/tutorials/project/model/ModificationAction.java +++ b/code_samples/project_model/src/com/intellij/tutorials/project/model/ModificationAction.java @@ -19,30 +19,30 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class ModificationAction extends AnAction { - @Override - public void actionPerformed(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - if (project == null) return; - Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); - if (element instanceof PsiClass) { - PsiFile file = ((PsiClass) element).getContainingFile(); - if (file == null) return; - final VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile == null) return; - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - final Module module = fileIndex.getModuleForFile(virtualFile); - if (module == null) return; - if (!ModuleRootManager.getInstance(module).getFileIndex().isInContent(virtualFile)) { - ModuleRootModificationUtil.addModuleLibrary(module, virtualFile.getUrl()); - } - } - + @Override + public void actionPerformed(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + if (project == null) return; + Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); + if (element instanceof PsiClass) { + PsiFile file = ((PsiClass) element).getContainingFile(); + if (file == null) return; + final VirtualFile virtualFile = file.getVirtualFile(); + if (virtualFile == null) return; + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + final Module module = fileIndex.getModuleForFile(virtualFile); + if (module == null) return; + if (!ModuleRootManager.getInstance(module).getFileIndex().isInContent(virtualFile)) { + ModuleRootModificationUtil.addModuleLibrary(module, virtualFile.getUrl()); + } } - @Override - public void update(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); - event.getPresentation().setEnabledAndVisible(project != null && element != null); - } + } + + @Override + public void update(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); + event.getPresentation().setEnabledAndVisible(project != null && element != null); + } } diff --git a/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectFileIndexSampleAction.java b/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectFileIndexSampleAction.java index efe8c1da3..46b3588a6 100644 --- a/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectFileIndexSampleAction.java +++ b/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectFileIndexSampleAction.java @@ -18,38 +18,38 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class ProjectFileIndexSampleAction extends AnAction { - @Override - public void update(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - final Editor editor = event.getData(CommonDataKeys.EDITOR); - boolean visibility = project != null && editor != null; - event.getPresentation().setEnabledAndVisible(visibility); - } + @Override + public void update(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + final Editor editor = event.getData(CommonDataKeys.EDITOR); + boolean visibility = project != null && editor != null; + event.getPresentation().setEnabledAndVisible(visibility); + } - @Override - public void actionPerformed(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - final Editor editor = event.getData(CommonDataKeys.EDITOR); - if (project == null || editor == null) return; - Document document = editor.getDocument(); - FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); - VirtualFile virtualFile = fileDocumentManager.getFile(document); - ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - if (virtualFile != null) { - Module module = projectFileIndex.getModuleForFile(virtualFile); - String moduleName; - moduleName = module != null ? module.getName() : "No module defined for file"; + @Override + public void actionPerformed(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + final Editor editor = event.getData(CommonDataKeys.EDITOR); + if (project == null || editor == null) return; + Document document = editor.getDocument(); + FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); + VirtualFile virtualFile = fileDocumentManager.getFile(document); + ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + if (virtualFile != null) { + Module module = projectFileIndex.getModuleForFile(virtualFile); + String moduleName; + moduleName = module != null ? module.getName() : "No module defined for file"; - VirtualFile moduleContentRoot = projectFileIndex.getContentRootForFile(virtualFile); - boolean isLibraryFile = projectFileIndex.isLibraryClassFile(virtualFile); - boolean isInLibraryClasses = projectFileIndex.isInLibraryClasses(virtualFile); - boolean isInLibrarySource = projectFileIndex.isInLibrarySource(virtualFile); - Messages.showInfoMessage("Module: " + moduleName + "\n" + - "Module content root: " + moduleContentRoot + "\n" + - "Is library file: " + isLibraryFile + "\n" + - "Is in library classes" + isInLibraryClasses + - "Is in library source" + isInLibrarySource, - "Main File Info for" + virtualFile.getName()); - } + VirtualFile moduleContentRoot = projectFileIndex.getContentRootForFile(virtualFile); + boolean isLibraryFile = projectFileIndex.isLibraryClassFile(virtualFile); + boolean isInLibraryClasses = projectFileIndex.isInLibraryClasses(virtualFile); + boolean isInLibrarySource = projectFileIndex.isInLibrarySource(virtualFile); + Messages.showInfoMessage("Module: " + moduleName + "\n" + + "Module content root: " + moduleContentRoot + "\n" + + "Is library file: " + isLibraryFile + "\n" + + "Is in library classes" + isInLibraryClasses + + "Is in library source" + isInLibrarySource, + "Main File Info for" + virtualFile.getName()); } + } } diff --git a/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectSdkAction.java b/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectSdkAction.java index b030992f2..22f906422 100644 --- a/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectSdkAction.java +++ b/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectSdkAction.java @@ -12,23 +12,23 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class ProjectSdkAction extends AnAction { - @Override - public void actionPerformed(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - if (project != null) { - String projectSDKName = ProjectRootManager.getInstance(project).getProjectSdkName(); - String newProjectSdkName = "New Sdk Name"; - ProjectRootManager.getInstance(project).setProjectSdkName(newProjectSdkName); - Messages.showInfoMessage(projectSDKName + " has changed to " + newProjectSdkName, "Project Sdk Info"); - } + @Override + public void actionPerformed(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + if (project != null) { + String projectSDKName = ProjectRootManager.getInstance(project).getProjectSdkName(); + String newProjectSdkName = "New Sdk Name"; + ProjectRootManager.getInstance(project).setProjectSdkName(newProjectSdkName); + Messages.showInfoMessage(projectSDKName + " has changed to " + newProjectSdkName, "Project Sdk Info"); } + } - @Override - public void update(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - if (project != null) { - Sdk sdk = ProjectRootManager.getInstance(project).getProjectSdk(); - event.getPresentation().setEnabledAndVisible(sdk != null); - } + @Override + public void update(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + if (project != null) { + Sdk sdk = ProjectRootManager.getInstance(project).getProjectSdk(); + event.getPresentation().setEnabledAndVisible(sdk != null); } + } } diff --git a/code_samples/project_model/src/com/intellij/tutorials/project/model/ShowSourceRootsActions.java b/code_samples/project_model/src/com/intellij/tutorials/project/model/ShowSourceRootsActions.java index 2a7d5e527..baaea1b72 100644 --- a/code_samples/project_model/src/com/intellij/tutorials/project/model/ShowSourceRootsActions.java +++ b/code_samples/project_model/src/com/intellij/tutorials/project/model/ShowSourceRootsActions.java @@ -12,23 +12,24 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class ShowSourceRootsActions extends AnAction { - @Override - public void actionPerformed(@NotNull final AnActionEvent event) { - Project project = event.getProject(); - if (project == null) return; - String projectName = project.getName(); - StringBuilder sourceRootsList = new StringBuilder(); - VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentSourceRoots(); - for (VirtualFile file : vFiles) { - sourceRootsList.append(file.getUrl()).append("\n"); - } - Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, "Project Properties"); + @Override + public void actionPerformed(@NotNull final AnActionEvent event) { + Project project = event.getProject(); + if (project == null) return; + String projectName = project.getName(); + StringBuilder sourceRootsList = new StringBuilder(); + VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentSourceRoots(); + for (VirtualFile file : vFiles) { + sourceRootsList.append(file.getUrl()).append("\n"); } + Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, + "Project Properties"); + } - @Override - public void update(@NotNull final AnActionEvent event) { - boolean visibility = event.getProject() != null; - event.getPresentation().setEnabled(visibility); - event.getPresentation().setVisible(visibility); - } + @Override + public void update(@NotNull final AnActionEvent event) { + boolean visibility = event.getProject() != null; + event.getPresentation().setEnabled(visibility); + event.getPresentation().setVisible(visibility); + } } diff --git a/code_samples/project_view_pane/resources/META-INF/plugin.xml b/code_samples/project_view_pane/resources/META-INF/plugin.xml index 1a6ab3cd2..3356d2a0f 100644 --- a/code_samples/project_view_pane/resources/META-INF/plugin.xml +++ b/code_samples/project_view_pane/resources/META-INF/plugin.xml @@ -1,30 +1,30 @@ - org.jetbrains.plugins.sample.ProjectViewPane - Project View Pain Demo - 1.0 - JetBrains + org.jetbrains.plugins.sample.ProjectViewPane + Project View Pain Demo + 1.0 + JetBrains - Project View Pain Demo + Project View Pain Demo - Initial commit + Initial commit - - - com.intellij.modules.lang + + + com.intellij.modules.lang - - - + + + - - - + + + - - - + + + - - - + + + \ No newline at end of file diff --git a/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectNode.java b/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectNode.java index 6c44feb53..e61741aa9 100644 --- a/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectNode.java +++ b/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectNode.java @@ -26,146 +26,148 @@ import java.util.*; * @author Anna Bulenkova */ public class ImagesProjectNode extends AbstractTreeNode { - private static final Key> IMAGES_PROJECT_DIRS = Key.create("images.files.or.directories"); + private static final Key> IMAGES_PROJECT_DIRS = Key.create("images.files.or.directories"); - public ImagesProjectNode(final Project project) { - super(project, project.getBaseDir()); - scanImages(project); + public ImagesProjectNode(final Project project) { + super(project, project.getBaseDir()); + scanImages(project); - subscribeToVFS(project); + subscribeToVFS(project); + } + + public ImagesProjectNode(Project project, VirtualFile file) { + super(project, file); + } + + private void scanImages(Project project) { + addAllByExt(project, "png"); + addAllByExt(project, "jpg"); + } + + private void addAllByExt(Project project, String ext) { + final Set imagesFiles = getImagesFiles(project); + final VirtualFile projectDir = project.getBaseDir(); + for (VirtualFile file : FilenameIndex.getAllFilesByExt(project, ext)) { + while (file != null && !file.equals(projectDir)) { + imagesFiles.add(file); + file = file.getParent(); + } } + } - public ImagesProjectNode(Project project, VirtualFile file) { - super(project, file); + @NotNull + private Set getImagesFiles(Project project) { + Set files = project.getUserData(IMAGES_PROJECT_DIRS); + if (files == null) { + files = new HashSet(); + project.putUserData(IMAGES_PROJECT_DIRS, files); } + return files; + } - private void scanImages(Project project) { - addAllByExt(project, "png"); - addAllByExt(project, "jpg"); + @Override + protected VirtualFile getVirtualFile() { + return getValue(); + } + + @NotNull + @Override + public Collection getChildren() { + final List files = new ArrayList(0); + for (VirtualFile file : getValue().getChildren()) { + if (getImagesFiles(myProject).contains(file)) { + files.add(file); + } } - - private void addAllByExt(Project project, String ext) { - final Set imagesFiles = getImagesFiles(project); - final VirtualFile projectDir = project.getBaseDir(); - for (VirtualFile file : FilenameIndex.getAllFilesByExt(project, ext)) { - while (file != null && !file.equals(projectDir)) { - imagesFiles.add(file); - file = file.getParent(); - } + if (files.isEmpty()) return Collections.emptyList(); + final List nodes = new ArrayList(files.size()); + final boolean alwaysOnTop = ((ProjectViewImpl) ProjectView.getInstance(myProject)).isFoldersAlwaysOnTop(); + Collections.sort(files, new Comparator() { + @Override + public int compare(VirtualFile o1, VirtualFile o2) { + if (alwaysOnTop) { + final boolean d1 = o1.isDirectory(); + final boolean d2 = o2.isDirectory(); + if (d1 && !d2) return -1; + if (!d1 && d2) return 1; } + + return StringUtil.naturalCompare(o1.getName(), o2.getName()); + } + }); + for (VirtualFile file : files) { + nodes.add(new ImagesProjectNode(myProject, file)); } + return nodes; + } - @NotNull - private Set getImagesFiles(Project project) { - Set files = project.getUserData(IMAGES_PROJECT_DIRS); - if (files == null) { - files = new HashSet(); - project.putUserData(IMAGES_PROJECT_DIRS, files); - } - return files; - } + @Override + protected void update(PresentationData data) { + data.setIcon(getValue().isDirectory() ? AllIcons.Nodes.Folder : getValue().getFileType().getIcon()); + data.setPresentableText(getValue().getName()); + } - @Override - protected VirtualFile getVirtualFile() { - return getValue(); - } - @NotNull - @Override - public Collection getChildren() { - final List files = new ArrayList(0); - for (VirtualFile file : getValue().getChildren()) { - if (getImagesFiles(myProject).contains(file)) { - files.add(file); - } - } - if (files.isEmpty()) return Collections.emptyList(); - final List nodes = new ArrayList(files.size()); - final boolean alwaysOnTop = ((ProjectViewImpl) ProjectView.getInstance(myProject)).isFoldersAlwaysOnTop(); - Collections.sort(files, new Comparator() { - @Override - public int compare(VirtualFile o1, VirtualFile o2) { - if (alwaysOnTop) { - final boolean d1 = o1.isDirectory(); - final boolean d2 = o2.isDirectory(); - if (d1 && !d2) return -1; - if (!d1 && d2) return 1; - } + @Override + public boolean canNavigate() { + return !getValue().isDirectory(); + } - return StringUtil.naturalCompare(o1.getName(), o2.getName()); - } + @Override + public boolean canNavigateToSource() { + return canNavigate(); + } + + @Override + public void navigate(boolean requestFocus) { + FileEditorManager.getInstance(myProject).openFile(getValue(), false); + } + + private void subscribeToVFS(final Project project) { + final Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project); + LocalFileSystem.getInstance().addVirtualFileListener(new VirtualFileAdapter() { + { + final VirtualFileAdapter me = this; + Disposer.register(project, new Disposable() { + @Override + public void dispose() { + LocalFileSystem.getInstance().removeVirtualFileListener(me); + } }); - for (VirtualFile file : files) { - nodes.add(new ImagesProjectNode(myProject, file)); - } - return nodes; - } + } - @Override - protected void update(PresentationData data) { - data.setIcon(getValue().isDirectory() ? AllIcons.Nodes.Folder : getValue().getFileType().getIcon()); - data.setPresentableText(getValue().getName()); - } + @Override + public void fileCreated(@NotNull VirtualFileEvent event) { + handle(event); + } + @Override + public void fileDeleted(@NotNull VirtualFileEvent event) { + handle(event); + } - @Override - public boolean canNavigate() { - return !getValue().isDirectory(); - } - - @Override - public boolean canNavigateToSource() { - return canNavigate(); - } - - @Override - public void navigate(boolean requestFocus) { - FileEditorManager.getInstance(myProject).openFile(getValue(), false); - } - - private void subscribeToVFS(final Project project) { - final Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project); - LocalFileSystem.getInstance().addVirtualFileListener(new VirtualFileAdapter() { - { - final VirtualFileAdapter me = this; - Disposer.register(project, new Disposable() { - @Override - public void dispose() { - LocalFileSystem.getInstance().removeVirtualFileListener(me); - } - }); - } - - @Override - public void fileCreated(@NotNull VirtualFileEvent event) { - handle(event); - } - - @Override - public void fileDeleted(@NotNull VirtualFileEvent event) { - handle(event); - } - - void handle(VirtualFileEvent event) { - final String filename = event.getFileName().toLowerCase(); - if (filename.endsWith(".png") || filename.endsWith(".jpg")) { - alarm.cancelAllRequests(); - alarm.addRequest(new Runnable() { - public void run() { - getImagesFiles(project).clear(); - scanImages(project); - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - ProjectView.getInstance(myProject).getProjectViewPaneById(ImagesProjectViewPane.ID).updateFromRoot(true); - } - }); - } - }, 1000); + void handle(VirtualFileEvent event) { + final String filename = event.getFileName().toLowerCase(); + if (filename.endsWith(".png") || filename.endsWith(".jpg")) { + alarm.cancelAllRequests(); + alarm.addRequest(new Runnable() { + public void run() { + getImagesFiles(project).clear(); + scanImages(project); + //noinspection SSBasedInspection + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + ProjectView.getInstance(myProject) + .getProjectViewPaneById(ImagesProjectViewPane.ID) + .updateFromRoot(true); } + }); } - }); - } + }, 1000); + } + } + }); + } } diff --git a/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectViewPane.java b/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectViewPane.java index b95985af1..7597819c5 100644 --- a/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectViewPane.java +++ b/code_samples/project_view_pane/src/org/jetbrains/tutorials/view/pane/ImagesProjectViewPane.java @@ -22,88 +22,88 @@ import javax.swing.tree.DefaultTreeModel; * @author Anna Bulenkova */ public class ImagesProjectViewPane extends AbstractProjectViewPSIPane { - public static final String ID = "IMAGES"; + public static final String ID = "IMAGES"; - protected ImagesProjectViewPane(Project project) { - super(project); - } + protected ImagesProjectViewPane(Project project) { + super(project); + } - @Override - public String getTitle() { - return "Images"; - } + @Override + public String getTitle() { + return "Images"; + } - @Override - public javax.swing.Icon getIcon() { - return AllIcons.FileTypes.Custom; - } + @Override + public javax.swing.Icon getIcon() { + return AllIcons.FileTypes.Custom; + } - @NotNull - @Override - public String getId() { - return ID; - } + @NotNull + @Override + public String getId() { + return ID; + } - @Override - public int getWeight() { + @Override + public int getWeight() { + return 10; + } + + @Override + public SelectInTarget createSelectInTarget() { + return new ProjectViewSelectInTarget(myProject) { + + @Override + public String toString() { + return "images"; + } + + @Nullable + @Override + public String getMinorViewId() { + return "images"; + } + + @Override + public float getWeight() { return 10; - } + } + }; + } - @Override - public SelectInTarget createSelectInTarget() { - return new ProjectViewSelectInTarget(myProject) { + @Override + protected ProjectAbstractTreeStructureBase createStructure() { + return new ProjectTreeStructure(myProject, ID) { + @Override + protected AbstractTreeNode createRoot(Project project, ViewSettings settings) { + return new ImagesProjectNode(project); + } - @Override - public String toString() { - return "images"; - } + @Override + public Object[] getChildElements(Object element) { + return super.getChildElements(element); + } + }; + } - @Nullable - @Override - public String getMinorViewId() { - return "images"; - } + @Override + protected ProjectViewTree createTree(DefaultTreeModel model) { + return new ProjectViewTree(myProject, model) { + @Override + public DefaultMutableTreeNode getSelectedNode() { + return ImagesProjectViewPane.this.getSelectedNode(); + } - @Override - public float getWeight() { - return 10; - } - }; - } + @Override + public boolean isRootVisible() { + return true; + } + }; + } - @Override - protected ProjectAbstractTreeStructureBase createStructure() { - return new ProjectTreeStructure(myProject, ID) { - @Override - protected AbstractTreeNode createRoot(Project project, ViewSettings settings) { - return new ImagesProjectNode(project); - } - - @Override - public Object[] getChildElements(Object element) { - return super.getChildElements(element); - } - }; - } - - @Override - protected ProjectViewTree createTree(DefaultTreeModel model) { - return new ProjectViewTree(myProject, model) { - @Override - public DefaultMutableTreeNode getSelectedNode() { - return ImagesProjectViewPane.this.getSelectedNode(); - } - - @Override - public boolean isRootVisible() { - return true; - } - }; - } - - @Override - protected AbstractTreeUpdater createTreeUpdater(AbstractTreeBuilder builder) { - return new AbstractTreeUpdater(builder); - } + @Override + protected AbstractTreeUpdater createTreeUpdater(AbstractTreeBuilder builder) { + return new AbstractTreeUpdater(builder); + } } diff --git a/code_samples/project_wizard/resources/META-INF/plugin.xml b/code_samples/project_wizard/resources/META-INF/plugin.xml index 63ac241ac..60bc7c0b2 100644 --- a/code_samples/project_wizard/resources/META-INF/plugin.xml +++ b/code_samples/project_wizard/resources/META-INF/plugin.xml @@ -14,7 +14,9 @@ - + diff --git a/code_samples/project_wizard/src/org/jetbrains/tutorials/project/wizard/DemoModuleWizardStep.java b/code_samples/project_wizard/src/org/jetbrains/tutorials/project/wizard/DemoModuleWizardStep.java index 6fb234c78..ef1fa18ca 100644 --- a/code_samples/project_wizard/src/org/jetbrains/tutorials/project/wizard/DemoModuleWizardStep.java +++ b/code_samples/project_wizard/src/org/jetbrains/tutorials/project/wizard/DemoModuleWizardStep.java @@ -15,26 +15,27 @@ import javax.swing.*; * @author Anna Bulenkova */ public class DemoModuleWizardStep extends ModuleBuilder { - public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { + public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException { - } + } - public ModuleType getModuleType() { - return ModuleType.EMPTY; //or it could be other module type - } + public ModuleType getModuleType() { + return ModuleType.EMPTY; //or it could be other module type + } - @Override - public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull ModulesProvider modulesProvider) { - return new ModuleWizardStep[]{new ModuleWizardStep() { - @Override - public JComponent getComponent() { - return new JLabel("Put your content here"); - } + @Override + public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, + @NotNull ModulesProvider modulesProvider) { + return new ModuleWizardStep[]{new ModuleWizardStep() { + @Override + public JComponent getComponent() { + return new JLabel("Put your content here"); + } - @Override - public void updateDataModel() { + @Override + public void updateDataModel() { - } - }}; - } + } + }}; + } } diff --git a/code_samples/register_actions/resources/META-INF/plugin.xml b/code_samples/register_actions/resources/META-INF/plugin.xml index 23142be67..2cd8b4f42 100644 --- a/code_samples/register_actions/resources/META-INF/plugin.xml +++ b/code_samples/register_actions/resources/META-INF/plugin.xml @@ -2,15 +2,15 @@ org.jetbrains.plugins.sample.RegisterActions Sample plugin for working with IntelliJ Action System 1.0 - JetBrains + JetBrains - Illustration of Action System + Illustration of Action System - Initial commit + Initial commit - - - com.intellij.modules.lang + + + com.intellij.modules.lang @@ -39,45 +39,45 @@ The optional "use-shortcut-of" attribute specifies the ID of the action whose keyboard shortcut this action will use. The optional "description" attribute specifies the text which is displayed in the status bar when the action is focused. The optional "icon" attribute specifies the icon which is displayed on the toolbar button or next to the menu item. --> - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/BaseActionGroup.java b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/BaseActionGroup.java index 499e5bf72..31601df30 100644 --- a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/BaseActionGroup.java +++ b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/BaseActionGroup.java @@ -9,18 +9,20 @@ import org.jetbrains.annotations.NotNull; * @author Anna Bulenkova */ public class BaseActionGroup extends ActionGroup { - @NotNull + @NotNull + @Override + public AnAction[] getChildren(AnActionEvent anActionEvent) { + return new AnAction[]{new MyAction()}; + } + + class MyAction extends AnAction { + public MyAction() { + super("Dynamically Added Action"); + } + @Override - public AnAction[] getChildren(AnActionEvent anActionEvent) { - return new AnAction[]{new MyAction()}; - } - class MyAction extends AnAction { - public MyAction() { - super("Dynamically Added Action"); - } - @Override - public void actionPerformed(@NotNull AnActionEvent anActionEvent) { - //does nothing - } + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + //does nothing } + } } diff --git a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomDefaultActionGroup.java b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomDefaultActionGroup.java index cb24193af..56e697136 100644 --- a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomDefaultActionGroup.java +++ b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomDefaultActionGroup.java @@ -10,11 +10,11 @@ import com.intellij.openapi.editor.Editor; * @author Anna Bulenkova */ public class CustomDefaultActionGroup extends DefaultActionGroup { - @Override - public void update(AnActionEvent event) { - Editor editor = event.getData(CommonDataKeys.EDITOR); - event.getPresentation().setVisible(true); - event.getPresentation().setEnabled(editor != null); - event.getPresentation().setIcon(AllIcons.General.Error); - } + @Override + public void update(AnActionEvent event) { + Editor editor = event.getData(CommonDataKeys.EDITOR); + event.getPresentation().setVisible(true); + event.getPresentation().setEnabled(editor != null); + event.getPresentation().setIcon(AllIcons.General.Error); + } } diff --git a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomGroupedAction.java b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomGroupedAction.java index 77444a508..ca2d19099 100644 --- a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomGroupedAction.java +++ b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/CustomGroupedAction.java @@ -7,8 +7,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent; * @author Anna Bulenkova */ public class CustomGroupedAction extends AnAction { - @Override - public void actionPerformed(AnActionEvent anActionEvent) { - //Does nothing - } + @Override + public void actionPerformed(AnActionEvent anActionEvent) { + //Does nothing + } } diff --git a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/GroupedAction.java b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/GroupedAction.java index abdb9e824..3d9062cc4 100644 --- a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/GroupedAction.java +++ b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/GroupedAction.java @@ -7,13 +7,13 @@ import com.intellij.openapi.actionSystem.AnActionEvent; * @author Anna Bulenkova */ public class GroupedAction extends AnAction { - @Override - public void update(AnActionEvent event) { - event.getPresentation().setEnabledAndVisible(true); - } + @Override + public void update(AnActionEvent event) { + event.getPresentation().setEnabledAndVisible(true); + } - @Override - public void actionPerformed(AnActionEvent event) { - //Does nothing - } + @Override + public void actionPerformed(AnActionEvent event) { + //Does nothing + } } diff --git a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/SimpleAction.java b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/SimpleAction.java index 48ba91cd8..9aa4a27bc 100644 --- a/code_samples/register_actions/src/org/jetbrains/tutorials/actions/SimpleAction.java +++ b/code_samples/register_actions/src/org/jetbrains/tutorials/actions/SimpleAction.java @@ -10,20 +10,20 @@ import com.intellij.openapi.ui.Messages; * @author Anna Bulenkova */ public class SimpleAction extends AnAction { - @Override - public void actionPerformed(AnActionEvent anActionEvent) { - Object navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE); - if (navigatable != null) { - Messages.showDialog(navigatable.toString(), "Selected Element:", new String[]{"OK"}, -1, null); - } + @Override + public void actionPerformed(AnActionEvent anActionEvent) { + Object navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE); + if (navigatable != null) { + Messages.showDialog(navigatable.toString(), "Selected Element:", new String[]{"OK"}, -1, null); } + } - @Override - public void update(AnActionEvent anActionEvent) { - final Project project = anActionEvent.getData(CommonDataKeys.PROJECT); - if (project != null) - return; - Object navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE); - anActionEvent.getPresentation().setVisible(navigatable != null); - } + @Override + public void update(AnActionEvent anActionEvent) { + final Project project = anActionEvent.getData(CommonDataKeys.PROJECT); + if (project != null) + return; + Object navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE); + anActionEvent.getPresentation().setVisible(navigatable != null); + } } diff --git a/code_samples/run_configuration/resources/META-INF/plugin.xml b/code_samples/run_configuration/resources/META-INF/plugin.xml index e29508754..c715c42cf 100644 --- a/code_samples/run_configuration/resources/META-INF/plugin.xml +++ b/code_samples/run_configuration/resources/META-INF/plugin.xml @@ -1,30 +1,30 @@ - org.jetbrains.tutorials.run.configuration - Run Configuration - 1.0 - JetBrains + org.jetbrains.tutorials.run.configuration + Run Configuration + 1.0 + JetBrains - Illustration of working with run configurations + Illustration of working with run configurations - Initial commit + Initial commit - - - com.intellij.modules.lang + + + com.intellij.modules.lang - - - + + + - - - + + + - - - + + + - - + + \ No newline at end of file diff --git a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoConfigurationFactory.java b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoConfigurationFactory.java index a475e8373..4f37ec22f 100644 --- a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoConfigurationFactory.java +++ b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoConfigurationFactory.java @@ -9,19 +9,19 @@ import com.intellij.openapi.project.Project; * @author Anna Bulenkova */ public class DemoConfigurationFactory extends ConfigurationFactory { - private static final String FACTORY_NAME = "Demo configuration factory"; + private static final String FACTORY_NAME = "Demo configuration factory"; - protected DemoConfigurationFactory(ConfigurationType type) { - super(type); - } + protected DemoConfigurationFactory(ConfigurationType type) { + super(type); + } - @Override - public RunConfiguration createTemplateConfiguration(Project project) { - return new DemoRunConfiguration(project, this, "Demo"); - } + @Override + public RunConfiguration createTemplateConfiguration(Project project) { + return new DemoRunConfiguration(project, this, "Demo"); + } - @Override - public String getName() { - return FACTORY_NAME; - } + @Override + public String getName() { + return FACTORY_NAME; + } } diff --git a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfiguration.java b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfiguration.java index 1ab7c7de3..87aac481c 100644 --- a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfiguration.java +++ b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfiguration.java @@ -13,24 +13,25 @@ import org.jetbrains.annotations.Nullable; * @author Anna Bulenkova */ public class DemoRunConfiguration extends RunConfigurationBase { - protected DemoRunConfiguration(Project project, ConfigurationFactory factory, String name) { - super(project, factory, name); - } + protected DemoRunConfiguration(Project project, ConfigurationFactory factory, String name) { + super(project, factory, name); + } - @NotNull - @Override - public SettingsEditor getConfigurationEditor() { - return new DemoSettingsEditor(); - } + @NotNull + @Override + public SettingsEditor getConfigurationEditor() { + return new DemoSettingsEditor(); + } - @Override - public void checkConfiguration() throws RuntimeConfigurationException { + @Override + public void checkConfiguration() throws RuntimeConfigurationException { - } + } - @Nullable - @Override - public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws ExecutionException { - return null; - } + @Nullable + @Override + public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws + ExecutionException { + return null; + } } diff --git a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfigurationType.java b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfigurationType.java index bac651411..64897ba15 100644 --- a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfigurationType.java +++ b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoRunConfigurationType.java @@ -11,29 +11,29 @@ import javax.swing.*; * @author Anna Bulenkova */ public class DemoRunConfigurationType implements ConfigurationType { - @Override - public String getDisplayName() { - return "Demo"; - } + @Override + public String getDisplayName() { + return "Demo"; + } - @Override - public String getConfigurationTypeDescription() { - return "Demo Run Configuration Type"; - } + @Override + public String getConfigurationTypeDescription() { + return "Demo Run Configuration Type"; + } - @Override - public Icon getIcon() { - return AllIcons.General.Information; - } + @Override + public Icon getIcon() { + return AllIcons.General.Information; + } - @NotNull - @Override - public String getId() { - return "DEMO_RUN_CONFIGURATION"; - } + @NotNull + @Override + public String getId() { + return "DEMO_RUN_CONFIGURATION"; + } - @Override - public ConfigurationFactory[] getConfigurationFactories() { - return new ConfigurationFactory[]{new DemoConfigurationFactory(this)}; - } + @Override + public ConfigurationFactory[] getConfigurationFactories() { + return new ConfigurationFactory[]{new DemoConfigurationFactory(this)}; + } } diff --git a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoSettingsEditor.java b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoSettingsEditor.java index db66fec90..56120c58a 100644 --- a/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoSettingsEditor.java +++ b/code_samples/run_configuration/src/org/jetbrains/tutorials/run/configuration/DemoSettingsEditor.java @@ -17,28 +17,28 @@ import javax.swing.*; * @author Anna Bulenkova */ public class DemoSettingsEditor extends SettingsEditor { - private JPanel myPanel; - private LabeledComponent myMainClass; + private JPanel myPanel; + private LabeledComponent myMainClass; - @Override - protected void resetEditorFrom(DemoRunConfiguration demoRunConfiguration) { + @Override + protected void resetEditorFrom(DemoRunConfiguration demoRunConfiguration) { - } + } - @Override - protected void applyEditorTo(DemoRunConfiguration demoRunConfiguration) throws ConfigurationException { + @Override + protected void applyEditorTo(DemoRunConfiguration demoRunConfiguration) throws ConfigurationException { - } + } - @NotNull - @Override - protected JComponent createEditor() { - return myPanel; - } + @NotNull + @Override + protected JComponent createEditor() { + return myPanel; + } - private void createUIComponents() { - myMainClass = new LabeledComponent(); - myMainClass.setComponent(new TextFieldWithBrowseButton()); - } + private void createUIComponents() { + myMainClass = new LabeledComponent(); + myMainClass.setComponent(new TextFieldWithBrowseButton()); + } } diff --git a/code_samples/simple_language_plugin/gen/com/simpleplugin/parser/SimpleParser.java b/code_samples/simple_language_plugin/gen/com/simpleplugin/parser/SimpleParser.java index 3e28b7da7..297d6f757 100644 --- a/code_samples/simple_language_plugin/gen/com/simpleplugin/parser/SimpleParser.java +++ b/code_samples/simple_language_plugin/gen/com/simpleplugin/parser/SimpleParser.java @@ -1,15 +1,15 @@ // This is a generated file. Not intended for manual editing. package com.simpleplugin.parser; +import com.intellij.lang.ASTNode; +import com.intellij.lang.LightPsiParser; import com.intellij.lang.PsiBuilder; import com.intellij.lang.PsiBuilder.Marker; -import static com.simpleplugin.psi.SimpleTypes.*; -import static com.intellij.lang.parser.GeneratedParserUtilBase.*; -import com.intellij.psi.tree.IElementType; -import com.intellij.lang.ASTNode; -import com.intellij.psi.tree.TokenSet; import com.intellij.lang.PsiParser; -import com.intellij.lang.LightPsiParser; +import com.intellij.psi.tree.IElementType; + +import static com.intellij.lang.parser.GeneratedParserUtilBase.*; +import static com.simpleplugin.psi.SimpleTypes.*; @SuppressWarnings({"SimplifiableIfStatement", "UnusedAssignment"}) public class SimpleParser implements PsiParser, LightPsiParser { @@ -25,8 +25,7 @@ public class SimpleParser implements PsiParser, LightPsiParser { Marker m = enter_section_(b, 0, _COLLAPSE_, null); if (t == PROPERTY) { r = property(b, 0); - } - else { + } else { r = parse_root_(t, b, 0); } exit_section_(b, 0, m, t, r, true, TRUE_CONDITION); diff --git a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleProperty.java b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleProperty.java index 2ff5df042..3070e4a78 100644 --- a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleProperty.java +++ b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleProperty.java @@ -1,10 +1,8 @@ // This is a generated file. Not intended for manual editing. package com.simpleplugin.psi; -import java.util.List; -import org.jetbrains.annotations.*; -import com.intellij.psi.PsiElement; import com.intellij.navigation.ItemPresentation; +import com.intellij.psi.PsiElement; public interface SimpleProperty extends SimpleNamedElement { diff --git a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleTypes.java b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleTypes.java index 36792334c..5c7afd50e 100644 --- a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleTypes.java +++ b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleTypes.java @@ -1,10 +1,10 @@ // This is a generated file. Not intended for manual editing. package com.simpleplugin.psi; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.PsiElement; import com.intellij.lang.ASTNode; -import com.simpleplugin.psi.impl.*; +import com.intellij.psi.PsiElement; +import com.intellij.psi.tree.IElementType; +import com.simpleplugin.psi.impl.SimplePropertyImpl; public interface SimpleTypes { @@ -19,7 +19,7 @@ public interface SimpleTypes { class Factory { public static PsiElement createElement(ASTNode node) { IElementType type = node.getElementType(); - if (type == PROPERTY) { + if (type == PROPERTY) { return new SimplePropertyImpl(node); } throw new AssertionError("Unknown element type: " + type); diff --git a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleVisitor.java b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleVisitor.java index 504829968..5827d5862 100644 --- a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleVisitor.java +++ b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/SimpleVisitor.java @@ -1,9 +1,9 @@ // This is a generated file. Not intended for manual editing. package com.simpleplugin.psi; -import org.jetbrains.annotations.*; -import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import org.jetbrains.annotations.NotNull; public class SimpleVisitor extends PsiElementVisitor { diff --git a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/impl/SimplePropertyImpl.java b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/impl/SimplePropertyImpl.java index 7c0abca71..7daac4c28 100644 --- a/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/impl/SimplePropertyImpl.java +++ b/code_samples/simple_language_plugin/gen/com/simpleplugin/psi/impl/SimplePropertyImpl.java @@ -1,15 +1,13 @@ // This is a generated file. Not intended for manual editing. package com.simpleplugin.psi.impl; -import java.util.List; -import org.jetbrains.annotations.*; import com.intellij.lang.ASTNode; +import com.intellij.navigation.ItemPresentation; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.util.PsiTreeUtil; -import static com.simpleplugin.psi.SimpleTypes.*; -import com.simpleplugin.psi.*; -import com.intellij.navigation.ItemPresentation; +import com.simpleplugin.psi.SimpleProperty; +import com.simpleplugin.psi.SimpleVisitor; +import org.jetbrains.annotations.NotNull; public class SimplePropertyImpl extends SimpleNamedElementImpl implements SimpleProperty { @@ -18,7 +16,7 @@ public class SimplePropertyImpl extends SimpleNamedElementImpl implements Simple } public void accept(@NotNull PsiElementVisitor visitor) { - if (visitor instanceof SimpleVisitor) ((SimpleVisitor)visitor).visitProperty(this); + if (visitor instanceof SimpleVisitor) ((SimpleVisitor) visitor).visitProperty(this); else super.accept(visitor); } diff --git a/code_samples/simple_language_plugin/resources/META-INF/plugin.xml b/code_samples/simple_language_plugin/resources/META-INF/plugin.xml index 601bc4d54..46bbe7372 100644 --- a/code_samples/simple_language_plugin/resources/META-INF/plugin.xml +++ b/code_samples/simple_language_plugin/resources/META-INF/plugin.xml @@ -38,23 +38,25 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/CreatePropertyQuickFix.java b/code_samples/simple_language_plugin/src/com/simpleplugin/CreatePropertyQuickFix.java index add125e7d..18e53c328 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/CreatePropertyQuickFix.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/CreatePropertyQuickFix.java @@ -4,7 +4,7 @@ import com.intellij.codeInsight.intention.impl.BaseIntentionAction; import com.intellij.lang.ASTNode; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; @@ -27,73 +27,76 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; class CreatePropertyQuickFix extends BaseIntentionAction { - private String key; + private String key; - CreatePropertyQuickFix(String key) { - this.key = key; - } + CreatePropertyQuickFix(String key) { + this.key = key; + } - @NotNull - @Override - public String getText() { - return "Create property"; - } + @NotNull + @Override + public String getText() { + return "Create property"; + } - @NotNull - @Override - public String getFamilyName() { - return "Simple properties"; - } + @NotNull + @Override + public String getFamilyName() { + return "Simple properties"; + } - @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return true; - } + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + return true; + } - @Override - public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException { - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - Collection virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE, - GlobalSearchScope.allScope(project)); - if (virtualFiles.size() == 1) { - createProperty(project, virtualFiles.iterator().next()); - } else { - final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE); - descriptor.setRoots(project.getBaseDir()); - final VirtualFile file = FileChooser.chooseFile(descriptor, project, null); - if (file != null) { - createProperty(project, file); - } - } - } - }); - } + @Override + public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws + IncorrectOperationException { + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + Collection virtualFiles = + FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE, + GlobalSearchScope.allScope(project)); + if (virtualFiles.size() == 1) { + createProperty(project, virtualFiles.iterator().next()); + } else { + final FileChooserDescriptor descriptor = + FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE); + descriptor.setRoots(project.getBaseDir()); + final VirtualFile file = FileChooser.chooseFile(descriptor, project, null); + if (file != null) { + createProperty(project, file); + } + } + } + }); + } - private void createProperty(final Project project, final VirtualFile file) { - new WriteCommandAction.Simple(project) { - @Override - public void run() { - SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(file); - ASTNode lastChildNode = simpleFile.getNode().getLastChildNode(); - if (lastChildNode != null && !lastChildNode.getElementType().equals(SimpleTypes.CRLF)) { - simpleFile.getNode().addChild(SimpleElementFactory.createCRLF(project).getNode()); - } - // IMPORTANT: change spaces to escaped spaces or the new node will only have the first word for the key - SimpleProperty property = SimpleElementFactory.createProperty(project, key.replaceAll(" ", "\\\\ "), ""); - simpleFile.getNode().addChild(property.getNode()); - ((Navigatable) property.getLastChild().getNavigationElement()).navigate(true); - FileEditorManager.getInstance(project).getSelectedTextEditor().getCaretModel(). - moveCaretRelatively(2, 0, false, false, false); + private void createProperty(final Project project, final VirtualFile file) { + new WriteCommandAction.Simple(project) { + @Override + public void run() { + SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(file); + ASTNode lastChildNode = simpleFile.getNode().getLastChildNode(); + if (lastChildNode != null && !lastChildNode.getElementType().equals(SimpleTypes.CRLF)) { + simpleFile.getNode().addChild(SimpleElementFactory.createCRLF(project).getNode()); + } + // IMPORTANT: change spaces to escaped spaces or the new node will only have the first word for the key + SimpleProperty property = SimpleElementFactory.createProperty(project, key.replaceAll(" ", "\\\\ "), ""); + simpleFile.getNode().addChild(property.getNode()); + ((Navigatable) property.getLastChild().getNavigationElement()).navigate(true); + FileEditorManager.getInstance(project).getSelectedTextEditor().getCaretModel(). + moveCaretRelatively(2, 0, false, false, false); - // almost the same thing but manipulating plain text of the document instead of PSI + // almost the same thing but manipulating plain text of the document instead of PSI // FileEditorManager.getInstance(project).openFile(file, true); // final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); // final Document document = editor.getDocument(); // document.insertString(document.getTextLength(), "\n" + key.replaceAll(" ", "\\\\ ") + " = "); // editor.getCaretModel().getPrimaryCaret().moveToOffset(document.getTextLength()); - } - }.execute(); - } + } + }.execute(); + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleAnnotator.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleAnnotator.java index e0425c5cc..d459b27f2 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleAnnotator.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleAnnotator.java @@ -14,28 +14,28 @@ import org.jetbrains.annotations.NotNull; import java.util.List; public class SimpleAnnotator implements Annotator { - @Override - public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) { - if (element instanceof PsiLiteralExpression) { - PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; - String value = literalExpression.getValue() instanceof String ? (String)literalExpression.getValue() : null; + @Override + public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) { + if (element instanceof PsiLiteralExpression) { + PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; + String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; - if (value != null && value.startsWith("simple"+":")) { - Project project = element.getProject(); - String key = value.substring(7); - List properties = SimpleUtil.findProperties(project, key); - if (properties.size() == 1) { - TextRange range = new TextRange(element.getTextRange().getStartOffset() + 7, - element.getTextRange().getStartOffset() + 7); - Annotation annotation = holder.createInfoAnnotation(range, null); - annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT); - } else if (properties.size() == 0) { - TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8, - element.getTextRange().getEndOffset()); - holder.createErrorAnnotation(range, "Unresolved property"). - registerFix(new CreatePropertyQuickFix(key)); - } - } + if (value != null && value.startsWith("simple" + ":")) { + Project project = element.getProject(); + String key = value.substring(7); + List properties = SimpleUtil.findProperties(project, key); + if (properties.size() == 1) { + TextRange range = new TextRange(element.getTextRange().getStartOffset() + 7, + element.getTextRange().getStartOffset() + 7); + Annotation annotation = holder.createInfoAnnotation(range, null); + annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT); + } else if (properties.size() == 0) { + TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8, + element.getTextRange().getEndOffset()); + holder.createErrorAnnotation(range, "Unresolved property"). + registerFix(new CreatePropertyQuickFix(key)); } + } } + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleBlock.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleBlock.java index 9c1b723a0..c743183dc 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleBlock.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleBlock.java @@ -12,46 +12,46 @@ import java.util.ArrayList; import java.util.List; public class SimpleBlock extends AbstractBlock { - private SpacingBuilder spacingBuilder; + private SpacingBuilder spacingBuilder; - protected SimpleBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, - SpacingBuilder spacingBuilder) { - super(node, wrap, alignment); - this.spacingBuilder = spacingBuilder; - } + protected SimpleBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, + SpacingBuilder spacingBuilder) { + super(node, wrap, alignment); + this.spacingBuilder = spacingBuilder; + } - @Override - protected List buildChildren() { - List blocks = new ArrayList(); - ASTNode child = myNode.getFirstChildNode(); - ASTNode previousChild = null; - while (child != null) { - if (child.getElementType() != TokenType.WHITE_SPACE && - (previousChild == null || previousChild.getElementType() != SimpleTypes.CRLF || - child.getElementType() != SimpleTypes.CRLF)) { - Block block = new SimpleBlock(child, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment(), - spacingBuilder); - blocks.add(block); - } - previousChild = child; - child = child.getTreeNext(); - } - return blocks; + @Override + protected List buildChildren() { + List blocks = new ArrayList(); + ASTNode child = myNode.getFirstChildNode(); + ASTNode previousChild = null; + while (child != null) { + if (child.getElementType() != TokenType.WHITE_SPACE && + (previousChild == null || previousChild.getElementType() != SimpleTypes.CRLF || + child.getElementType() != SimpleTypes.CRLF)) { + Block block = new SimpleBlock(child, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment(), + spacingBuilder); + blocks.add(block); + } + previousChild = child; + child = child.getTreeNext(); } + return blocks; + } - @Override - public Indent getIndent() { - return Indent.getNoneIndent(); - } + @Override + public Indent getIndent() { + return Indent.getNoneIndent(); + } - @Nullable - @Override - public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { - return spacingBuilder.getSpacing(this, child1, child2); - } + @Nullable + @Override + public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { + return spacingBuilder.getSpacing(this, child1, child2); + } - @Override - public boolean isLeaf() { - return myNode.getFirstChildNode() == null; - } + @Override + public boolean isLeaf() { + return myNode.getFirstChildNode() == null; + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleChooseByNameContributor.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleChooseByNameContributor.java index 1ec9f06ed..e49539cce 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleChooseByNameContributor.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleChooseByNameContributor.java @@ -10,24 +10,24 @@ import java.util.ArrayList; import java.util.List; public class SimpleChooseByNameContributor implements ChooseByNameContributor { - @NotNull - @Override - public String[] getNames(Project project, boolean includeNonProjectItems) { - List properties = SimpleUtil.findProperties(project); - List names = new ArrayList(properties.size()); - for (SimpleProperty property : properties) { - if (property.getKey() != null && property.getKey().length() > 0) { - names.add(property.getKey()); - } - } - return names.toArray(new String[names.size()]); + @NotNull + @Override + public String[] getNames(Project project, boolean includeNonProjectItems) { + List properties = SimpleUtil.findProperties(project); + List names = new ArrayList(properties.size()); + for (SimpleProperty property : properties) { + if (property.getKey() != null && property.getKey().length() > 0) { + names.add(property.getKey()); + } } + return names.toArray(new String[names.size()]); + } - @NotNull - @Override - public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) { - // todo include non project items - List properties = SimpleUtil.findProperties(project, name); - return properties.toArray(new NavigationItem[properties.size()]); - } + @NotNull + @Override + public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) { + // todo include non project items + List properties = SimpleUtil.findProperties(project, name); + return properties.toArray(new NavigationItem[properties.size()]); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettings.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettings.java index bb62cdb4c..8a0bf9e33 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettings.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettings.java @@ -4,7 +4,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CustomCodeStyleSettings; public class SimpleCodeStyleSettings extends CustomCodeStyleSettings { - public SimpleCodeStyleSettings(CodeStyleSettings settings) { - super("SimpleCodeStyleSettings", settings); - } + public SimpleCodeStyleSettings(CodeStyleSettings settings) { + super("SimpleCodeStyleSettings", settings); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettingsProvider.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettingsProvider.java index f19dc35b8..8b8b3420a 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettingsProvider.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCodeStyleSettingsProvider.java @@ -11,37 +11,37 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class SimpleCodeStyleSettingsProvider extends CodeStyleSettingsProvider { - @Override - public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) { - return new SimpleCodeStyleSettings(settings); - } + @Override + public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) { + return new SimpleCodeStyleSettings(settings); + } - @Nullable - @Override - public String getConfigurableDisplayName() { - return "Simple"; - } + @Nullable + @Override + public String getConfigurableDisplayName() { + return "Simple"; + } - @NotNull - @Override - public Configurable createSettingsPage(CodeStyleSettings settings, CodeStyleSettings originalSettings) { - return new CodeStyleAbstractConfigurable(settings, originalSettings, "Simple") { - @Override - protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) { - return new SimpleCodeStyleMainPanel(getCurrentSettings(), settings); - } + @NotNull + @Override + public Configurable createSettingsPage(CodeStyleSettings settings, CodeStyleSettings originalSettings) { + return new CodeStyleAbstractConfigurable(settings, originalSettings, "Simple") { + @Override + protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) { + return new SimpleCodeStyleMainPanel(getCurrentSettings(), settings); + } - @Nullable - @Override - public String getHelpTopic() { - return null; - } - }; - } + @Nullable + @Override + public String getHelpTopic() { + return null; + } + }; + } - private static class SimpleCodeStyleMainPanel extends TabbedLanguageCodeStylePanel { - public SimpleCodeStyleMainPanel(CodeStyleSettings currentSettings, CodeStyleSettings settings) { - super(SimpleLanguage.INSTANCE, currentSettings, settings); - } + private static class SimpleCodeStyleMainPanel extends TabbedLanguageCodeStylePanel { + public SimpleCodeStyleMainPanel(CodeStyleSettings currentSettings, CodeStyleSettings settings) { + super(SimpleLanguage.INSTANCE, currentSettings, settings); } + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleColorSettingsPage.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleColorSettingsPage.java index 489aede15..22210f8d6 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleColorSettingsPage.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleColorSettingsPage.java @@ -12,62 +12,62 @@ import javax.swing.*; import java.util.Map; public class SimpleColorSettingsPage implements ColorSettingsPage { - private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{ - new AttributesDescriptor("Key", SimpleSyntaxHighlighter.KEY), - new AttributesDescriptor("Separator", SimpleSyntaxHighlighter.SEPARATOR), - new AttributesDescriptor("Value", SimpleSyntaxHighlighter.VALUE), - }; + private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{ + new AttributesDescriptor("Key", SimpleSyntaxHighlighter.KEY), + new AttributesDescriptor("Separator", SimpleSyntaxHighlighter.SEPARATOR), + new AttributesDescriptor("Value", SimpleSyntaxHighlighter.VALUE), + }; - @Nullable - @Override - public Icon getIcon() { - return SimpleIcons.FILE; - } + @Nullable + @Override + public Icon getIcon() { + return SimpleIcons.FILE; + } - @NotNull - @Override - public SyntaxHighlighter getHighlighter() { - return new SimpleSyntaxHighlighter(); - } + @NotNull + @Override + public SyntaxHighlighter getHighlighter() { + return new SimpleSyntaxHighlighter(); + } - @NotNull - @Override - public String getDemoText() { - return "# You are reading the \".properties\" entry.\n" + - "! The exclamation mark can also mark text as comments.\n" + - "website = http://en.wikipedia.org/\n" + - "language = English\n" + - "# The backslash below tells the application to continue reading\n" + - "# the value onto the next line.\n" + - "message = Welcome to \\\n" + - " Wikipedia!\n" + - "# Add spaces to the key\n" + - "key\\ with\\ spaces = This is the value that could be looked up with the key \"key with spaces\".\n" + - "# Unicode\n" + - "tab : \\u0009"; - } + @NotNull + @Override + public String getDemoText() { + return "# You are reading the \".properties\" entry.\n" + + "! The exclamation mark can also mark text as comments.\n" + + "website = http://en.wikipedia.org/\n" + + "language = English\n" + + "# The backslash below tells the application to continue reading\n" + + "# the value onto the next line.\n" + + "message = Welcome to \\\n" + + " Wikipedia!\n" + + "# Add spaces to the key\n" + + "key\\ with\\ spaces = This is the value that could be looked up with the key \"key with spaces\".\n" + + "# Unicode\n" + + "tab : \\u0009"; + } - @Nullable - @Override - public Map getAdditionalHighlightingTagToDescriptorMap() { - return null; - } + @Nullable + @Override + public Map getAdditionalHighlightingTagToDescriptorMap() { + return null; + } - @NotNull - @Override - public AttributesDescriptor[] getAttributeDescriptors() { - return DESCRIPTORS; - } + @NotNull + @Override + public AttributesDescriptor[] getAttributeDescriptors() { + return DESCRIPTORS; + } - @NotNull - @Override - public ColorDescriptor[] getColorDescriptors() { - return ColorDescriptor.EMPTY_ARRAY; - } + @NotNull + @Override + public ColorDescriptor[] getColorDescriptors() { + return ColorDescriptor.EMPTY_ARRAY; + } - @NotNull - @Override - public String getDisplayName() { - return "Simple"; - } + @NotNull + @Override + public String getDisplayName() { + return "Simple"; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCommenter.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCommenter.java index f9f0e24a1..4c2179547 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCommenter.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCommenter.java @@ -4,33 +4,33 @@ import com.intellij.lang.Commenter; import org.jetbrains.annotations.Nullable; public class SimpleCommenter implements Commenter { - @Nullable - @Override - public String getLineCommentPrefix() { - return "#"; - } + @Nullable + @Override + public String getLineCommentPrefix() { + return "#"; + } - @Nullable - @Override - public String getBlockCommentPrefix() { - return ""; - } + @Nullable + @Override + public String getBlockCommentPrefix() { + return ""; + } - @Nullable - @Override - public String getBlockCommentSuffix() { - return null; - } + @Nullable + @Override + public String getBlockCommentSuffix() { + return null; + } - @Nullable - @Override - public String getCommentedBlockCommentPrefix() { - return null; - } + @Nullable + @Override + public String getCommentedBlockCommentPrefix() { + return null; + } - @Nullable - @Override - public String getCommentedBlockCommentSuffix() { - return null; - } + @Nullable + @Override + public String getCommentedBlockCommentSuffix() { + return null; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCompletionContributor.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCompletionContributor.java index 1ca45e01e..e6407a9a9 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCompletionContributor.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleCompletionContributor.java @@ -8,16 +8,16 @@ import com.simpleplugin.psi.SimpleTypes; import org.jetbrains.annotations.NotNull; public class SimpleCompletionContributor extends CompletionContributor { - public SimpleCompletionContributor() { - extend(CompletionType.BASIC, - PlatformPatterns.psiElement(SimpleTypes.VALUE).withLanguage(SimpleLanguage.INSTANCE), - new CompletionProvider() { - public void addCompletions(@NotNull CompletionParameters parameters, - ProcessingContext context, - @NotNull CompletionResultSet resultSet) { - resultSet.addElement(LookupElementBuilder.create("Hello")); - } - } - ); - } + public SimpleCompletionContributor() { + extend(CompletionType.BASIC, + PlatformPatterns.psiElement(SimpleTypes.VALUE).withLanguage(SimpleLanguage.INSTANCE), + new CompletionProvider() { + public void addCompletions(@NotNull CompletionParameters parameters, + ProcessingContext context, + @NotNull CompletionResultSet resultSet) { + resultSet.addElement(LookupElementBuilder.create("Hello")); + } + } + ); + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileType.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileType.java index 3d3714b4d..5e84a5cd5 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileType.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileType.java @@ -7,33 +7,33 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; public class SimpleFileType extends LanguageFileType { - public static final SimpleFileType INSTANCE = new SimpleFileType(); + public static final SimpleFileType INSTANCE = new SimpleFileType(); - private SimpleFileType() { - super(SimpleLanguage.INSTANCE); - } + private SimpleFileType() { + super(SimpleLanguage.INSTANCE); + } - @NotNull - @Override - public String getName() { - return "Simple file"; - } + @NotNull + @Override + public String getName() { + return "Simple file"; + } - @NotNull - @Override - public String getDescription() { - return "Simple language file"; - } + @NotNull + @Override + public String getDescription() { + return "Simple language file"; + } - @NotNull - @Override - public String getDefaultExtension() { - return "simple"; - } + @NotNull + @Override + public String getDefaultExtension() { + return "simple"; + } - @Nullable - @Override - public Icon getIcon() { - return SimpleIcons.FILE; - } + @Nullable + @Override + public Icon getIcon() { + return SimpleIcons.FILE; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileTypeFactory.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileTypeFactory.java index 2a09d45be..087dce1ca 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileTypeFactory.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFileTypeFactory.java @@ -4,9 +4,9 @@ import com.intellij.openapi.fileTypes.FileTypeConsumer; import com.intellij.openapi.fileTypes.FileTypeFactory; import org.jetbrains.annotations.NotNull; -public class SimpleFileTypeFactory extends FileTypeFactory{ - @Override - public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { - fileTypeConsumer.consume(SimpleFileType.INSTANCE, "simple"); - } +public class SimpleFileTypeFactory extends FileTypeFactory { + @Override + public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { + fileTypeConsumer.consume(SimpleFileType.INSTANCE, "simple"); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFilterLexer.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFilterLexer.java index 78de00162..03ee325df 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFilterLexer.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFilterLexer.java @@ -6,14 +6,14 @@ import com.intellij.psi.impl.cache.impl.OccurrenceConsumer; import com.intellij.psi.search.UsageSearchContext; public class SimpleFilterLexer extends BaseFilterLexer { - public SimpleFilterLexer(final Lexer originalLexer, final OccurrenceConsumer table) { - super(originalLexer, table); - } + public SimpleFilterLexer(final Lexer originalLexer, final OccurrenceConsumer table) { + super(originalLexer, table); + } - @Override - public void advance() { - scanWordsInToken(UsageSearchContext.IN_COMMENTS, false, false); - advanceTodoItemCountsInToken(); - myDelegate.advance(); - } + @Override + public void advance() { + scanWordsInToken(UsageSearchContext.IN_COMMENTS, false, false); + advanceTodoItemCountsInToken(); + myDelegate.advance(); + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFindUsagesProvider.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFindUsagesProvider.java index 0d8160cab..670056e92 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFindUsagesProvider.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFindUsagesProvider.java @@ -12,51 +12,53 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class SimpleFindUsagesProvider implements FindUsagesProvider { - @Nullable - @Override - public WordsScanner getWordsScanner() { - return new DefaultWordsScanner(new SimpleLexerAdapter(), - TokenSet.create(SimpleTypes.KEY), TokenSet.create(SimpleTypes.COMMENT), TokenSet.EMPTY); - } + @Nullable + @Override + public WordsScanner getWordsScanner() { + return new DefaultWordsScanner(new SimpleLexerAdapter(), + TokenSet.create(SimpleTypes.KEY), + TokenSet.create(SimpleTypes.COMMENT), + TokenSet.EMPTY); + } - @Override - public boolean canFindUsagesFor(@NotNull PsiElement psiElement) { - return psiElement instanceof PsiNamedElement; - } + @Override + public boolean canFindUsagesFor(@NotNull PsiElement psiElement) { + return psiElement instanceof PsiNamedElement; + } - @Nullable - @Override - public String getHelpId(@NotNull PsiElement psiElement) { - return null; - } + @Nullable + @Override + public String getHelpId(@NotNull PsiElement psiElement) { + return null; + } - @NotNull - @Override - public String getType(@NotNull PsiElement element) { - if (element instanceof SimpleProperty) { - return "simple property"; - } else { - return ""; - } + @NotNull + @Override + public String getType(@NotNull PsiElement element) { + if (element instanceof SimpleProperty) { + return "simple property"; + } else { + return ""; } + } - @NotNull - @Override - public String getDescriptiveName(@NotNull PsiElement element) { - if (element instanceof SimpleProperty) { - return ((SimpleProperty) element).getKey(); - } else { - return ""; - } + @NotNull + @Override + public String getDescriptiveName(@NotNull PsiElement element) { + if (element instanceof SimpleProperty) { + return ((SimpleProperty) element).getKey(); + } else { + return ""; } + } - @NotNull - @Override - public String getNodeText(@NotNull PsiElement element, boolean useFullName) { - if (element instanceof SimpleProperty) { - return ((SimpleProperty) element).getKey() + ":" + ((SimpleProperty) element).getValue(); - } else { - return ""; - } + @NotNull + @Override + public String getNodeText(@NotNull PsiElement element, boolean useFullName) { + if (element instanceof SimpleProperty) { + return ((SimpleProperty) element).getKey() + ":" + ((SimpleProperty) element).getValue(); + } else { + return ""; } + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFoldingBuilder.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFoldingBuilder.java index 745726933..0831b7430 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFoldingBuilder.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFoldingBuilder.java @@ -19,47 +19,50 @@ import java.util.Collection; import java.util.List; public class SimpleFoldingBuilder extends FoldingBuilderEx { - @NotNull - @Override - public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { - FoldingGroup group = FoldingGroup.newGroup("simple"); + @NotNull + @Override + public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { + FoldingGroup group = FoldingGroup.newGroup("simple"); - List descriptors = new ArrayList(); - Collection literalExpressions = PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class); - for (final PsiLiteralExpression literalExpression : literalExpressions) { - String value = literalExpression.getValue() instanceof String ? (String)literalExpression.getValue() : null; + List descriptors = new ArrayList(); + Collection literalExpressions = + PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class); + for (final PsiLiteralExpression literalExpression : literalExpressions) { + String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; - if (value != null && value.startsWith("simple:")) { - Project project = literalExpression.getProject(); - String key = value.substring(7); - final List properties = SimpleUtil.findProperties(project, key); - if (properties.size() == 1) { - descriptors.add(new FoldingDescriptor(literalExpression.getNode(), - new TextRange(literalExpression.getTextRange().getStartOffset() + 1, - literalExpression.getTextRange().getEndOffset() - 1), group) { - @Nullable - @Override - public String getPlaceholderText() { - // IMPORTANT: keys can come with no values, so a test for null is needed - // IMPORTANT: Convert embedded \n to backslash n, so that the string will look like it has LF embedded in it and embedded " to escaped " - String valueOf = properties.get(0).getValue(); - return valueOf == null ? "" : valueOf.replaceAll("\n","\\n").replaceAll("\"","\\\\\""); - } - }); - } + if (value != null && value.startsWith("simple:")) { + Project project = literalExpression.getProject(); + String key = value.substring(7); + final List properties = SimpleUtil.findProperties(project, key); + if (properties.size() == 1) { + descriptors.add(new FoldingDescriptor(literalExpression.getNode(), + new TextRange(literalExpression.getTextRange().getStartOffset() + 1, + literalExpression.getTextRange().getEndOffset() - 1), + group) { + @Nullable + @Override + public String getPlaceholderText() { + // IMPORTANT: keys can come with no values, so a test for null is needed + // IMPORTANT: Convert embedded \n to backslash n, so that the string will look like it has LF embedded + // in it and embedded " to escaped " + String valueOf = properties.get(0).getValue(); + return valueOf == null ? "" : valueOf.replaceAll("\n", "\\n").replaceAll("\"", "\\\\\""); } + }); } - return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); + } } + return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); + } - @Nullable - @Override - public String getPlaceholderText(@NotNull ASTNode node) { - return "..."; - } + @Nullable + @Override + public String getPlaceholderText(@NotNull ASTNode node) { + return "..."; + } - @Override - public boolean isCollapsedByDefault(@NotNull ASTNode node) { - return true; - } + @Override + public boolean isCollapsedByDefault(@NotNull ASTNode node) { + return true; + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFormattingModelBuilder.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFormattingModelBuilder.java index b20468c77..c509934c1 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFormattingModelBuilder.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFormattingModelBuilder.java @@ -11,23 +11,30 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class SimpleFormattingModelBuilder implements FormattingModelBuilder { - @NotNull - @Override - public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { - return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), - new SimpleBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), - Alignment.createAlignment(), createSpaceBuilder(settings)), settings); - } + @NotNull + @Override + public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { + return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), + new SimpleBlock(element.getNode(), + Wrap.createWrap(WrapType.NONE, + false), + Alignment.createAlignment(), + createSpaceBuilder(settings)), + settings); + } - private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) { - return new SpacingBuilder(settings, SimpleLanguage.INSTANCE). - around(SimpleTypes.SEPARATOR).spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS). - before(SimpleTypes.PROPERTY).none(); - } + private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) { + return new SpacingBuilder(settings, SimpleLanguage.INSTANCE). + around(SimpleTypes.SEPARATOR) + .spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS) + . + before(SimpleTypes.PROPERTY) + .none(); + } - @Nullable - @Override - public TextRange getRangeAffectingIndent(PsiFile file, int offset, ASTNode elementAtOffset) { - return null; - } + @Nullable + @Override + public TextRange getRangeAffectingIndent(PsiFile file, int offset, ASTNode elementAtOffset) { + return null; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIcons.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIcons.java index 2719cf69e..f191c0ce3 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIcons.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIcons.java @@ -5,5 +5,5 @@ import com.intellij.openapi.util.IconLoader; import javax.swing.*; public class SimpleIcons { - public static final Icon FILE = IconLoader.getIcon("/com/simpleplugin/icons/jar-gray.png"); + public static final Icon FILE = IconLoader.getIcon("/com/simpleplugin/icons/jar-gray.png"); } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIdIndexer.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIdIndexer.java index bfc0a75ac..613636ed5 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIdIndexer.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleIdIndexer.java @@ -6,12 +6,12 @@ import com.intellij.psi.impl.cache.impl.id.LexerBasedIdIndexer; public class SimpleIdIndexer extends LexerBasedIdIndexer { - public static Lexer createIndexingLexer(OccurrenceConsumer consumer) { - return new SimpleFilterLexer(new SimpleLexerAdapter(), consumer); - } + public static Lexer createIndexingLexer(OccurrenceConsumer consumer) { + return new SimpleFilterLexer(new SimpleLexerAdapter(), consumer); + } - @Override - public Lexer createLexer(final OccurrenceConsumer consumer) { - return createIndexingLexer(consumer); - } + @Override + public Lexer createLexer(final OccurrenceConsumer consumer) { + return createIndexingLexer(consumer); + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguage.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguage.java index 425e59019..9ac5f23f9 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguage.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguage.java @@ -3,9 +3,9 @@ package com.simpleplugin; import com.intellij.lang.Language; public class SimpleLanguage extends Language { - public static final SimpleLanguage INSTANCE = new SimpleLanguage(); + public static final SimpleLanguage INSTANCE = new SimpleLanguage(); - private SimpleLanguage() { - super("Simple"); - } + private SimpleLanguage() { + super("Simple"); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguageCodeStyleSettingsProvider.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguageCodeStyleSettingsProvider.java index 5df02eb89..a8e9e811d 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguageCodeStyleSettingsProvider.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLanguageCodeStyleSettingsProvider.java @@ -6,38 +6,38 @@ import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider; import org.jetbrains.annotations.NotNull; public class SimpleLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider { - @NotNull - @Override - public Language getLanguage() { - return SimpleLanguage.INSTANCE; - } + @NotNull + @Override + public Language getLanguage() { + return SimpleLanguage.INSTANCE; + } - @Override - public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @NotNull SettingsType settingsType) { - if (settingsType == SettingsType.SPACING_SETTINGS) { - consumer.showStandardOptions("SPACE_AROUND_ASSIGNMENT_OPERATORS"); - consumer.renameStandardOption("SPACE_AROUND_ASSIGNMENT_OPERATORS", "Separator"); - } else if (settingsType == SettingsType.BLANK_LINES_SETTINGS) { - consumer.showStandardOptions("KEEP_BLANK_LINES_IN_CODE"); - } + @Override + public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @NotNull SettingsType settingsType) { + if (settingsType == SettingsType.SPACING_SETTINGS) { + consumer.showStandardOptions("SPACE_AROUND_ASSIGNMENT_OPERATORS"); + consumer.renameStandardOption("SPACE_AROUND_ASSIGNMENT_OPERATORS", "Separator"); + } else if (settingsType == SettingsType.BLANK_LINES_SETTINGS) { + consumer.showStandardOptions("KEEP_BLANK_LINES_IN_CODE"); } + } - @Override - public String getCodeSample(@NotNull SettingsType settingsType) { - return "# You are reading the \".properties\" entry.\n" + - "! The exclamation mark can also mark text as comments.\n" + - "website = http://en.wikipedia.org/\n" + - "\n" + - "\n" + - "\n" + - "language = English\n" + - "# The backslash below tells the application to continue reading\n" + - "# the value onto the next line.\n" + - "message = Welcome to \\\n" + - " Wikipedia!\n" + - "# Add spaces to the key\n" + - "key\\ with\\ spaces = This is the value that could be looked up with the key \"key with spaces\".\n" + - "# Unicode\n" + - "tab : \\u0009"; - } + @Override + public String getCodeSample(@NotNull SettingsType settingsType) { + return "# You are reading the \".properties\" entry.\n" + + "! The exclamation mark can also mark text as comments.\n" + + "website = http://en.wikipedia.org/\n" + + "\n" + + "\n" + + "\n" + + "language = English\n" + + "# The backslash below tells the application to continue reading\n" + + "# the value onto the next line.\n" + + "message = Welcome to \\\n" + + " Wikipedia!\n" + + "# Add spaces to the key\n" + + "key\\ with\\ spaces = This is the value that could be looked up with the key \"key with spaces\".\n" + + "# Unicode\n" + + "tab : \\u0009"; + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexer.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexer.java index b18e92e45..fd66560c5 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexer.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexer.java @@ -3,64 +3,68 @@ package com.simpleplugin; import com.intellij.lexer.FlexLexer; +import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; import com.simpleplugin.psi.SimpleTypes; -import com.intellij.psi.TokenType; /** - * This class is a scanner generated by + * This class is a scanner generated by * JFlex 1.4.3 * on 02/09/15 10:04 AM from the specification file * /Users/vlad/src/SimplePlugin/src/com/simpleplugin/Simple.flex */ class SimpleLexer implements FlexLexer { - /** initial size of the lookahead buffer */ + /** + * initial size of the lookahead buffer + */ private static final int ZZ_BUFFERSIZE = 16384; - /** lexical states */ + /** + * lexical states + */ public static final int WAITING_VALUE = 2; public static final int YYINITIAL = 0; /** * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l - * at the beginning of a line + * at the beginning of a line * l is of the form l = 2*k, k a non negative integer */ - private static final int ZZ_LEXSTATE[] = { - 0, 0, 1, 1 + private static final int ZZ_LEXSTATE[] = { + 0, 0, 1, 1 }; - /** + /** * Translates characters to character classes */ - private static final String ZZ_CMAP_PACKED = - "\11\0\1\3\1\1\1\0\1\6\1\2\22\0\1\5\1\7\1\0"+ - "\1\7\26\0\1\10\2\0\1\10\36\0\1\4\uffa3\0"; + private static final String ZZ_CMAP_PACKED = + "\11\0\1\3\1\1\1\0\1\6\1\2\22\0\1\5\1\7\1\0" + + "\1\7\26\0\1\10\2\0\1\10\36\0\1\4\uffa3\0"; - /** + /** * Translates characters to character classes */ - private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); + private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); - /** + /** * Translates DFA states to action switch labels. */ - private static final int [] ZZ_ACTION = zzUnpackAction(); + private static final int[] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = - "\2\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7"+ - "\1\3\1\7\2\0\1\6"; + "\2\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7" + + "\1\3\1\7\2\0\1\6"; - private static int [] zzUnpackAction() { - int [] result = new int[14]; + private static int[] zzUnpackAction() { + int[] result = new int[14]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; } - private static int zzUnpackAction(String packed, int offset, int [] result) { + private static int zzUnpackAction(String packed, int offset, int[] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); @@ -73,23 +77,23 @@ class SimpleLexer implements FlexLexer { } - /** + /** * Translates a state to a row index in the transition table */ - private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); + private static final int[] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = - "\0\0\0\11\0\22\0\33\0\44\0\55\0\66\0\77"+ - "\0\110\0\121\0\132\0\44\0\121\0\143"; + "\0\0\0\11\0\22\0\33\0\44\0\55\0\66\0\77" + + "\0\110\0\121\0\132\0\44\0\121\0\143"; - private static int [] zzUnpackRowMap() { - int [] result = new int[14]; + private static int[] zzUnpackRowMap() { + int[] result = new int[14]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; } - private static int zzUnpackRowMap(String packed, int offset, int [] result) { + private static int zzUnpackRowMap(String packed, int offset, int[] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); @@ -100,28 +104,28 @@ class SimpleLexer implements FlexLexer { return j; } - /** + /** * The transition table of the DFA */ - private static final int [] ZZ_TRANS = zzUnpackTrans(); + private static final int[] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = - "\1\3\3\4\1\5\2\4\1\6\1\7\1\10\2\4"+ - "\1\11\1\12\2\13\2\10\1\3\3\0\1\14\2\0"+ - "\1\3\2\0\3\4\1\0\2\4\7\0\1\3\3\0"+ - "\1\6\2\0\6\6\11\0\1\10\2\0\1\10\1\15"+ - "\1\10\1\0\3\10\2\4\1\11\1\15\1\11\1\13"+ - "\4\10\1\16\6\10\1\0\2\4\1\13\1\0\2\13"+ - "\2\0\2\10\1\0\1\10\1\15\1\10\1\0\2\10"; + "\1\3\3\4\1\5\2\4\1\6\1\7\1\10\2\4" + + "\1\11\1\12\2\13\2\10\1\3\3\0\1\14\2\0" + + "\1\3\2\0\3\4\1\0\2\4\7\0\1\3\3\0" + + "\1\6\2\0\6\6\11\0\1\10\2\0\1\10\1\15" + + "\1\10\1\0\3\10\2\4\1\11\1\15\1\11\1\13" + + "\4\10\1\16\6\10\1\0\2\4\1\13\1\0\2\13" + + "\2\0\2\10\1\0\1\10\1\15\1\10\1\0\2\10"; - private static int [] zzUnpackTrans() { - int [] result = new int[108]; + private static int[] zzUnpackTrans() { + int[] result = new int[108]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; } - private static int zzUnpackTrans(String packed, int offset, int [] result) { + private static int zzUnpackTrans(String packed, int offset, int[] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); @@ -145,27 +149,27 @@ class SimpleLexer implements FlexLexer { /* error messages for the codes above */ private static final String ZZ_ERROR_MSG[] = { - "Unkown internal scanner error", - "Error: could not match input", - "Error: pushback value was too large" + "Unkown internal scanner error", + "Error: could not match input", + "Error: pushback value was too large" }; /** * ZZ_ATTRIBUTE[aState] contains the attributes of state aState */ - private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); + private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = - "\2\0\4\1\1\11\4\1\2\0\1\1"; + "\2\0\4\1\1\11\4\1\2\0\1\1"; - private static int [] zzUnpackAttribute() { - int [] result = new int[14]; + private static int[] zzUnpackAttribute() { + int[] result = new int[14]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; } - private static int zzUnpackAttribute(String packed, int offset, int [] result) { + private static int zzUnpackAttribute(String packed, int offset, int[] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); @@ -177,33 +181,51 @@ class SimpleLexer implements FlexLexer { return j; } - /** the current state of the DFA */ + /** + * the current state of the DFA + */ private int zzState; - /** the current lexical state */ + /** + * the current lexical state + */ private int zzLexicalState = YYINITIAL; - /** this buffer contains the current text to be matched and is - the source of the yytext() string */ + /** + * this buffer contains the current text to be matched and is + * the source of the yytext() string + */ private CharSequence zzBuffer = ""; - /** this buffer may contains the current text array to be matched when it is cheap to acquire it */ + /** + * this buffer may contains the current text array to be matched when it is cheap to acquire it + */ private char[] zzBufferArray; - /** the textposition at the last accepting state */ + /** + * the textposition at the last accepting state + */ private int zzMarkedPos; - /** the textposition at the last state to be included in yytext */ + /** + * the textposition at the last state to be included in yytext + */ private int zzPushbackPos; - /** the current text position in the buffer */ + /** + * the current text position in the buffer + */ private int zzCurrentPos; - /** startRead marks the beginning of the yytext() string in the buffer */ + /** + * startRead marks the beginning of the yytext() string in the buffer + */ private int zzStartRead; - /** endRead marks the last character in the buffer, that has been read - from input */ + /** + * endRead marks the last character in the buffer, that has been read + * from input + */ private int zzEndRead; /** @@ -211,10 +233,14 @@ class SimpleLexer implements FlexLexer { */ private boolean zzAtBOL = true; - /** zzAtEOF == true <=> the scanner is at the EOF */ + /** + * zzAtEOF == true <=> the scanner is at the EOF + */ private boolean zzAtEOF; - /** denotes if the user-EOF-code has already been executed */ + /** + * denotes if the user-EOF-code has already been executed + */ private boolean zzEOFDone; @@ -226,44 +252,44 @@ class SimpleLexer implements FlexLexer { * Creates a new scanner. * There is also java.io.Reader version of this constructor. * - * @param in the java.io.Inputstream to read input from. + * @param in the java.io.Inputstream to read input from. */ SimpleLexer(java.io.InputStream in) { this(new java.io.InputStreamReader(in)); } - /** + /** * Unpacks the compressed character translation table. * - * @param packed the packed character translation table - * @return the unpacked character translation table + * @param packed the packed character translation table + * @return the unpacked character translation table */ - private static char [] zzUnpackCMap(String packed) { - char [] map = new char[0x10000]; + private static char[] zzUnpackCMap(String packed) { + char[] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < 36) { - int count = packed.charAt(i++); + int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } return map; } - public final int getTokenStart(){ + public final int getTokenStart() { return zzStartRead; } - public final int getTokenEnd(){ + public final int getTokenEnd() { return getTokenStart() + yylength(); } - public void reset(CharSequence buffer, int start, int end,int initialState){ + public void reset(CharSequence buffer, int start, int end, int initialState) { zzBuffer = buffer; zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer); zzCurrentPos = zzMarkedPos = zzStartRead = start; zzPushbackPos = 0; - zzAtEOF = false; + zzAtEOF = false; zzAtBOL = true; zzEndRead = end; yybegin(initialState); @@ -272,9 +298,8 @@ class SimpleLexer implements FlexLexer { /** * Refills the input buffer. * - * @return false, iff there was new input. - * - * @exception java.io.IOException if any I/O-Error occurs + * @return false, iff there was new input. + * @throws java.io.IOException if any I/O-Error occurs */ private boolean zzRefill() throws java.io.IOException { return true; @@ -310,16 +335,15 @@ class SimpleLexer implements FlexLexer { /** * Returns the character at position pos from the * matched text. - * + *

* It is equivalent to yytext().charAt(pos), but faster * * @param pos the position of the character to fetch. * A value from 0 to yylength()-1. - * * @return the character at position pos */ public final char yycharat(int pos) { - return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos); + return zzBufferArray != null ? zzBufferArray[zzStartRead + pos] : zzBuffer.charAt(zzStartRead + pos); } @@ -327,30 +351,29 @@ class SimpleLexer implements FlexLexer { * Returns the length of the matched text region. */ public final int yylength() { - return zzMarkedPos-zzStartRead; + return zzMarkedPos - zzStartRead; } /** * Reports an error that occured while scanning. - * + *

* In a wellformed scanner (no or only correct usage of * yypushback(int) and a match-all fallback rule) this method * will only be called with things that "Can't Possibly Happen". * If this method is called, something is seriously wrong * (e.g. a JFlex bug producing a faulty scanner etc.). - * + *

* Usual syntax/scanner level error handling should be done * in error fallback rules. * - * @param errorCode the code of the errormessage to display + * @param errorCode the code of the errormessage to display */ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; - } - catch (ArrayIndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } @@ -360,14 +383,14 @@ class SimpleLexer implements FlexLexer { /** * Pushes the specified amount of characters back into the input stream. - * + *

* They will be read again by then next call of the scanning method * - * @param number the number of characters to be read again. - * This number must not be greater than yylength()! + * @param number the number of characters to be read again. + * This number must not be greater than yylength()! */ - public void yypushback(int number) { - if ( number > yylength() ) + public void yypushback(int number) { + if (number > yylength()) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; @@ -381,7 +404,7 @@ class SimpleLexer implements FlexLexer { private void zzDoEOF() { if (!zzEOFDone) { zzEOFDone = true; - + } } @@ -390,8 +413,8 @@ class SimpleLexer implements FlexLexer { * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * - * @return the next token - * @exception java.io.IOException if any I/O-Error occurs + * @return the next token + * @throws java.io.IOException if any I/O-Error occurs */ public IElementType advance() throws java.io.IOException { int zzInput; @@ -403,11 +426,11 @@ class SimpleLexer implements FlexLexer { int zzEndReadL = zzEndRead; CharSequence zzBufferL = zzBuffer; char[] zzBufferArrayL = zzBufferArray; - char [] zzCMapL = ZZ_CMAP; + char[] zzCMapL = ZZ_CMAP; - int [] zzTransL = ZZ_TRANS; - int [] zzRowMapL = ZZ_ROWMAP; - int [] zzAttrL = ZZ_ATTRIBUTE; + int[] zzTransL = ZZ_TRANS; + int[] zzRowMapL = ZZ_ROWMAP; + int[] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; @@ -419,7 +442,8 @@ class SimpleLexer implements FlexLexer { zzState = ZZ_LEXSTATE[zzLexicalState]; - zzForAction: { + zzForAction: + { while (true) { if (zzCurrentPosL < zzEndReadL) @@ -427,34 +451,32 @@ class SimpleLexer implements FlexLexer { else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; - } - else { + } else { // store back cached positions - zzCurrentPos = zzCurrentPosL; - zzMarkedPos = zzMarkedPosL; + zzCurrentPos = zzCurrentPosL; + zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer - zzCurrentPosL = zzCurrentPos; - zzMarkedPosL = zzMarkedPos; - zzBufferL = zzBuffer; - zzEndReadL = zzEndRead; + zzCurrentPosL = zzCurrentPos; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; - } - else { + } else { zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) break zzForAction; zzState = zzNext; int zzAttributes = zzAttrL[zzState]; - if ( (zzAttributes & 1) == 1 ) { + if ((zzAttributes & 1) == 1) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; - if ( (zzAttributes & 8) == 8 ) break zzForAction; + if ((zzAttributes & 8) == 8) break zzForAction; } } @@ -464,41 +486,53 @@ class SimpleLexer implements FlexLexer { zzMarkedPos = zzMarkedPosL; switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { - case 6: - { yybegin(YYINITIAL); return SimpleTypes.VALUE; - } - case 8: break; - case 5: - { yybegin(WAITING_VALUE); return SimpleTypes.SEPARATOR; - } - case 9: break; - case 4: - { yybegin(YYINITIAL); return SimpleTypes.COMMENT; - } - case 10: break; - case 3: - { return TokenType.BAD_CHARACTER; - } - case 11: break; - case 2: - { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; - } - case 12: break; - case 7: - { yybegin(WAITING_VALUE); return TokenType.WHITE_SPACE; - } - case 13: break; - case 1: - { yybegin(YYINITIAL); return SimpleTypes.KEY; - } - case 14: break; + case 6: { + yybegin(YYINITIAL); + return SimpleTypes.VALUE; + } + case 8: + break; + case 5: { + yybegin(WAITING_VALUE); + return SimpleTypes.SEPARATOR; + } + case 9: + break; + case 4: { + yybegin(YYINITIAL); + return SimpleTypes.COMMENT; + } + case 10: + break; + case 3: { + return TokenType.BAD_CHARACTER; + } + case 11: + break; + case 2: { + yybegin(YYINITIAL); + return TokenType.WHITE_SPACE; + } + case 12: + break; + case 7: { + yybegin(WAITING_VALUE); + return TokenType.WHITE_SPACE; + } + case 13: + break; + case 1: { + yybegin(YYINITIAL); + return SimpleTypes.KEY; + } + case 14: + break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; zzDoEOF(); return null; - } - else { + } else { zzScanError(ZZ_NO_MATCH); } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexerAdapter.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexerAdapter.java index 662acb59a..40c89a0d5 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexerAdapter.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLexerAdapter.java @@ -5,7 +5,7 @@ import com.intellij.lexer.FlexAdapter; import java.io.Reader; public class SimpleLexerAdapter extends FlexAdapter { - public SimpleLexerAdapter() { - super(new SimpleLexer((Reader) null)); - } + public SimpleLexerAdapter() { + super(new SimpleLexer((Reader) null)); + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLineMarkerProvider.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLineMarkerProvider.java index d6dc43d96..07b9e08b7 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLineMarkerProvider.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleLineMarkerProvider.java @@ -13,22 +13,23 @@ import java.util.Collection; import java.util.List; public class SimpleLineMarkerProvider extends RelatedItemLineMarkerProvider { - @Override - protected void collectNavigationMarkers(@NotNull PsiElement element, Collection result) { - if (element instanceof PsiLiteralExpression) { - PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; - String value = literalExpression.getValue() instanceof String ? (String)literalExpression.getValue() : null; - if (value != null && value.startsWith("simple"+":")) { - Project project = element.getProject(); - final List properties = SimpleUtil.findProperties(project, value.substring(7)); - if (properties.size() > 0) { - NavigationGutterIconBuilder builder = - NavigationGutterIconBuilder.create(SimpleIcons.FILE). - setTargets(properties). - setTooltipText("Navigate to a simple property"); - result.add(builder.createLineMarkerInfo(element)); - } - } + @Override + protected void collectNavigationMarkers(@NotNull PsiElement element, + Collection result) { + if (element instanceof PsiLiteralExpression) { + PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; + String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; + if (value != null && value.startsWith("simple" + ":")) { + Project project = element.getProject(); + final List properties = SimpleUtil.findProperties(project, value.substring(7)); + if (properties.size() > 0) { + NavigationGutterIconBuilder builder = + NavigationGutterIconBuilder.create(SimpleIcons.FILE). + setTargets(properties). + setTooltipText("Navigate to a simple property"); + result.add(builder.createLineMarkerInfo(element)); } + } } + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleParserDefinition.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleParserDefinition.java index c9de1df95..4d56eeeda 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleParserDefinition.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleParserDefinition.java @@ -17,53 +17,54 @@ import com.simpleplugin.psi.SimpleFile; import com.simpleplugin.psi.SimpleTypes; import org.jetbrains.annotations.NotNull; -public class SimpleParserDefinition implements ParserDefinition{ - public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE); - public static final TokenSet COMMENTS = TokenSet.create(SimpleTypes.COMMENT); +public class SimpleParserDefinition implements ParserDefinition { + public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE); + public static final TokenSet COMMENTS = TokenSet.create(SimpleTypes.COMMENT); - public static final IFileElementType FILE = new IFileElementType(Language.findInstance(SimpleLanguage.class)); + public static final IFileElementType FILE = + new IFileElementType(Language.findInstance(SimpleLanguage.class)); - @NotNull - @Override - public Lexer createLexer(Project project) { - return new SimpleLexerAdapter(); - } + @NotNull + @Override + public Lexer createLexer(Project project) { + return new SimpleLexerAdapter(); + } - @NotNull - public TokenSet getWhitespaceTokens() { - return WHITE_SPACES; - } + @NotNull + public TokenSet getWhitespaceTokens() { + return WHITE_SPACES; + } - @NotNull - public TokenSet getCommentTokens() { - return COMMENTS; - } + @NotNull + public TokenSet getCommentTokens() { + return COMMENTS; + } - @NotNull - public TokenSet getStringLiteralElements() { - return TokenSet.EMPTY; - } + @NotNull + public TokenSet getStringLiteralElements() { + return TokenSet.EMPTY; + } - @NotNull - public PsiParser createParser(final Project project) { - return new SimpleParser(); - } + @NotNull + public PsiParser createParser(final Project project) { + return new SimpleParser(); + } - @Override - public IFileElementType getFileNodeType() { - return FILE; - } + @Override + public IFileElementType getFileNodeType() { + return FILE; + } - public PsiFile createFile(FileViewProvider viewProvider) { - return new SimpleFile(viewProvider); - } + public PsiFile createFile(FileViewProvider viewProvider) { + return new SimpleFile(viewProvider); + } - public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { - return SpaceRequirements.MAY; - } + public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { + return SpaceRequirements.MAY; + } - @NotNull - public PsiElement createElement(ASTNode node) { - return SimpleTypes.Factory.createElement(node); - } + @NotNull + public PsiElement createElement(ASTNode node) { + return SimpleTypes.Factory.createElement(node); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleRefactoringSupportProvider.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleRefactoringSupportProvider.java index 8040801d7..a538c7c54 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleRefactoringSupportProvider.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleRefactoringSupportProvider.java @@ -5,8 +5,8 @@ import com.intellij.psi.PsiElement; import com.simpleplugin.psi.SimpleProperty; public class SimpleRefactoringSupportProvider extends RefactoringSupportProvider { - @Override - public boolean isMemberInplaceRenameAvailable(PsiElement element, PsiElement context) { - return element instanceof SimpleProperty; - } + @Override + public boolean isMemberInplaceRenameAvailable(PsiElement element, PsiElement context) { + return element instanceof SimpleProperty; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReference.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReference.java index cbb9b295d..6290c5a21 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReference.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReference.java @@ -13,46 +13,46 @@ import java.util.ArrayList; import java.util.List; public class SimpleReference extends PsiReferenceBase implements PsiPolyVariantReference { - private String key; + private String key; - public SimpleReference(@NotNull PsiElement element, TextRange textRange) { - super(element, textRange); - key = element.getText().substring(textRange.getStartOffset(), textRange.getEndOffset()); - } + public SimpleReference(@NotNull PsiElement element, TextRange textRange) { + super(element, textRange); + key = element.getText().substring(textRange.getStartOffset(), textRange.getEndOffset()); + } - @NotNull - @Override - public ResolveResult[] multiResolve(boolean incompleteCode) { - Project project = myElement.getProject(); - final List properties = SimpleUtil.findProperties(project, key); - List results = new ArrayList(); - for (SimpleProperty property : properties) { - results.add(new PsiElementResolveResult(property)); - } - return results.toArray(new ResolveResult[results.size()]); + @NotNull + @Override + public ResolveResult[] multiResolve(boolean incompleteCode) { + Project project = myElement.getProject(); + final List properties = SimpleUtil.findProperties(project, key); + List results = new ArrayList(); + for (SimpleProperty property : properties) { + results.add(new PsiElementResolveResult(property)); } + return results.toArray(new ResolveResult[results.size()]); + } - @Nullable - @Override - public PsiElement resolve() { - ResolveResult[] resolveResults = multiResolve(false); - return resolveResults.length == 1 ? resolveResults[0].getElement() : null; - } + @Nullable + @Override + public PsiElement resolve() { + ResolveResult[] resolveResults = multiResolve(false); + return resolveResults.length == 1 ? resolveResults[0].getElement() : null; + } - @NotNull - @Override - public Object[] getVariants() { - Project project = myElement.getProject(); - List properties = SimpleUtil.findProperties(project); - List variants = new ArrayList(); - for (final SimpleProperty property : properties) { - if (property.getKey() != null && property.getKey().length() > 0) { - variants.add(LookupElementBuilder.create(property). - withIcon(SimpleIcons.FILE). - withTypeText(property.getContainingFile().getName()) - ); - } - } - return variants.toArray(); + @NotNull + @Override + public Object[] getVariants() { + Project project = myElement.getProject(); + List properties = SimpleUtil.findProperties(project); + List variants = new ArrayList(); + for (final SimpleProperty property : properties) { + if (property.getKey() != null && property.getKey().length() > 0) { + variants.add(LookupElementBuilder.create(property). + withIcon(SimpleIcons.FILE). + withTypeText(property.getContainingFile().getName()) + ); + } } + return variants.toArray(); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReferenceContributor.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReferenceContributor.java index 99806e74f..7d234422b 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReferenceContributor.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleReferenceContributor.java @@ -7,20 +7,24 @@ import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; public class SimpleReferenceContributor extends PsiReferenceContributor { - @Override - public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { - registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), - new PsiReferenceProvider() { - @NotNull - @Override - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { - PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; - String value = literalExpression.getValue() instanceof String ? (String)literalExpression.getValue() : null; - if (value != null && value.startsWith("simple"+":")) { - return new PsiReference[]{new SimpleReference(element, new TextRange(8, value.length() + 1))}; - } - return PsiReference.EMPTY_ARRAY; - } - }); - } + @Override + public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { + registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), + new PsiReferenceProvider() { + @NotNull + @Override + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, + @NotNull ProcessingContext + context) { + PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; + String value = literalExpression.getValue() instanceof String ? + (String) literalExpression.getValue() : null; + if (value != null && value.startsWith("simple" + ":")) { + return new PsiReference[]{ + new SimpleReference(element, new TextRange(8, value.length() + 1))}; + } + return PsiReference.EMPTY_ARRAY; + } + }); + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewElement.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewElement.java index 29ba22956..065b1f09b 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewElement.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewElement.java @@ -15,58 +15,58 @@ import java.util.ArrayList; import java.util.List; public class SimpleStructureViewElement implements StructureViewTreeElement, SortableTreeElement { - private PsiElement element; + private PsiElement element; - public SimpleStructureViewElement(PsiElement element) { - this.element = element; - } + public SimpleStructureViewElement(PsiElement element) { + this.element = element; + } - @Override - public Object getValue() { - return element; - } + @Override + public Object getValue() { + return element; + } - @Override - public void navigate(boolean requestFocus) { - if (element instanceof NavigationItem) { - ((NavigationItem) element).navigate(requestFocus); - } + @Override + public void navigate(boolean requestFocus) { + if (element instanceof NavigationItem) { + ((NavigationItem) element).navigate(requestFocus); } + } - @Override - public boolean canNavigate() { - return element instanceof NavigationItem && - ((NavigationItem)element).canNavigate(); - } + @Override + public boolean canNavigate() { + return element instanceof NavigationItem && + ((NavigationItem) element).canNavigate(); + } - @Override - public boolean canNavigateToSource() { - return element instanceof NavigationItem && - ((NavigationItem)element).canNavigateToSource(); - } + @Override + public boolean canNavigateToSource() { + return element instanceof NavigationItem && + ((NavigationItem) element).canNavigateToSource(); + } - @Override - public String getAlphaSortKey() { - return element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : null; - } + @Override + public String getAlphaSortKey() { + return element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : null; + } - @Override - public ItemPresentation getPresentation() { - return element instanceof NavigationItem ? - ((NavigationItem) element).getPresentation() : null; - } + @Override + public ItemPresentation getPresentation() { + return element instanceof NavigationItem ? + ((NavigationItem) element).getPresentation() : null; + } - @Override - public TreeElement[] getChildren() { - if (element instanceof SimpleFile) { - SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(element, SimpleProperty.class); - List treeElements = new ArrayList(properties.length); - for (SimpleProperty property : properties) { - treeElements.add(new SimpleStructureViewElement(property)); - } - return treeElements.toArray(new TreeElement[treeElements.size()]); - } else { - return EMPTY_ARRAY; - } + @Override + public TreeElement[] getChildren() { + if (element instanceof SimpleFile) { + SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(element, SimpleProperty.class); + List treeElements = new ArrayList(properties.length); + for (SimpleProperty property : properties) { + treeElements.add(new SimpleStructureViewElement(property)); + } + return treeElements.toArray(new TreeElement[treeElements.size()]); + } else { + return EMPTY_ARRAY; } + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewFactory.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewFactory.java index 937fe85a6..16323e9b4 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewFactory.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewFactory.java @@ -10,15 +10,15 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class SimpleStructureViewFactory implements PsiStructureViewFactory { - @Nullable - @Override - public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) { - return new TreeBasedStructureViewBuilder() { - @NotNull - @Override - public StructureViewModel createStructureViewModel(@Nullable Editor editor) { - return new SimpleStructureViewModel(psiFile); - } - }; - } + @Nullable + @Override + public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) { + return new TreeBasedStructureViewBuilder() { + @NotNull + @Override + public StructureViewModel createStructureViewModel(@Nullable Editor editor) { + return new SimpleStructureViewModel(psiFile); + } + }; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewModel.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewModel.java index 3d2318087..db53751c6 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewModel.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleStructureViewModel.java @@ -9,24 +9,24 @@ import com.simpleplugin.psi.SimpleFile; import org.jetbrains.annotations.NotNull; public class SimpleStructureViewModel extends StructureViewModelBase implements - StructureViewModel.ElementInfoProvider { - public SimpleStructureViewModel(PsiFile psiFile) { - super(psiFile, new SimpleStructureViewElement(psiFile)); - } + StructureViewModel.ElementInfoProvider { + public SimpleStructureViewModel(PsiFile psiFile) { + super(psiFile, new SimpleStructureViewElement(psiFile)); + } - @NotNull - public Sorter[] getSorters() { - return new Sorter[] {Sorter.ALPHA_SORTER}; - } + @NotNull + public Sorter[] getSorters() { + return new Sorter[]{Sorter.ALPHA_SORTER}; + } - @Override - public boolean isAlwaysShowsPlus(StructureViewTreeElement element) { - return false; - } + @Override + public boolean isAlwaysShowsPlus(StructureViewTreeElement element) { + return false; + } - @Override - public boolean isAlwaysLeaf(StructureViewTreeElement element) { - return element instanceof SimpleFile; - } + @Override + public boolean isAlwaysLeaf(StructureViewTreeElement element) { + return element instanceof SimpleFile; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighter.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighter.java index 530581d58..a65f43e0e 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighter.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighter.java @@ -13,40 +13,45 @@ import org.jetbrains.annotations.NotNull; import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; public class SimpleSyntaxHighlighter extends SyntaxHighlighterBase { - public static final TextAttributesKey SEPARATOR = createTextAttributesKey("SIMPLE_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN); - public static final TextAttributesKey KEY = createTextAttributesKey("SIMPLE_KEY", DefaultLanguageHighlighterColors.KEYWORD); - public static final TextAttributesKey VALUE = createTextAttributesKey("SIMPLE_VALUE", DefaultLanguageHighlighterColors.STRING); - public static final TextAttributesKey COMMENT = createTextAttributesKey("SIMPLE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT); - public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("SIMPLE_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER); + public static final TextAttributesKey SEPARATOR = + createTextAttributesKey("SIMPLE_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN); + public static final TextAttributesKey KEY = + createTextAttributesKey("SIMPLE_KEY", DefaultLanguageHighlighterColors.KEYWORD); + public static final TextAttributesKey VALUE = + createTextAttributesKey("SIMPLE_VALUE", DefaultLanguageHighlighterColors.STRING); + public static final TextAttributesKey COMMENT = + createTextAttributesKey("SIMPLE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT); + public static final TextAttributesKey BAD_CHARACTER = + createTextAttributesKey("SIMPLE_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER); - private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER}; - private static final TextAttributesKey[] SEPARATOR_KEYS = new TextAttributesKey[]{SEPARATOR}; - private static final TextAttributesKey[] KEY_KEYS = new TextAttributesKey[]{KEY}; - private static final TextAttributesKey[] VALUE_KEYS = new TextAttributesKey[]{VALUE}; - private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT}; - private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0]; + private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER}; + private static final TextAttributesKey[] SEPARATOR_KEYS = new TextAttributesKey[]{SEPARATOR}; + private static final TextAttributesKey[] KEY_KEYS = new TextAttributesKey[]{KEY}; + private static final TextAttributesKey[] VALUE_KEYS = new TextAttributesKey[]{VALUE}; + private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT}; + private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0]; - @NotNull - @Override - public Lexer getHighlightingLexer() { - return new SimpleLexerAdapter(); - } - - @NotNull - @Override - public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { - if (tokenType.equals(SimpleTypes.SEPARATOR)) { - return SEPARATOR_KEYS; - } else if (tokenType.equals(SimpleTypes.KEY)) { - return KEY_KEYS; - } else if (tokenType.equals(SimpleTypes.VALUE)) { - return VALUE_KEYS; - } else if (tokenType.equals(SimpleTypes.COMMENT)) { - return COMMENT_KEYS; - } else if (tokenType.equals(TokenType.BAD_CHARACTER)) { - return BAD_CHAR_KEYS; - } else { - return EMPTY_KEYS; - } + @NotNull + @Override + public Lexer getHighlightingLexer() { + return new SimpleLexerAdapter(); + } + + @NotNull + @Override + public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { + if (tokenType.equals(SimpleTypes.SEPARATOR)) { + return SEPARATOR_KEYS; + } else if (tokenType.equals(SimpleTypes.KEY)) { + return KEY_KEYS; + } else if (tokenType.equals(SimpleTypes.VALUE)) { + return VALUE_KEYS; + } else if (tokenType.equals(SimpleTypes.COMMENT)) { + return COMMENT_KEYS; + } else if (tokenType.equals(TokenType.BAD_CHARACTER)) { + return BAD_CHAR_KEYS; + } else { + return EMPTY_KEYS; } + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighterFactory.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighterFactory.java index e3a6fe428..49bd0addb 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighterFactory.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleSyntaxHighlighterFactory.java @@ -7,9 +7,9 @@ import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; public class SimpleSyntaxHighlighterFactory extends SyntaxHighlighterFactory { - @NotNull - @Override - public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { - return new SimpleSyntaxHighlighter(); - } + @NotNull + @Override + public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { + return new SimpleSyntaxHighlighter(); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleTodoIndexer.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleTodoIndexer.java index 505c0acce..bee9bd730 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleTodoIndexer.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleTodoIndexer.java @@ -5,8 +5,8 @@ import com.intellij.psi.impl.cache.impl.OccurrenceConsumer; import com.intellij.psi.impl.cache.impl.todo.LexerBasedTodoIndexer; public class SimpleTodoIndexer extends LexerBasedTodoIndexer { - @Override - public Lexer createLexer(OccurrenceConsumer consumer) { - return SimpleIdIndexer.createIndexingLexer(consumer); - } + @Override + public Lexer createLexer(OccurrenceConsumer consumer) { + return SimpleIdIndexer.createIndexingLexer(consumer); + } } diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleUtil.java b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleUtil.java index c2bb98218..03e31235a 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleUtil.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/SimpleUtil.java @@ -16,42 +16,44 @@ import java.util.Collections; import java.util.List; public class SimpleUtil { - public static List findProperties(Project project, String key) { - List result = null; - Collection virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE, - GlobalSearchScope.allScope(project)); - for (VirtualFile virtualFile : virtualFiles) { - SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile); - if (simpleFile != null) { - SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, SimpleProperty.class); - if (properties != null) { - for (SimpleProperty property : properties) { - if (key.equals(property.getKey())) { - if (result == null) { - result = new ArrayList(); - } - result.add(property); - } - } - } + public static List findProperties(Project project, String key) { + List result = null; + Collection virtualFiles = + FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE, + GlobalSearchScope.allScope(project)); + for (VirtualFile virtualFile : virtualFiles) { + SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile); + if (simpleFile != null) { + SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, SimpleProperty.class); + if (properties != null) { + for (SimpleProperty property : properties) { + if (key.equals(property.getKey())) { + if (result == null) { + result = new ArrayList(); + } + result.add(property); } + } } - return result != null ? result : Collections.emptyList(); + } } + return result != null ? result : Collections.emptyList(); + } - public static List findProperties(Project project) { - List result = new ArrayList(); - Collection virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE, - GlobalSearchScope.allScope(project)); - for (VirtualFile virtualFile : virtualFiles) { - SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile); - if (simpleFile != null) { - SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, SimpleProperty.class); - if (properties != null) { - Collections.addAll(result, properties); - } - } + public static List findProperties(Project project) { + List result = new ArrayList(); + Collection virtualFiles = + FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE, + GlobalSearchScope.allScope(project)); + for (VirtualFile virtualFile : virtualFiles) { + SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile); + if (simpleFile != null) { + SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, SimpleProperty.class); + if (properties != null) { + Collections.addAll(result, properties); } - return result; + } } + return result; + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementFactory.java b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementFactory.java index 91e10ba09..3b94792a9 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementFactory.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementFactory.java @@ -6,24 +6,24 @@ import com.intellij.psi.PsiFileFactory; import com.simpleplugin.SimpleFileType; public class SimpleElementFactory { - public static SimpleProperty createProperty(Project project, String name, String value) { - final SimpleFile file = createFile(project, name + " = " + value); - return (SimpleProperty) file.getFirstChild(); - } + public static SimpleProperty createProperty(Project project, String name, String value) { + final SimpleFile file = createFile(project, name + " = " + value); + return (SimpleProperty) file.getFirstChild(); + } - public static SimpleProperty createProperty(Project project, String name) { - final SimpleFile file = createFile(project, name); - return (SimpleProperty) file.getFirstChild(); - } + public static SimpleProperty createProperty(Project project, String name) { + final SimpleFile file = createFile(project, name); + return (SimpleProperty) file.getFirstChild(); + } - public static PsiElement createCRLF(Project project) { - final SimpleFile file = createFile(project, "\n"); - return file.getFirstChild(); - } + public static PsiElement createCRLF(Project project) { + final SimpleFile file = createFile(project, "\n"); + return file.getFirstChild(); + } - public static SimpleFile createFile(Project project, String text) { - String name = "dummy.simple"; - return (SimpleFile) PsiFileFactory.getInstance(project). - createFileFromText(name, SimpleFileType.INSTANCE, text); - } + public static SimpleFile createFile(Project project, String text) { + String name = "dummy.simple"; + return (SimpleFile) PsiFileFactory.getInstance(project). + createFileFromText(name, SimpleFileType.INSTANCE, text); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementType.java b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementType.java index 34e5c3464..4ff00b6a8 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementType.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleElementType.java @@ -6,7 +6,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class SimpleElementType extends IElementType { - public SimpleElementType(@NotNull @NonNls String debugName) { - super(debugName, SimpleLanguage.INSTANCE); - } + public SimpleElementType(@NotNull @NonNls String debugName) { + super(debugName, SimpleLanguage.INSTANCE); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleFile.java b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleFile.java index 21c8adc3b..133916e7f 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleFile.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleFile.java @@ -10,23 +10,23 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; public class SimpleFile extends PsiFileBase { - public SimpleFile(@NotNull FileViewProvider viewProvider) { - super(viewProvider, SimpleLanguage.INSTANCE); - } + public SimpleFile(@NotNull FileViewProvider viewProvider) { + super(viewProvider, SimpleLanguage.INSTANCE); + } - @NotNull - @Override - public FileType getFileType() { - return SimpleFileType.INSTANCE; - } + @NotNull + @Override + public FileType getFileType() { + return SimpleFileType.INSTANCE; + } - @Override - public String toString() { - return "Simple File"; - } + @Override + public String toString() { + return "Simple File"; + } - @Override - public Icon getIcon(int flags) { - return super.getIcon(flags); - } + @Override + public Icon getIcon(int flags) { + return super.getIcon(flags); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleTokenType.java b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleTokenType.java index 6bdb585b4..188392218 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleTokenType.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/SimpleTokenType.java @@ -6,12 +6,12 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class SimpleTokenType extends IElementType { - public SimpleTokenType(@NotNull @NonNls String debugName) { - super(debugName, SimpleLanguage.INSTANCE); - } + public SimpleTokenType(@NotNull @NonNls String debugName) { + super(debugName, SimpleLanguage.INSTANCE); + } - @Override - public String toString() { - return "SimpleTokenType." + super.toString(); - } + @Override + public String toString() { + return "SimpleTokenType." + super.toString(); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimpleNamedElementImpl.java b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimpleNamedElementImpl.java index dcb333a62..e727d873d 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimpleNamedElementImpl.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimpleNamedElementImpl.java @@ -6,7 +6,7 @@ import com.simpleplugin.psi.SimpleNamedElement; import org.jetbrains.annotations.NotNull; public abstract class SimpleNamedElementImpl extends ASTWrapperPsiElement implements SimpleNamedElement { - public SimpleNamedElementImpl(@NotNull ASTNode node) { - super(node); - } + public SimpleNamedElementImpl(@NotNull ASTNode node) { + super(node); + } } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimplePsiImplUtil.java b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimplePsiImplUtil.java index 3e58dc070..399d96ccc 100644 --- a/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimplePsiImplUtil.java +++ b/code_samples/simple_language_plugin/src/com/simpleplugin/psi/impl/SimplePsiImplUtil.java @@ -9,73 +9,72 @@ import com.simpleplugin.psi.SimpleElementFactory; import com.simpleplugin.psi.SimpleProperty; import com.simpleplugin.psi.SimpleTypes; import org.jetbrains.annotations.Nullable; -import java.lang.String; import javax.swing.*; public class SimplePsiImplUtil { - public static String getKey(SimpleProperty element) { - ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); - if (keyNode != null) { - // IMPORTANT: Convert embedded escaped spaces to simple spaces - return keyNode.getText().replaceAll("\\\\ "," "); - } else { - return null; - } + public static String getKey(SimpleProperty element) { + ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); + if (keyNode != null) { + // IMPORTANT: Convert embedded escaped spaces to simple spaces + return keyNode.getText().replaceAll("\\\\ ", " "); + } else { + return null; } + } - public static String getValue(SimpleProperty element) { - ASTNode valueNode = element.getNode().findChildByType(SimpleTypes.VALUE); - if (valueNode != null) { - return valueNode.getText(); - } else { - return null; - } + public static String getValue(SimpleProperty element) { + ASTNode valueNode = element.getNode().findChildByType(SimpleTypes.VALUE); + if (valueNode != null) { + return valueNode.getText(); + } else { + return null; } + } - public static String getName(SimpleProperty element) { - return getKey(element); + public static String getName(SimpleProperty element) { + return getKey(element); + } + + public static PsiElement setName(SimpleProperty element, String newName) { + ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); + if (keyNode != null) { + SimpleProperty property = SimpleElementFactory.createProperty(element.getProject(), newName); + ASTNode newKeyNode = property.getFirstChild().getNode(); + element.getNode().replaceChild(keyNode, newKeyNode); } + return element; + } - public static PsiElement setName(SimpleProperty element, String newName) { - ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); - if (keyNode != null) { - SimpleProperty property = SimpleElementFactory.createProperty(element.getProject(), newName); - ASTNode newKeyNode = property.getFirstChild().getNode(); - element.getNode().replaceChild(keyNode, newKeyNode); - } - return element; + public static PsiElement getNameIdentifier(SimpleProperty element) { + ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); + if (keyNode != null) { + return keyNode.getPsi(); + } else { + return null; } + } - public static PsiElement getNameIdentifier(SimpleProperty element) { - ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); - if (keyNode != null) { - return keyNode.getPsi(); - } else { - return null; - } - } + public static ItemPresentation getPresentation(final SimpleProperty element) { + return new ItemPresentation() { + @Nullable + @Override + public String getPresentableText() { + return element.getKey(); + } - public static ItemPresentation getPresentation(final SimpleProperty element) { - return new ItemPresentation() { - @Nullable - @Override - public String getPresentableText() { - return element.getKey(); - } + @Nullable + @Override + public String getLocationString() { + PsiFile containingFile = element.getContainingFile(); + return containingFile == null ? null : containingFile.getName(); + } - @Nullable - @Override - public String getLocationString() { - PsiFile containingFile = element.getContainingFile(); - return containingFile == null ? null : containingFile.getName(); - } - - @Nullable - @Override - public Icon getIcon(boolean unused) { - return SimpleIcons.FILE; - } - }; - } + @Nullable + @Override + public Icon getIcon(boolean unused) { + return SimpleIcons.FILE; + } + }; + } } diff --git a/code_samples/simple_language_plugin/testData/AnnotatorTestData.java b/code_samples/simple_language_plugin/testData/AnnotatorTestData.java index 699bba52c..afb27b17a 100644 --- a/code_samples/simple_language_plugin/testData/AnnotatorTestData.java +++ b/code_samples/simple_language_plugin/testData/AnnotatorTestData.java @@ -1,7 +1,7 @@ public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - System.out.println("simple:key with spaces"); - System.out.println("simple:websit"); - } + public static void main(String[] args) { + System.out.println("simple:website"); + System.out.println("simple:key with spaces"); + System.out.println("simple:websit" < / error >); + } } diff --git a/code_samples/simple_language_plugin/testData/CompleteTestData.java b/code_samples/simple_language_plugin/testData/CompleteTestData.java index 4a883daec..7c2c666a1 100644 --- a/code_samples/simple_language_plugin/testData/CompleteTestData.java +++ b/code_samples/simple_language_plugin/testData/CompleteTestData.java @@ -1,5 +1,5 @@ public class Test { - public static void main(String[] args) { - System.out.println("simple:"); - } + public static void main(String[] args) { + System.out.println("simple:"); + } } diff --git a/code_samples/simple_language_plugin/testData/FindUsagesTestData.java b/code_samples/simple_language_plugin/testData/FindUsagesTestData.java index 401d8c782..727681239 100644 --- a/code_samples/simple_language_plugin/testData/FindUsagesTestData.java +++ b/code_samples/simple_language_plugin/testData/FindUsagesTestData.java @@ -1,5 +1,5 @@ public class Test { - public static void main(String[] args) { - System.out.println("simple:key with spaces"); - } + public static void main(String[] args) { + System.out.println("simple:key with spaces"); + } } diff --git a/code_samples/simple_language_plugin/testData/FoldingTestData.java b/code_samples/simple_language_plugin/testData/FoldingTestData.java index 1920b5fae..8c53505df 100644 --- a/code_samples/simple_language_plugin/testData/FoldingTestData.java +++ b/code_samples/simple_language_plugin/testData/FoldingTestData.java @@ -1,11 +1,35 @@ public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - } - public static void main1(String[] args) { - System.out.println("simple:key with spaces"); - } - public static void main2(String[] args) { - System.out.println("simple:message"); - } + public static void main(String[] args) + + + + { + System.out.println("simple:website"); + } + + + + public static void main1(String[] args) + + + + { + System.out.println( + "simple:key with " + + "spaces");< + fold text = ' }' > + } + + + + public static void main2(String[] args) + + + + { + System.out.println("simple:message");< + fold text = ' }' > + } + + } diff --git a/code_samples/simple_language_plugin/testData/ReferenceTestData.java b/code_samples/simple_language_plugin/testData/ReferenceTestData.java index 384347eda..92c55dfd5 100644 --- a/code_samples/simple_language_plugin/testData/ReferenceTestData.java +++ b/code_samples/simple_language_plugin/testData/ReferenceTestData.java @@ -1,5 +1,5 @@ public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - } + public static void main(String[] args) { + System.out.println("simple:website"); + } } diff --git a/code_samples/simple_language_plugin/testData/RenameTestData.java b/code_samples/simple_language_plugin/testData/RenameTestData.java index 384347eda..92c55dfd5 100644 --- a/code_samples/simple_language_plugin/testData/RenameTestData.java +++ b/code_samples/simple_language_plugin/testData/RenameTestData.java @@ -1,5 +1,5 @@ public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - } + public static void main(String[] args) { + System.out.println("simple:website"); + } } diff --git a/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleCodeInsightTest.java b/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleCodeInsightTest.java index f7a703264..b965fdf20 100644 --- a/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleCodeInsightTest.java +++ b/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleCodeInsightTest.java @@ -16,71 +16,71 @@ import java.util.Collection; import java.util.List; public class SimpleCodeInsightTest extends LightCodeInsightFixtureTestCase { - @Override - protected void setUp() throws Exception { - VfsRootAccess.SHOULD_PERFORM_ACCESS_CHECK = false; // TODO: a workaround for v15 - super.setUp(); - } + @Override + protected void setUp() throws Exception { + VfsRootAccess.SHOULD_PERFORM_ACCESS_CHECK = false; // TODO: a workaround for v15 + super.setUp(); + } - @Override - protected String getTestDataPath() { - return "code_samples/simple_language_plugin/testData"; - } + @Override + protected String getTestDataPath() { + return "code_samples/simple_language_plugin/testData"; + } - public void testCompletion() { - myFixture.configureByFiles("CompleteTestData.java", "DefaultTestData.simple"); - myFixture.complete(CompletionType.BASIC, 1); - List strings = myFixture.getLookupElementStrings(); - assertTrue(strings.containsAll(Arrays.asList("key with spaces", "language", "message", "tab", "website"))); - assertEquals(5, strings.size()); - } + public void testCompletion() { + myFixture.configureByFiles("CompleteTestData.java", "DefaultTestData.simple"); + myFixture.complete(CompletionType.BASIC, 1); + List strings = myFixture.getLookupElementStrings(); + assertTrue(strings.containsAll(Arrays.asList("key with spaces", "language", "message", "tab", "website"))); + assertEquals(5, strings.size()); + } - public void testAnnotator() { - myFixture.configureByFiles("AnnotatorTestData.java", "DefaultTestData.simple"); - myFixture.checkHighlighting(false, false, true); - } + public void testAnnotator() { + myFixture.configureByFiles("AnnotatorTestData.java", "DefaultTestData.simple"); + myFixture.checkHighlighting(false, false, true); + } - public void testFormatter() { - myFixture.configureByFiles("FormatterTestData.simple"); - CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true; - CodeStyleSettingsManager.getSettings(getProject()).KEEP_BLANK_LINES_IN_CODE = 2; - new WriteCommandAction.Simple(getProject()) { - @Override - protected void run() throws Throwable { - CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile()); - } - }.execute(); - myFixture.checkResultByFile("DefaultTestData.simple"); - } + public void testFormatter() { + myFixture.configureByFiles("FormatterTestData.simple"); + CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true; + CodeStyleSettingsManager.getSettings(getProject()).KEEP_BLANK_LINES_IN_CODE = 2; + new WriteCommandAction.Simple(getProject()) { + @Override + protected void run() throws Throwable { + CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile()); + } + }.execute(); + myFixture.checkResultByFile("DefaultTestData.simple"); + } - public void testRename() { - myFixture.configureByFiles("RenameTestData.java", "RenameTestData.simple"); - myFixture.renameElementAtCaret("websiteUrl"); - myFixture.checkResultByFile("RenameTestData.simple", "RenameTestDataAfter.simple", false); - } + public void testRename() { + myFixture.configureByFiles("RenameTestData.java", "RenameTestData.simple"); + myFixture.renameElementAtCaret("websiteUrl"); + myFixture.checkResultByFile("RenameTestData.simple", "RenameTestDataAfter.simple", false); + } - public void testFolding() { - myFixture.configureByFiles("DefaultTestData.simple"); - myFixture.testFolding(getTestDataPath() + "/FoldingTestData.java"); - } + public void testFolding() { + myFixture.configureByFiles("DefaultTestData.simple"); + myFixture.testFolding(getTestDataPath() + "/FoldingTestData.java"); + } - public void testFindUsages() { - Collection usageInfos = myFixture.testFindUsages("FindUsagesTestData.simple", "FindUsagesTestData.java"); - assertEquals(1, usageInfos.size()); - } + public void testFindUsages() { + Collection usageInfos = myFixture.testFindUsages("FindUsagesTestData.simple", "FindUsagesTestData.java"); + assertEquals(1, usageInfos.size()); + } - public void testCommenter() { - myFixture.configureByText(SimpleFileType.INSTANCE, "website = http://en.wikipedia.org/"); - CommentByLineCommentAction commentAction = new CommentByLineCommentAction(); - commentAction.actionPerformedImpl(getProject(), myFixture.getEditor()); - myFixture.checkResult("#website = http://en.wikipedia.org/"); - commentAction.actionPerformedImpl(getProject(), myFixture.getEditor()); - myFixture.checkResult("website = http://en.wikipedia.org/"); - } + public void testCommenter() { + myFixture.configureByText(SimpleFileType.INSTANCE, "website = http://en.wikipedia.org/"); + CommentByLineCommentAction commentAction = new CommentByLineCommentAction(); + commentAction.actionPerformedImpl(getProject(), myFixture.getEditor()); + myFixture.checkResult("#website = http://en.wikipedia.org/"); + commentAction.actionPerformedImpl(getProject(), myFixture.getEditor()); + myFixture.checkResult("website = http://en.wikipedia.org/"); + } - public void testReference() { - myFixture.configureByFiles("ReferenceTestData.java", "DefaultTestData.simple"); - PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent(); - assertEquals("http://en.wikipedia.org/", ((SimpleProperty) element.getReferences()[0].resolve()).getValue()); - } + public void testReference() { + myFixture.configureByFiles("ReferenceTestData.java", "DefaultTestData.simple"); + PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent(); + assertEquals("http://en.wikipedia.org/", ((SimpleProperty) element.getReferences()[0].resolve()).getValue()); + } } diff --git a/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleParsingTest.java b/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleParsingTest.java index 83119a1a6..31543cf21 100644 --- a/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleParsingTest.java +++ b/code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleParsingTest.java @@ -3,26 +3,26 @@ package com.simpleplugin; import com.intellij.testFramework.ParsingTestCase; public class SimpleParsingTest extends ParsingTestCase { - public SimpleParsingTest() { - super("", "simple", new SimpleParserDefinition()); - } + public SimpleParsingTest() { + super("", "simple", new SimpleParserDefinition()); + } - public void testParsingTestData() { - doTest(true); - } + public void testParsingTestData() { + doTest(true); + } - @Override - protected String getTestDataPath() { - return "code_samples/simple_language_plugin/testData"; - } + @Override + protected String getTestDataPath() { + return "code_samples/simple_language_plugin/testData"; + } - @Override - protected boolean skipSpaces() { - return false; - } + @Override + protected boolean skipSpaces() { + return false; + } - @Override - protected boolean includeRanges() { - return true; - } + @Override + protected boolean includeRanges() { + return true; + } } diff --git a/code_samples/tool_window/resources/META-INF/plugin.xml b/code_samples/tool_window/resources/META-INF/plugin.xml index 332a2a997..33986b761 100644 --- a/code_samples/tool_window/resources/META-INF/plugin.xml +++ b/code_samples/tool_window/resources/META-INF/plugin.xml @@ -1,33 +1,33 @@ - org.jetbrains.plugins.sample.ToolWindow - Tool Window - This sample plugin illustrates how to create your custom tool window. - 2.0 - YourCompany + org.jetbrains.plugins.sample.ToolWindow + Tool Window + This sample plugin illustrates how to create your custom tool window. + 2.0 + YourCompany - most HTML tags may be used ]]> - + - - + + - - + + - - + + - + - - - + + + \ No newline at end of file diff --git a/code_samples/tool_window/src/myToolWindow/MyToolWindowFactory.java b/code_samples/tool_window/src/myToolWindow/MyToolWindowFactory.java index 1082183c6..29829ba54 100644 --- a/code_samples/tool_window/src/myToolWindow/MyToolWindowFactory.java +++ b/code_samples/tool_window/src/myToolWindow/MyToolWindowFactory.java @@ -19,61 +19,62 @@ import java.util.Calendar; */ public class MyToolWindowFactory implements ToolWindowFactory { - private JButton refreshToolWindowButton; - private JButton hideToolWindowButton; - private JLabel currentDate; - private JLabel currentTime; - private JLabel timeZone; - private JPanel myToolWindowContent; - private ToolWindow myToolWindow; + private JButton refreshToolWindowButton; + private JButton hideToolWindowButton; + private JLabel currentDate; + private JLabel currentTime; + private JLabel timeZone; + private JPanel myToolWindowContent; + private ToolWindow myToolWindow; - public MyToolWindowFactory() { - hideToolWindowButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - myToolWindow.hide(null); - } - }); - refreshToolWindowButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - MyToolWindowFactory.this.currentDateTime(); - } - }); + public MyToolWindowFactory() { + hideToolWindowButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + myToolWindow.hide(null); + } + }); + refreshToolWindowButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + MyToolWindowFactory.this.currentDateTime(); + } + }); + } + + // Create the tool window content. + public void createToolWindowContent(Project project, ToolWindow toolWindow) { + myToolWindow = toolWindow; + this.currentDateTime(); + ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); + Content content = contentFactory.createContent(myToolWindowContent, "", false); + toolWindow.getContentManager().addContent(content); + + } + + public void currentDateTime() { + // Get current date and time + Calendar instance = Calendar.getInstance(); + currentDate.setText(String.valueOf(instance.get(Calendar.DAY_OF_MONTH)) + "/" + + String.valueOf(instance.get(Calendar.MONTH) + 1) + "/" + + String.valueOf(instance.get(Calendar.YEAR))); + currentDate.setIcon(new ImageIcon(getClass().getResource("/myToolWindow/Calendar-icon.png"))); + int min = instance.get(Calendar.MINUTE); + String strMin; + if (min < 10) { + strMin = "0" + String.valueOf(min); + } else { + strMin = String.valueOf(min); } - - // Create the tool window content. - public void createToolWindowContent(Project project, ToolWindow toolWindow) { - myToolWindow = toolWindow; - this.currentDateTime(); - ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); - Content content = contentFactory.createContent(myToolWindowContent, "", false); - toolWindow.getContentManager().addContent(content); - - } - - public void currentDateTime() { - // Get current date and time - Calendar instance = Calendar.getInstance(); - currentDate.setText(String.valueOf(instance.get(Calendar.DAY_OF_MONTH)) + "/" - + String.valueOf(instance.get(Calendar.MONTH) + 1) + "/" + String.valueOf(instance.get(Calendar.YEAR))); - currentDate.setIcon(new ImageIcon(getClass().getResource("/myToolWindow/Calendar-icon.png"))); - int min = instance.get(Calendar.MINUTE); - String strMin; - if (min < 10) { - strMin = "0" + String.valueOf(min); - } else { - strMin = String.valueOf(min); - } - currentTime.setText(instance.get(Calendar.HOUR_OF_DAY) + ":" + strMin); - currentTime.setIcon(new ImageIcon(getClass().getResource("/myToolWindow/Time-icon.png"))); - // Get time zone - long gmt_Offset = instance.get(Calendar.ZONE_OFFSET); // offset from GMT in milliseconds - String str_gmt_Offset = String.valueOf(gmt_Offset / 3600000); - str_gmt_Offset = (gmt_Offset > 0) ? "GMT + " + str_gmt_Offset : "GMT - " + str_gmt_Offset; - timeZone.setText(str_gmt_Offset); - timeZone.setIcon(new ImageIcon(getClass().getResource("/myToolWindow/Time-zone-icon.png"))); + currentTime.setText(instance.get(Calendar.HOUR_OF_DAY) + ":" + strMin); + currentTime.setIcon(new ImageIcon(getClass().getResource("/myToolWindow/Time-icon.png"))); + // Get time zone + long gmt_Offset = instance.get(Calendar.ZONE_OFFSET); // offset from GMT in milliseconds + String str_gmt_Offset = String.valueOf(gmt_Offset / 3600000); + str_gmt_Offset = (gmt_Offset > 0) ? "GMT + " + str_gmt_Offset : "GMT - " + str_gmt_Offset; + timeZone.setText(str_gmt_Offset); + timeZone.setIcon(new ImageIcon(getClass().getResource("/myToolWindow/Time-zone-icon.png"))); - } + } } diff --git a/code_samples/tree_structure_provider/src/org/jetbrains/tutorials/tree/structure/TextOnlyTreeStructureProvider.java b/code_samples/tree_structure_provider/src/org/jetbrains/tutorials/tree/structure/TextOnlyTreeStructureProvider.java index 58fb2b216..610d3e998 100644 --- a/code_samples/tree_structure_provider/src/org/jetbrains/tutorials/tree/structure/TextOnlyTreeStructureProvider.java +++ b/code_samples/tree_structure_provider/src/org/jetbrains/tutorials/tree/structure/TextOnlyTreeStructureProvider.java @@ -16,25 +16,27 @@ import java.util.Collection; * @author Anna Bulenkova */ public class TextOnlyTreeStructureProvider implements TreeStructureProvider { - @NotNull - @Override - public Collection modify(@NotNull AbstractTreeNode parent, @NotNull Collection children, ViewSettings settings) { - ArrayList nodes = new ArrayList(); - for (AbstractTreeNode child : children) { - if (child instanceof PsiFileNode) { - VirtualFile file = ((PsiFileNode) child).getVirtualFile(); - if (file != null && !file.isDirectory() && !(file.getFileType() instanceof PlainTextFileType)) { - continue; - } - } - nodes.add(child); + @NotNull + @Override + public Collection modify(@NotNull AbstractTreeNode parent, + @NotNull Collection children, + ViewSettings settings) { + ArrayList nodes = new ArrayList(); + for (AbstractTreeNode child : children) { + if (child instanceof PsiFileNode) { + VirtualFile file = ((PsiFileNode) child).getVirtualFile(); + if (file != null && !file.isDirectory() && !(file.getFileType() instanceof PlainTextFileType)) { + continue; } - return nodes; + } + nodes.add(child); } + return nodes; + } - @Nullable - @Override - public Object getData(Collection collection, String s) { - return null; - } + @Nullable + @Override + public Object getData(Collection collection, String s) { + return null; + } } \ No newline at end of file