Tidy up code samples and wrap at 80 chars #IJSDK-24

This commit is contained in:
Breandan Considine 2016-03-21 16:08:47 -04:00
parent 8aaf13b046
commit f416f02ce2
127 changed files with 2659 additions and 2528 deletions

View File

@ -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,8 +23,12 @@ 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() {
@ -67,7 +68,8 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool {
}
@Override public void visitBinaryExpression(PsiBinaryExpression expression) {
@Override
public void visitBinaryExpression(PsiBinaryExpression expression) {
super.visitBinaryExpression(expression);
IElementType opSign = expression.getOperationTokenType();
if (opSign == JavaTokenType.EQEQ || opSign == JavaTokenType.NE) {
@ -109,7 +111,8 @@ 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);
@ -121,8 +124,7 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool {
negation.getOperand().replace(result);
result.replace(negation);
}
}
catch (IncorrectOperationException e) {
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}

View File

@ -26,7 +26,8 @@ public class TestThisPlugin extends UsefulTestCase {
public void setUp() throws Exception {
final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = fixtureFactory.createFixtureBuilder(getName());
final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder =
fixtureFactory.createFixtureBuilder(getName());
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture());
myFixture.setTestDataPath(dataPath);
final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class);

View File

@ -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() {
@ -67,7 +68,8 @@ import org.jetbrains.annotations.Nullable;
final PsiElement[] declaredElements = declaration.getDeclaredElements();
PsiLocalVariable variable = null;
for (PsiElement declaredElement : declaredElements) {
if (declaredElement instanceof PsiLocalVariable && PsiTreeUtil.isAncestor(declaredElement, conditionalExpression, true)) {
if (declaredElement instanceof PsiLocalVariable &&
PsiTreeUtil.isAncestor(declaredElement, conditionalExpression, true)) {
variable = (PsiLocalVariable) declaredElement;
break;
}

View File

@ -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;
@ -20,7 +19,8 @@ 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";
// 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

View File

@ -25,15 +25,21 @@
</project-components>
<actions>
<action id="EditorBasics.EditorIllustration" class="org.jetbrains.tutorials.editor.basics.EditorIllustration" text="Editor Basics"
<action id="EditorBasics.EditorIllustration"
class="org.jetbrains.tutorials.editor.basics.EditorIllustration"
text="Editor Basics"
description="Illustrates how to plug an action in">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>
<action id="EditorBasics.EditorHandlerIllustration" class="org.jetbrains.tutorials.editor.basics.EditorHandlerIllustration" text="Editor Handler"
<action id="EditorBasics.EditorHandlerIllustration"
class="org.jetbrains.tutorials.editor.basics.EditorHandlerIllustration"
text="Editor Handler"
description="Illustrates how to plug an action in">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>
<action id="EditorBasics.LogicalPositionIllustration" class="org.jetbrains.tutorials.editor.basics.EditorAreaIllustration" text="Caret Position"
<action id="EditorBasics.LogicalPositionIllustration"
class="org.jetbrains.tutorials.editor.basics.EditorAreaIllustration"
text="Caret Position"
description="Illustrates how editor area is organized">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>

View File

@ -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;

View File

@ -22,11 +22,13 @@ public class EditorHandlerIllustration extends AnAction {
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()));
anActionEvent.getPresentation()
.setVisible((project != null && editor != null && !editor.getCaretModel().getAllCarets().isEmpty()));
}
}

View File

@ -44,6 +44,7 @@ public class EditorIllustration extends AnAction {
WriteCommandAction.runWriteCommandAction(project, runnable);
selectionModel.removeSelection();
}
@Override
public void update(final AnActionEvent e) {
//Get required data keys

View File

@ -10,7 +10,11 @@ import com.intellij.openapi.module.Module;
public class DemoFacet extends Facet<DemoFacetConfiguration> {
public static final String ID = "DEMO_FACET_ID";
public DemoFacet(FacetType facetType, Module module, String name, DemoFacetConfiguration configuration, Facet underlyingFacet) {
public DemoFacet(FacetType facetType,
Module module,
String name,
DemoFacetConfiguration configuration,
Facet underlyingFacet) {
super(facetType, module, name, configuration, underlyingFacet);
}
}

View File

@ -21,6 +21,7 @@ public class DemoFacetConfiguration implements FacetConfiguration {
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[]{

View File

@ -16,6 +16,7 @@ import javax.swing.*;
*/
public class DemoFacetType extends FacetType<DemoFacet, DemoFacetConfiguration> {
private static final FacetTypeId<DemoFacet> TYPE_ID = new FacetTypeId<DemoFacet>(DemoFacet.ID);
public DemoFacetType() {
super(TYPE_ID, DemoFacet.ID, "Demo Facet");
}
@ -26,7 +27,10 @@ public class DemoFacetType extends FacetType<DemoFacet, DemoFacetConfiguration>
}
@Override
public DemoFacet createFacet(@NotNull Module module, String s, @NotNull DemoFacetConfiguration configuration, Facet facet) {
public DemoFacet createFacet(@NotNull Module module,
String s,
@NotNull DemoFacetConfiguration configuration,
Facet facet) {
return new DemoFacet(this, module, s, configuration, facet);
}

View File

@ -19,6 +19,7 @@ import javax.swing.*;
*/
public class DemoFramework extends FrameworkTypeEx {
public static final String FRAMEWORK_ID = "Demo";
protected DemoFramework() {
super(FRAMEWORK_ID);
}
@ -44,7 +45,9 @@ public class DemoFramework extends FrameworkTypeEx {
}
@Override
public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ModifiableModelsProvider provider) {
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
}
};

View File

@ -1,5 +1,9 @@
<templateSet group="Markdown">
<template name="[" value="[$TEXT$]($LINK$)$END$" description="New link reference." toReformat="false" toShortenFQNames="false">
<template name="["
value="[$TEXT$]($LINK$)$END$"
description="New link reference."
toReformat="false"
toShortenFQNames="false">
<variable name="TEXT" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="LINK" expression="complete()" defaultValue="" alwaysStopAt="true"/>
<context>

View File

@ -1,9 +1,6 @@
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() {

View File

@ -3,8 +3,7 @@ import org.jetbrains.annotations.Nullable;
public class MarkdownTemplateProvider implements DefaultLiveTemplatesProvider {
@Override
public String[] getDefaultLiveTemplateFiles()
{
public String[] getDefaultLiveTemplateFiles() {
return new String[]{"liveTemplates/Markdown"};
}

View File

@ -36,7 +36,8 @@ public class MaxProject implements ProjectComponent {
MyCounter CommandCounter = ServiceManager.getService(MyCounter.class);
if (CommandCounter.IncreaseCounter() == -1) {
Messages.showMessageDialog("The maximum number of opened projects exceeds " + String.valueOf(CommandCounter.MaxCount) +
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();

View File

@ -11,6 +11,7 @@ public class MyCounter {
private int Count = 0;
// Sets the maximum allowed number of opened projects.
public final int MaxCount = 3;
public MyCounter() {

View File

@ -54,7 +54,9 @@ public class DemoModuleType extends ModuleType<DemoModuleBuilder> {
@NotNull
@Override
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull DemoModuleBuilder moduleBuilder, @NotNull ModulesProvider modulesProvider) {
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext,
@NotNull DemoModuleBuilder moduleBuilder,
@NotNull ModulesProvider modulesProvider) {
return super.createWizardSteps(wizardContext, moduleBuilder, modulesProvider);
}
}

View File

@ -73,7 +73,9 @@
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. -->
<action id="PluginSample.DummyAction" class="org.jetbrains.tutorials.sample.actions.SimpleAction" text="Dummy Action"
<action id="PluginSample.DummyAction"
class="org.jetbrains.tutorials.sample.actions.SimpleAction"
text="Dummy Action"
description="Illustrates how to plug an action in">
<!-- The <keyboard-shortcut> node specifies the keyboard shortcut for the action. An action can have several keyboard shortcuts.
The mandatory "first-keystroke" attribute specifies the first keystroke of the action. The key strokes are specified according to the regular Swing rules.
@ -107,7 +109,8 @@
The optional "popup" attribute specifies how the group is presented in the menu. If a group has popup="true", actions in it
are placed in a submenu; for popup="false", actions are displayed as a section of the same menu delimited by separators. -->
<group id="DummyDefaultActionGroup" text="Default action group">
<action class="org.jetbrains.tutorials.sample.actions.GroupedToDefaultAction" id="PluginSample.GroupedToDefaultAction"/>
<action class="org.jetbrains.tutorials.sample.actions.GroupedToDefaultAction"
id="PluginSample.GroupedToDefaultAction"/>
</group>
<group class="org.jetbrains.tutorials.sample.actions.DummyActionGroup" id="DummyActionGroup" text="Action Group"
description="Illustration of an action group"

View File

@ -56,7 +56,8 @@ public class LibrariesAction extends AnAction {
}
}
if (jars.length() > 0) {
Messages.showInfoMessage("Libraries for file " + virtualFile.getName() + ": " + jars.toString(), "Libraries Info");
Messages.showInfoMessage("Libraries for file " + virtualFile.getName() + ": " + jars.toString(),
"Libraries Info");
}
}
}

View File

@ -22,7 +22,8 @@ public class ShowSourceRootsActions extends AnAction {
for (VirtualFile file : vFiles) {
sourceRootsList.append(file.getUrl()).append("\n");
}
Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, "Project Properties");
Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList,
"Project Properties");
}
@Override

View File

@ -158,7 +158,9 @@ public class ImagesProjectNode extends AbstractTreeNode<VirtualFile> {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ProjectView.getInstance(myProject).getProjectViewPaneById(ImagesProjectViewPane.ID).updateFromRoot(true);
ProjectView.getInstance(myProject)
.getProjectViewPaneById(ImagesProjectViewPane.ID)
.updateFromRoot(true);
}
});
}

View File

@ -14,7 +14,9 @@
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<moduleBuilder builderClass="org.jetbrains.tutorials.project.wizard.DemoModuleWizardStep" id="DEMO_STEP" order="first"/>
<moduleBuilder builderClass="org.jetbrains.tutorials.project.wizard.DemoModuleWizardStep"
id="DEMO_STEP"
order="first"/>
</extensions>
<application-components>

View File

@ -24,7 +24,8 @@ public class DemoModuleWizardStep extends ModuleBuilder {
}
@Override
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull ModulesProvider modulesProvider) {
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext,
@NotNull ModulesProvider modulesProvider) {
return new ModuleWizardStep[]{new ModuleWizardStep() {
@Override
public JComponent getComponent() {

View File

@ -14,10 +14,12 @@ public class BaseActionGroup extends ActionGroup {
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

View File

@ -30,7 +30,8 @@ public class DemoRunConfiguration extends RunConfigurationBase {
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws ExecutionException {
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws
ExecutionException {
return null;
}
}

View File

@ -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);

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -40,7 +40,9 @@
<!-- Add your extensions here -->
<fileTypeFactory implementation="com.simpleplugin.SimpleFileTypeFactory"/>
<lang.parserDefinition language="Simple" implementationClass="com.simpleplugin.SimpleParserDefinition"/>
<lang.syntaxHighlighterFactory key="Simple" language="Simple" implementationClass="com.simpleplugin.SimpleSyntaxHighlighterFactory"/>
<lang.syntaxHighlighterFactory key="Simple"
language="Simple"
implementationClass="com.simpleplugin.SimpleSyntaxHighlighterFactory"/>
<colorSettingsPage implementation="com.simpleplugin.SimpleColorSettingsPage"/>
<annotator language="JAVA" implementationClass="com.simpleplugin.SimpleAnnotator"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.simpleplugin.SimpleLineMarkerProvider"/>

View File

@ -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;
@ -51,16 +51,19 @@ class CreatePropertyQuickFix extends BaseIntentionAction {
}
@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws
IncorrectOperationException {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
Collection<VirtualFile> 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);
final FileChooserDescriptor descriptor =
FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
descriptor.setRoots(project.getBaseDir());
final VirtualFile file = FileChooser.chooseFile(descriptor, project, null);
if (file != null) {

View File

@ -16,7 +16,9 @@ public class SimpleFindUsagesProvider implements FindUsagesProvider {
@Override
public WordsScanner getWordsScanner() {
return new DefaultWordsScanner(new SimpleLexerAdapter(),
TokenSet.create(SimpleTypes.KEY), TokenSet.create(SimpleTypes.COMMENT), TokenSet.EMPTY);
TokenSet.create(SimpleTypes.KEY),
TokenSet.create(SimpleTypes.COMMENT),
TokenSet.EMPTY);
}
@Override

View File

@ -25,7 +25,8 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx {
FoldingGroup group = FoldingGroup.newGroup("simple");
List<FoldingDescriptor> descriptors = new ArrayList<FoldingDescriptor>();
Collection<PsiLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class);
Collection<PsiLiteralExpression> literalExpressions =
PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class);
for (final PsiLiteralExpression literalExpression : literalExpressions) {
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
@ -36,12 +37,14 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx {
if (properties.size() == 1) {
descriptors.add(new FoldingDescriptor(literalExpression.getNode(),
new TextRange(literalExpression.getTextRange().getStartOffset() + 1,
literalExpression.getTextRange().getEndOffset() - 1), group) {
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 "
// 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("\"", "\\\\\"");
}

View File

@ -15,14 +15,21 @@ public class SimpleFormattingModelBuilder implements FormattingModelBuilder {
@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);
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();
around(SimpleTypes.SEPARATOR)
.spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS)
.
before(SimpleTypes.PROPERTY)
.none();
}
@Nullable

View File

@ -3,9 +3,9 @@
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;
/**
@ -15,10 +15,14 @@ import com.intellij.psi.TokenType;
* <tt>/Users/vlad/src/SimplePlugin/src/com/simpleplugin/Simple.flex</tt>
*/
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;
@ -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;
@ -273,8 +299,7 @@ class SimpleLexer implements FlexLexer {
* Refills the input buffer.
*
* @return <code>false</code>, iff there was new input.
*
* @exception java.io.IOException if any I/O-Error occurs
* @throws java.io.IOException if any I/O-Error occurs
*/
private boolean zzRefill() throws java.io.IOException {
return true;
@ -310,12 +335,11 @@ class SimpleLexer implements FlexLexer {
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
*
* <p>
* 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) {
@ -333,13 +357,13 @@ class SimpleLexer implements FlexLexer {
/**
* Reports an error that occured while scanning.
*
* <p>
* 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.).
*
* <p>
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
*
@ -349,8 +373,7 @@ class SimpleLexer implements FlexLexer {
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
}
catch (ArrayIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
@ -360,7 +383,7 @@ class SimpleLexer implements FlexLexer {
/**
* Pushes the specified amount of characters back into the input stream.
*
* <p>
* They will be read again by then next call of the scanning method
*
* @param number the number of characters to be read again.
@ -391,7 +414,7 @@ class SimpleLexer implements FlexLexer {
* 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
* @throws java.io.IOException if any I/O-Error occurs
*/
public IElementType advance() throws java.io.IOException {
int zzInput;
@ -419,7 +442,8 @@ class SimpleLexer implements FlexLexer {
zzState = ZZ_LEXSTATE[zzLexicalState];
zzForAction: {
zzForAction:
{
while (true) {
if (zzCurrentPosL < zzEndReadL)
@ -427,8 +451,7 @@ class SimpleLexer implements FlexLexer {
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
}
else {
} else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
@ -441,8 +464,7 @@ class SimpleLexer implements FlexLexer {
if (eof) {
zzInput = YYEOF;
break zzForAction;
}
else {
} else {
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
}
}
@ -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 6: {
yybegin(YYINITIAL);
return SimpleTypes.VALUE;
}
case 8: break;
case 5:
{ yybegin(WAITING_VALUE); return SimpleTypes.SEPARATOR;
case 8:
break;
case 5: {
yybegin(WAITING_VALUE);
return SimpleTypes.SEPARATOR;
}
case 9: break;
case 4:
{ yybegin(YYINITIAL); return SimpleTypes.COMMENT;
case 9:
break;
case 4: {
yybegin(YYINITIAL);
return SimpleTypes.COMMENT;
}
case 10: break;
case 3:
{ return TokenType.BAD_CHARACTER;
case 10:
break;
case 3: {
return TokenType.BAD_CHARACTER;
}
case 11: break;
case 2:
{ yybegin(YYINITIAL); return TokenType.WHITE_SPACE;
case 11:
break;
case 2: {
yybegin(YYINITIAL);
return TokenType.WHITE_SPACE;
}
case 12: break;
case 7:
{ yybegin(WAITING_VALUE); 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 13:
break;
case 1: {
yybegin(YYINITIAL);
return SimpleTypes.KEY;
}
case 14: break;
case 14:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
zzDoEOF();
return null;
}
else {
} else {
zzScanError(ZZ_NO_MATCH);
}
}

View File

@ -14,7 +14,8 @@ import java.util.List;
public class SimpleLineMarkerProvider extends RelatedItemLineMarkerProvider {
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
protected void collectNavigationMarkers(@NotNull PsiElement element,
Collection<? super RelatedItemLineMarkerInfo> result) {
if (element instanceof PsiLiteralExpression) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;

View File

@ -21,7 +21,8 @@ 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.<SimpleLanguage>findInstance(SimpleLanguage.class));
public static final IFileElementType FILE =
new IFileElementType(Language.<SimpleLanguage>findInstance(SimpleLanguage.class));
@NotNull
@Override

View File

@ -13,11 +13,15 @@ public class SimpleReferenceContributor extends PsiReferenceContributor {
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext
context) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
String value = literalExpression.getValue() instanceof String ? (String)literalExpression.getValue() : null;
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 new PsiReference[]{
new SimpleReference(element, new TextRange(8, value.length() + 1))};
}
return PsiReference.EMPTY_ARRAY;
}

View File

@ -13,11 +13,16 @@ 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};

View File

@ -18,7 +18,8 @@ import java.util.List;
public class SimpleUtil {
public static List<SimpleProperty> findProperties(Project project, String key) {
List<SimpleProperty> result = null;
Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
Collection<VirtualFile> virtualFiles =
FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
GlobalSearchScope.allScope(project));
for (VirtualFile virtualFile : virtualFiles) {
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);
@ -41,7 +42,8 @@ public class SimpleUtil {
public static List<SimpleProperty> findProperties(Project project) {
List<SimpleProperty> result = new ArrayList<SimpleProperty>();
Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
Collection<VirtualFile> virtualFiles =
FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
GlobalSearchScope.allScope(project));
for (VirtualFile virtualFile : virtualFiles) {
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);

View File

@ -9,7 +9,6 @@ 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.*;

View File

@ -1,11 +1,35 @@
public class Test {
public static void main(String[] args)<fold text=' { '> {
public static void main(String[] args)
<fold text=' { '>
{
</fold > System.out.println("<fold text='http://en.wikipedia.org/'>simple:website</fold>");<fold text = ' }' >
}</fold>
public static void main1(String[] args)<fold text=' { '> {
</fold>System.out.println("<fold text='This is the value that could be looked up with the key \"key with spaces\".'>simple:key with spaces</fold>");<fold text=' }'>
}</fold>
public static void main2(String[] args)<fold text=' { '> {
</fold>System.out.println("<fold text='Welcome to \n Wikipedia!'>simple:message</fold>");<fold text=' }'>
}</fold>
}
</fold>
public static void main1(String[] args)
<fold text=' { '>
{
</fold > System.out.println(
"<fold text='This is the value that could be looked up with the key \"key with spaces\".'>simple:key with " +
"spaces</fold>");<
fold text = ' }' >
}
</fold>
public static void main2(String[] args)
<fold text=' { '>
{
</fold > System.out.println("<fold text='Welcome to \n Wikipedia!'>simple:message</fold>");<
fold text = ' }' >
}
</fold>
}

View File

@ -55,7 +55,8 @@ public class MyToolWindowFactory implements ToolWindowFactory {
// 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)));
+ 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;

View File

@ -18,7 +18,9 @@ import java.util.Collection;
public class TextOnlyTreeStructureProvider implements TreeStructureProvider {
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent,
@NotNull Collection<AbstractTreeNode> children,
ViewSettings settings) {
ArrayList<AbstractTreeNode> nodes = new ArrayList<AbstractTreeNode>();
for (AbstractTreeNode child : children) {
if (child instanceof PsiFileNode) {