mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
Code samples: Change the CONTINUATION_INDENT_SIZE from 8 to 4 and reformat code.
We use INDENT_SIZE = 2 and continuation size should be at most 4 in this case.
This commit is contained in:
parent
436664b23f
commit
c37b34729e
1
.idea/codeStyles/Project.xml
generated
1
.idea/codeStyles/Project.xml
generated
@ -19,6 +19,7 @@
|
|||||||
<option name="WRAP_ON_TYPING" value="0" />
|
<option name="WRAP_ON_TYPING" value="0" />
|
||||||
<indentOptions>
|
<indentOptions>
|
||||||
<option name="INDENT_SIZE" value="2" />
|
<option name="INDENT_SIZE" value="2" />
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||||
<option name="TAB_SIZE" value="2" />
|
<option name="TAB_SIZE" value="2" />
|
||||||
</indentOptions>
|
</indentOptions>
|
||||||
</codeStyleSettings>
|
</codeStyleSettings>
|
||||||
|
@ -58,8 +58,8 @@ public class ComparingStringReferencesInspection extends AbstractBaseJavaLocalIn
|
|||||||
if (isStringType(lOperand) || isStringType(rOperand)) {
|
if (isStringType(lOperand) || isStringType(rOperand)) {
|
||||||
// Identified an expression with potential problems, register problem with the quick fix object
|
// Identified an expression with potential problems, register problem with the quick fix object
|
||||||
holder.registerProblem(expression,
|
holder.registerProblem(expression,
|
||||||
InspectionBundle.message("inspection.comparing.string.references.problem.descriptor"),
|
InspectionBundle.message("inspection.comparing.string.references.problem.descriptor"),
|
||||||
myQuickFix);
|
myQuickFix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ public class ComparingStringReferencesInspection extends AbstractBaseJavaLocalIn
|
|||||||
|
|
||||||
private static boolean isNullLiteral(PsiExpression expression) {
|
private static boolean isNullLiteral(PsiExpression expression) {
|
||||||
return expression instanceof PsiLiteralExpression &&
|
return expression instanceof PsiLiteralExpression &&
|
||||||
((PsiLiteralExpression) expression).getValue() == null;
|
((PsiLiteralExpression) expression).getValue() == null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public class ComparingStringReferencesInspection extends AbstractBaseJavaLocalIn
|
|||||||
|
|
||||||
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||||
PsiMethodCallExpression equalsCall =
|
PsiMethodCallExpression equalsCall =
|
||||||
(PsiMethodCallExpression) factory.createExpressionFromText("a.equals(b)", null);
|
(PsiMethodCallExpression) factory.createExpressionFromText("a.equals(b)", null);
|
||||||
|
|
||||||
PsiExpression qualifierExpression = equalsCall.getMethodExpression().getQualifierExpression();
|
PsiExpression qualifierExpression = equalsCall.getMethodExpression().getQualifierExpression();
|
||||||
assert qualifierExpression != null;
|
assert qualifierExpression != null;
|
||||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
public class ComparingStringReferencesInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
public class ComparingStringReferencesInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||||
|
|
||||||
private static final String QUICK_FIX_NAME =
|
private static final String QUICK_FIX_NAME =
|
||||||
InspectionBundle.message("inspection.comparing.string.references.use.quickfix");
|
InspectionBundle.message("inspection.comparing.string.references.use.quickfix");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
@ -41,7 +41,7 @@ public class EditorAreaIllustration extends AnAction {
|
|||||||
int caretOffset = primaryCaret.getOffset();
|
int caretOffset = primaryCaret.getOffset();
|
||||||
// Build and display the caret report.
|
// Build and display the caret report.
|
||||||
String report = logicalPos + "\n" + visualPos + "\n" +
|
String report = logicalPos + "\n" + visualPos + "\n" +
|
||||||
"Offset: " + caretOffset;
|
"Offset: " + caretOffset;
|
||||||
Messages.showInfoMessage(report, "Caret Parameters Inside The Editor");
|
Messages.showInfoMessage(report, "Caret Parameters Inside The Editor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class EditorHandlerIllustration extends AnAction {
|
|||||||
final EditorActionManager actionManager = EditorActionManager.getInstance();
|
final EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||||
// Get the action handler registered to clone carets
|
// Get the action handler registered to clone carets
|
||||||
final EditorActionHandler actionHandler =
|
final EditorActionHandler actionHandler =
|
||||||
actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
||||||
// Clone one caret below the active caret
|
// Clone one caret below the active caret
|
||||||
actionHandler.execute(editor, editor.getCaretModel().getPrimaryCaret(), e.getDataContext());
|
actionHandler.execute(editor, editor.getCaretModel().getPrimaryCaret(), e.getDataContext());
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class EditorIllustrationAction extends AnAction {
|
|||||||
// Replace the selection with a fixed string.
|
// Replace the selection with a fixed string.
|
||||||
// Must do this document change in a write action context.
|
// Must do this document change in a write action context.
|
||||||
WriteCommandAction.runWriteCommandAction(project, () ->
|
WriteCommandAction.runWriteCommandAction(project, () ->
|
||||||
document.replaceString(start, end, "Replacement")
|
document.replaceString(start, end, "Replacement")
|
||||||
);
|
);
|
||||||
// De-select the text range that was just replaced
|
// De-select the text range that was just replaced
|
||||||
primaryCaret.removeSelection();
|
primaryCaret.removeSelection();
|
||||||
@ -67,7 +67,7 @@ public class EditorIllustrationAction extends AnAction {
|
|||||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||||
// Set visibility and enable only in case of existing project and editor and if a selection exists
|
// Set visibility and enable only in case of existing project and editor and if a selection exists
|
||||||
e.getPresentation().setEnabledAndVisible(
|
e.getPresentation().setEnabledAndVisible(
|
||||||
project != null && editor != null && editor.getSelectionModel().hasSelection()
|
project != null && editor != null && editor.getSelectionModel().hasSelection()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class DemoFacetConfiguration implements FacetConfiguration, PersistentSta
|
|||||||
@Override
|
@Override
|
||||||
public FacetEditorTab[] createEditorTabs(FacetEditorContext context, FacetValidatorsManager manager) {
|
public FacetEditorTab[] createEditorTabs(FacetEditorContext context, FacetValidatorsManager manager) {
|
||||||
return new FacetEditorTab[]{
|
return new FacetEditorTab[]{
|
||||||
new DemoFacetEditorTab(myFacetState, context, manager)
|
new DemoFacetEditorTab(myFacetState, context, manager)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import java.awt.*;
|
|||||||
* Manages validation and modification of the {@link DemoFacet} state.
|
* Manages validation and modification of the {@link DemoFacet} state.
|
||||||
*/
|
*/
|
||||||
public class DemoFacetEditorTab extends FacetEditorTab {
|
public class DemoFacetEditorTab extends FacetEditorTab {
|
||||||
|
|
||||||
private static final String FACET_PANEL_PROMPT = "Path To SDK: ";
|
private static final String FACET_PANEL_PROMPT = "Path To SDK: ";
|
||||||
|
|
||||||
private final DemoFacetState mySettings;
|
private final DemoFacetState mySettings;
|
||||||
@ -84,7 +85,7 @@ public class DemoFacetEditorTab extends FacetEditorTab {
|
|||||||
try {
|
try {
|
||||||
String newTextContent = myPath.getText();
|
String newTextContent = myPath.getText();
|
||||||
mySettings.setDemoFacetState(newTextContent);
|
mySettings.setDemoFacetState(newTextContent);
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ConfigurationException(e.toString());
|
throw new ConfigurationException(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class ProjectCloseListener implements ProjectManagerListener {
|
|||||||
|
|
||||||
// Get the counting service
|
// Get the counting service
|
||||||
ProjectCountingService projectCountingService =
|
ProjectCountingService projectCountingService =
|
||||||
ApplicationManager.getApplication().getService(ProjectCountingService.class);
|
ApplicationManager.getApplication().getService(ProjectCountingService.class);
|
||||||
// Decrement the count because a project just closed
|
// Decrement the count because a project just closed
|
||||||
projectCountingService.decreaseOpenProjectCount();
|
projectCountingService.decreaseOpenProjectCount();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class ProjectOpenStartupActivity implements StartupActivity.DumbAware {
|
|||||||
|
|
||||||
// Get the counting service
|
// Get the counting service
|
||||||
ProjectCountingService projectCountingService =
|
ProjectCountingService projectCountingService =
|
||||||
ApplicationManager.getApplication().getService(ProjectCountingService.class);
|
ApplicationManager.getApplication().getService(ProjectCountingService.class);
|
||||||
// Increment the project count
|
// Increment the project count
|
||||||
projectCountingService.increaseOpenProjectCount();
|
projectCountingService.increaseOpenProjectCount();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class ProjectOpenStartupActivity implements StartupActivity.DumbAware {
|
|||||||
String message = "<br>The number of open projects exceeds the SDK plugin max_opened_projects limit.<br><br>";
|
String message = "<br>The number of open projects exceeds the SDK plugin max_opened_projects limit.<br><br>";
|
||||||
|
|
||||||
ApplicationManager.getApplication().invokeLater(() ->
|
ApplicationManager.getApplication().invokeLater(() ->
|
||||||
Messages.showMessageDialog(project, message, title, Messages.getInformationIcon())
|
Messages.showMessageDialog(project, message, title, Messages.getInformationIcon())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ public class PopupDialogAction extends AnAction {
|
|||||||
public void actionPerformed(@NotNull AnActionEvent event) {
|
public void actionPerformed(@NotNull AnActionEvent event) {
|
||||||
Project project = event.getProject();
|
Project project = event.getProject();
|
||||||
Messages.showMessageDialog(project,
|
Messages.showMessageDialog(project,
|
||||||
"Popup dialog action",
|
"Popup dialog action",
|
||||||
"Greetings from PyCharm Basics Plugin",
|
"Greetings from PyCharm Basics Plugin",
|
||||||
Messages.getInformationIcon());
|
Messages.getInformationIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,7 +84,7 @@ public class LibrariesAction extends AnAction {
|
|||||||
fileAndLibs = "None";
|
fileAndLibs = "None";
|
||||||
}
|
}
|
||||||
Messages.showInfoMessage("Libraries for file: " + fileAndLibs,
|
Messages.showInfoMessage("Libraries for file: " + fileAndLibs,
|
||||||
"Libraries Info");
|
"Libraries Info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ public class ProjectFileIndexSampleAction extends AnAction {
|
|||||||
boolean isInLibraryClasses = projectFileIndex.isInLibraryClasses(virtualFile);
|
boolean isInLibraryClasses = projectFileIndex.isInLibraryClasses(virtualFile);
|
||||||
boolean isInLibrarySource = projectFileIndex.isInLibrarySource(virtualFile);
|
boolean isInLibrarySource = projectFileIndex.isInLibrarySource(virtualFile);
|
||||||
Messages.showInfoMessage("Module: " + moduleName + "\n" +
|
Messages.showInfoMessage("Module: " + moduleName + "\n" +
|
||||||
"Module content root: " + moduleContentRoot + "\n" +
|
"Module content root: " + moduleContentRoot + "\n" +
|
||||||
"Is library file: " + isLibraryFile + "\n" +
|
"Is library file: " + isLibraryFile + "\n" +
|
||||||
"Is in library classes: " + isInLibraryClasses +
|
"Is in library classes: " + isInLibraryClasses +
|
||||||
", Is in library source: " + isInLibrarySource,
|
", Is in library source: " + isInLibrarySource,
|
||||||
"Main File Info for" + virtualFile.getName());
|
"Main File Info for" + virtualFile.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ public class ShowSourceRootsActions extends AnAction {
|
|||||||
sourceRootsList.append(file.getUrl()).append("\n");
|
sourceRootsList.append(file.getUrl()).append("\n");
|
||||||
}
|
}
|
||||||
Messages.showInfoMessage(
|
Messages.showInfoMessage(
|
||||||
"Source roots for the " + projectName + " plugin:\n" + sourceRootsList.toString(),
|
"Source roots for the " + projectName + " plugin:\n" + sourceRootsList.toString(),
|
||||||
"Project Properties"
|
"Project Properties"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,9 +113,9 @@ public class ImagesProjectNode extends ProjectViewNode<VirtualFile> {
|
|||||||
getImagesFiles(project).clear();
|
getImagesFiles(project).clear();
|
||||||
scanImages(project);
|
scanImages(project);
|
||||||
ApplicationManager.getApplication().invokeLater(() ->
|
ApplicationManager.getApplication().invokeLater(() ->
|
||||||
ProjectView.getInstance(project)
|
ProjectView.getInstance(project)
|
||||||
.getProjectViewPaneById(ImagesProjectViewPane.ID)
|
.getProjectViewPaneById(ImagesProjectViewPane.ID)
|
||||||
.updateFromRoot(true),
|
.updateFromRoot(true),
|
||||||
project.getDisposed()
|
project.getDisposed()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,15 @@ public class PsiNavigationDemoAction extends AnAction {
|
|||||||
if (element != null) {
|
if (element != null) {
|
||||||
PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
|
PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
|
||||||
infoBuilder
|
infoBuilder
|
||||||
.append("Containing method: ")
|
.append("Containing method: ")
|
||||||
.append(containingMethod != null ? containingMethod.getName() : "none")
|
.append(containingMethod != null ? containingMethod.getName() : "none")
|
||||||
.append("\n");
|
.append("\n");
|
||||||
if (containingMethod != null) {
|
if (containingMethod != null) {
|
||||||
PsiClass containingClass = containingMethod.getContainingClass();
|
PsiClass containingClass = containingMethod.getContainingClass();
|
||||||
infoBuilder
|
infoBuilder
|
||||||
.append("Containing class: ")
|
.append("Containing class: ")
|
||||||
.append(containingClass != null ? containingClass.getName() : "none")
|
.append(containingClass != null ? containingClass.getName() : "none")
|
||||||
.append("\n");
|
.append("\n");
|
||||||
|
|
||||||
infoBuilder.append("Local variables:\n");
|
infoBuilder.append("Local variables:\n");
|
||||||
containingMethod.accept(new JavaRecursiveElementVisitor() {
|
containingMethod.accept(new JavaRecursiveElementVisitor() {
|
||||||
|
@ -24,7 +24,7 @@ public class DemoConfigurationFactory extends ConfigurationFactory {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public RunConfiguration createTemplateConfiguration(
|
public RunConfiguration createTemplateConfiguration(
|
||||||
@NotNull Project project) {
|
@NotNull Project project) {
|
||||||
return new DemoRunConfiguration(project, this, "Demo");
|
return new DemoRunConfiguration(project, this, "Demo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ public class DemoRunConfiguration extends RunConfigurationBase<DemoRunConfigurat
|
|||||||
@Override
|
@Override
|
||||||
protected ProcessHandler startProcess() throws ExecutionException {
|
protected ProcessHandler startProcess() throws ExecutionException {
|
||||||
GeneralCommandLine commandLine =
|
GeneralCommandLine commandLine =
|
||||||
new GeneralCommandLine(getOptions().getScriptName());
|
new GeneralCommandLine(getOptions().getScriptName());
|
||||||
OSProcessHandler processHandler = ProcessHandlerFactory.getInstance()
|
OSProcessHandler processHandler = ProcessHandlerFactory.getInstance()
|
||||||
.createColoredProcessHandler(commandLine);
|
.createColoredProcessHandler(commandLine);
|
||||||
ProcessTerminatedListener.attach(processHandler);
|
ProcessTerminatedListener.attach(processHandler);
|
||||||
return processHandler;
|
return processHandler;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import com.intellij.openapi.components.StoredProperty;
|
|||||||
public class DemoRunConfigurationOptions extends RunConfigurationOptions {
|
public class DemoRunConfigurationOptions extends RunConfigurationOptions {
|
||||||
|
|
||||||
private final StoredProperty<String> myScriptName =
|
private final StoredProperty<String> myScriptName =
|
||||||
string("").provideDelegate(this, "scriptName");
|
string("").provideDelegate(this, "scriptName");
|
||||||
|
|
||||||
public String getScriptName() {
|
public String getScriptName() {
|
||||||
return myScriptName.getValue(this);
|
return myScriptName.getValue(this);
|
||||||
|
@ -11,7 +11,7 @@ public class DemoRunConfigurationType extends ConfigurationTypeBase {
|
|||||||
|
|
||||||
protected DemoRunConfigurationType() {
|
protected DemoRunConfigurationType() {
|
||||||
super(ID, "Demo", "Demo run configuration type",
|
super(ID, "Demo", "Demo run configuration type",
|
||||||
NotNullLazyValue.createValue(() -> AllIcons.Nodes.Console));
|
NotNullLazyValue.createValue(() -> AllIcons.Nodes.Console));
|
||||||
addFactory(new DemoConfigurationFactory(this));
|
addFactory(new DemoConfigurationFactory(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@ public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
|||||||
public DemoSettingsEditor() {
|
public DemoSettingsEditor() {
|
||||||
scriptPathField = new TextFieldWithBrowseButton();
|
scriptPathField = new TextFieldWithBrowseButton();
|
||||||
scriptPathField.addBrowseFolderListener("Select Script File", null, null,
|
scriptPathField.addBrowseFolderListener("Select Script File", null, null,
|
||||||
FileChooserDescriptorFactory.createSingleFileDescriptor());
|
FileChooserDescriptorFactory.createSingleFileDescriptor());
|
||||||
myPanel = FormBuilder.createFormBuilder()
|
myPanel = FormBuilder.createFormBuilder()
|
||||||
.addLabeledComponent("Script file", scriptPathField)
|
.addLabeledComponent("Script file", scriptPathField)
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,10 +21,10 @@ public class AppSettingsComponent {
|
|||||||
|
|
||||||
public AppSettingsComponent() {
|
public AppSettingsComponent() {
|
||||||
myMainPanel = FormBuilder.createFormBuilder()
|
myMainPanel = FormBuilder.createFormBuilder()
|
||||||
.addLabeledComponent(new JBLabel("Enter user name: "), myUserNameText, 1, false)
|
.addLabeledComponent(new JBLabel("Enter user name: "), myUserNameText, 1, false)
|
||||||
.addComponent(myIdeaUserStatus, 1)
|
.addComponent(myIdeaUserStatus, 1)
|
||||||
.addComponentFillVertically(new JPanel(), 0)
|
.addComponentFillVertically(new JPanel(), 0)
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getPanel() {
|
public JPanel getPanel() {
|
||||||
|
@ -16,8 +16,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* these persistent application settings are stored.
|
* these persistent application settings are stored.
|
||||||
*/
|
*/
|
||||||
@State(
|
@State(
|
||||||
name = "org.intellij.sdk.settings.AppSettingsState",
|
name = "org.intellij.sdk.settings.AppSettingsState",
|
||||||
storages = @Storage("SdkSettingsPlugin.xml")
|
storages = @Storage("SdkSettingsPlugin.xml")
|
||||||
)
|
)
|
||||||
public class AppSettingsState implements PersistentStateComponent<AppSettingsState> {
|
public class AppSettingsState implements PersistentStateComponent<AppSettingsState> {
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ public class SimpleAnnotator implements Annotator {
|
|||||||
|
|
||||||
// highlight "simple" prefix and ":" separator
|
// highlight "simple" prefix and ":" separator
|
||||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||||
.range(prefixRange).textAttributes(DefaultLanguageHighlighterColors.KEYWORD).create();
|
.range(prefixRange).textAttributes(DefaultLanguageHighlighterColors.KEYWORD).create();
|
||||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||||
.range(separatorRange).textAttributes(SimpleSyntaxHighlighter.SEPARATOR).create();
|
.range(separatorRange).textAttributes(SimpleSyntaxHighlighter.SEPARATOR).create();
|
||||||
|
|
||||||
|
|
||||||
// Get the list of properties for given key
|
// Get the list of properties for given key
|
||||||
@ -53,15 +53,15 @@ public class SimpleAnnotator implements Annotator {
|
|||||||
List<SimpleProperty> properties = SimpleUtil.findProperties(element.getProject(), key);
|
List<SimpleProperty> properties = SimpleUtil.findProperties(element.getProject(), key);
|
||||||
if (properties.isEmpty()) {
|
if (properties.isEmpty()) {
|
||||||
holder.newAnnotation(HighlightSeverity.ERROR, "Unresolved property")
|
holder.newAnnotation(HighlightSeverity.ERROR, "Unresolved property")
|
||||||
.range(keyRange)
|
.range(keyRange)
|
||||||
.highlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
|
.highlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
|
||||||
// ** Tutorial step 19. - Add a quick fix for the string containing possible properties
|
// ** Tutorial step 19. - Add a quick fix for the string containing possible properties
|
||||||
.withFix(new SimpleCreatePropertyQuickFix(key))
|
.withFix(new SimpleCreatePropertyQuickFix(key))
|
||||||
.create();
|
.create();
|
||||||
} else {
|
} else {
|
||||||
// Found at least one property, force the text attributes to Simple syntax value character
|
// Found at least one property, force the text attributes to Simple syntax value character
|
||||||
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
|
||||||
.range(keyRange).textAttributes(SimpleSyntaxHighlighter.VALUE).create();
|
.range(keyRange).textAttributes(SimpleSyntaxHighlighter.VALUE).create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class SimpleBlock extends AbstractBlock {
|
|||||||
while (child != null) {
|
while (child != null) {
|
||||||
if (child.getElementType() != TokenType.WHITE_SPACE) {
|
if (child.getElementType() != TokenType.WHITE_SPACE) {
|
||||||
Block block = new SimpleBlock(child, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment(),
|
Block block = new SimpleBlock(child, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment(),
|
||||||
spacingBuilder);
|
spacingBuilder);
|
||||||
blocks.add(block);
|
blocks.add(block);
|
||||||
}
|
}
|
||||||
child = child.getTreeNext();
|
child = child.getTreeNext();
|
||||||
|
@ -25,7 +25,7 @@ public class SimpleChooseByNameContributor implements ChooseByNameContributorEx
|
|||||||
@Nullable IdFilter filter) {
|
@Nullable IdFilter filter) {
|
||||||
Project project = Objects.requireNonNull(scope.getProject());
|
Project project = Objects.requireNonNull(scope.getProject());
|
||||||
List<String> propertyKeys = ContainerUtil.map(
|
List<String> propertyKeys = ContainerUtil.map(
|
||||||
SimpleUtil.findProperties(project), SimpleProperty::getKey);
|
SimpleUtil.findProperties(project), SimpleProperty::getKey);
|
||||||
ContainerUtil.process(propertyKeys, processor);
|
ContainerUtil.process(propertyKeys, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ public class SimpleChooseByNameContributor implements ChooseByNameContributorEx
|
|||||||
@NotNull Processor<? super NavigationItem> processor,
|
@NotNull Processor<? super NavigationItem> processor,
|
||||||
@NotNull FindSymbolParameters parameters) {
|
@NotNull FindSymbolParameters parameters) {
|
||||||
List<NavigationItem> properties = ContainerUtil.map(
|
List<NavigationItem> properties = ContainerUtil.map(
|
||||||
SimpleUtil.findProperties(parameters.getProject(), name),
|
SimpleUtil.findProperties(parameters.getProject(), name),
|
||||||
property -> (NavigationItem) property);
|
property -> (NavigationItem) property);
|
||||||
ContainerUtil.process(properties, processor);
|
ContainerUtil.process(properties, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,10 @@ import java.util.Map;
|
|||||||
public class SimpleColorSettingsPage implements ColorSettingsPage {
|
public class SimpleColorSettingsPage implements ColorSettingsPage {
|
||||||
|
|
||||||
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
|
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
|
||||||
new AttributesDescriptor("Key", SimpleSyntaxHighlighter.KEY),
|
new AttributesDescriptor("Key", SimpleSyntaxHighlighter.KEY),
|
||||||
new AttributesDescriptor("Separator", SimpleSyntaxHighlighter.SEPARATOR),
|
new AttributesDescriptor("Separator", SimpleSyntaxHighlighter.SEPARATOR),
|
||||||
new AttributesDescriptor("Value", SimpleSyntaxHighlighter.VALUE),
|
new AttributesDescriptor("Value", SimpleSyntaxHighlighter.VALUE),
|
||||||
new AttributesDescriptor("Bad value", SimpleSyntaxHighlighter.BAD_CHARACTER)
|
new AttributesDescriptor("Bad value", SimpleSyntaxHighlighter.BAD_CHARACTER)
|
||||||
};
|
};
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -38,17 +38,17 @@ public class SimpleColorSettingsPage implements ColorSettingsPage {
|
|||||||
@Override
|
@Override
|
||||||
public String getDemoText() {
|
public String getDemoText() {
|
||||||
return "# You are reading the \".properties\" entry.\n" +
|
return "# You are reading the \".properties\" entry.\n" +
|
||||||
"! The exclamation mark can also mark text as comments.\n" +
|
"! The exclamation mark can also mark text as comments.\n" +
|
||||||
"website = https://en.wikipedia.org/\n" +
|
"website = https://en.wikipedia.org/\n" +
|
||||||
"language = English\n" +
|
"language = English\n" +
|
||||||
"# The backslash below tells the application to continue reading\n" +
|
"# The backslash below tells the application to continue reading\n" +
|
||||||
"# the value onto the next line.\n" +
|
"# the value onto the next line.\n" +
|
||||||
"message = Welcome to \\\n" +
|
"message = Welcome to \\\n" +
|
||||||
" Wikipedia!\n" +
|
" Wikipedia!\n" +
|
||||||
"# Add spaces to the key\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" +
|
"key\\ with\\ spaces = This is the value that could be looked up with the key \"key with spaces\".\n" +
|
||||||
"# Unicode\n" +
|
"# Unicode\n" +
|
||||||
"tab : \\u0009";
|
"tab : \\u0009";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -13,13 +13,13 @@ public class SimpleCompletionContributor extends CompletionContributor {
|
|||||||
|
|
||||||
public SimpleCompletionContributor() {
|
public SimpleCompletionContributor() {
|
||||||
extend(CompletionType.BASIC, PlatformPatterns.psiElement(SimpleTypes.VALUE),
|
extend(CompletionType.BASIC, PlatformPatterns.psiElement(SimpleTypes.VALUE),
|
||||||
new CompletionProvider<>() {
|
new CompletionProvider<>() {
|
||||||
public void addCompletions(@NotNull CompletionParameters parameters,
|
public void addCompletions(@NotNull CompletionParameters parameters,
|
||||||
@NotNull ProcessingContext context,
|
@NotNull ProcessingContext context,
|
||||||
@NotNull CompletionResultSet resultSet) {
|
@NotNull CompletionResultSet resultSet) {
|
||||||
resultSet.addElement(LookupElementBuilder.create("Hello"));
|
resultSet.addElement(LookupElementBuilder.create("Hello"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,15 +54,15 @@ class SimpleCreatePropertyQuickFix extends BaseIntentionAction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws
|
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws
|
||||||
IncorrectOperationException {
|
IncorrectOperationException {
|
||||||
ApplicationManager.getApplication().invokeLater(() -> {
|
ApplicationManager.getApplication().invokeLater(() -> {
|
||||||
Collection<VirtualFile> virtualFiles =
|
Collection<VirtualFile> virtualFiles =
|
||||||
FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project));
|
FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project));
|
||||||
if (virtualFiles.size() == 1) {
|
if (virtualFiles.size() == 1) {
|
||||||
createProperty(project, virtualFiles.iterator().next());
|
createProperty(project, virtualFiles.iterator().next());
|
||||||
} else {
|
} else {
|
||||||
final FileChooserDescriptor descriptor =
|
final FileChooserDescriptor descriptor =
|
||||||
FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
|
FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
|
||||||
descriptor.setRoots(ProjectUtil.guessProjectDir(project));
|
descriptor.setRoots(ProjectUtil.guessProjectDir(project));
|
||||||
final VirtualFile file1 = FileChooser.chooseFile(descriptor, project, null);
|
final VirtualFile file1 = FileChooser.chooseFile(descriptor, project, null);
|
||||||
if (file1 != null) {
|
if (file1 != null) {
|
||||||
|
@ -19,9 +19,9 @@ public class SimpleFindUsagesProvider implements FindUsagesProvider {
|
|||||||
@Override
|
@Override
|
||||||
public WordsScanner getWordsScanner() {
|
public WordsScanner getWordsScanner() {
|
||||||
return new DefaultWordsScanner(new SimpleLexerAdapter(),
|
return new DefaultWordsScanner(new SimpleLexerAdapter(),
|
||||||
SimpleTokenSets.IDENTIFIERS,
|
SimpleTokenSets.IDENTIFIERS,
|
||||||
SimpleTokenSets.COMMENTS,
|
SimpleTokenSets.COMMENTS,
|
||||||
TokenSet.EMPTY);
|
TokenSet.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,8 +58,8 @@ public class SimpleFindUsagesProvider implements FindUsagesProvider {
|
|||||||
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
|
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
|
||||||
if (element instanceof SimpleProperty) {
|
if (element instanceof SimpleProperty) {
|
||||||
return ((SimpleProperty) element).getKey() +
|
return ((SimpleProperty) element).getKey() +
|
||||||
SimpleAnnotator.SIMPLE_SEPARATOR_STR +
|
SimpleAnnotator.SIMPLE_SEPARATOR_STR +
|
||||||
((SimpleProperty) element).getValue();
|
((SimpleProperty) element).getValue();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -43,16 +43,16 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware
|
|||||||
if (value != null && value.startsWith(SimpleAnnotator.SIMPLE_PREFIX_STR + SimpleAnnotator.SIMPLE_SEPARATOR_STR)) {
|
if (value != null && value.startsWith(SimpleAnnotator.SIMPLE_PREFIX_STR + SimpleAnnotator.SIMPLE_SEPARATOR_STR)) {
|
||||||
Project project = literalExpression.getProject();
|
Project project = literalExpression.getProject();
|
||||||
String key = value.substring(
|
String key = value.substring(
|
||||||
SimpleAnnotator.SIMPLE_PREFIX_STR.length() + SimpleAnnotator.SIMPLE_SEPARATOR_STR.length()
|
SimpleAnnotator.SIMPLE_PREFIX_STR.length() + SimpleAnnotator.SIMPLE_SEPARATOR_STR.length()
|
||||||
);
|
);
|
||||||
// find SimpleProperty for the given key in the project
|
// find SimpleProperty for the given key in the project
|
||||||
SimpleProperty simpleProperty = ContainerUtil.getOnlyItem(SimpleUtil.findProperties(project, key));
|
SimpleProperty simpleProperty = ContainerUtil.getOnlyItem(SimpleUtil.findProperties(project, key));
|
||||||
if (simpleProperty != null) {
|
if (simpleProperty != null) {
|
||||||
// Add a folding descriptor for the literal expression at this node.
|
// Add a folding descriptor for the literal expression at this node.
|
||||||
descriptors.add(new FoldingDescriptor(literalExpression.getNode(),
|
descriptors.add(new FoldingDescriptor(literalExpression.getNode(),
|
||||||
new TextRange(literalExpression.getTextRange().getStartOffset() + 1,
|
new TextRange(literalExpression.getTextRange().getStartOffset() + 1,
|
||||||
literalExpression.getTextRange().getEndOffset() - 1),
|
literalExpression.getTextRange().getEndOffset() - 1),
|
||||||
group, Collections.singleton(simpleProperty)));
|
group, Collections.singleton(simpleProperty)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,10 +78,10 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
String key = text.substring(SimpleAnnotator.SIMPLE_PREFIX_STR.length() +
|
String key = text.substring(SimpleAnnotator.SIMPLE_PREFIX_STR.length() +
|
||||||
SimpleAnnotator.SIMPLE_SEPARATOR_STR.length());
|
SimpleAnnotator.SIMPLE_SEPARATOR_STR.length());
|
||||||
|
|
||||||
SimpleProperty simpleProperty = ContainerUtil.getOnlyItem(
|
SimpleProperty simpleProperty = ContainerUtil.getOnlyItem(
|
||||||
SimpleUtil.findProperties(psiLiteralExpression.getProject(), key)
|
SimpleUtil.findProperties(psiLiteralExpression.getProject(), key)
|
||||||
);
|
);
|
||||||
if (simpleProperty == null) {
|
if (simpleProperty == null) {
|
||||||
return StringUtil.THREE_DOTS;
|
return StringUtil.THREE_DOTS;
|
||||||
|
@ -11,22 +11,22 @@ public class SimpleFormattingModelBuilder implements FormattingModelBuilder {
|
|||||||
|
|
||||||
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
|
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
|
||||||
return new SpacingBuilder(settings, SimpleLanguage.INSTANCE)
|
return new SpacingBuilder(settings, SimpleLanguage.INSTANCE)
|
||||||
.around(SimpleTypes.SEPARATOR)
|
.around(SimpleTypes.SEPARATOR)
|
||||||
.spaceIf(settings.getCommonSettings(SimpleLanguage.INSTANCE.getID()).SPACE_AROUND_ASSIGNMENT_OPERATORS)
|
.spaceIf(settings.getCommonSettings(SimpleLanguage.INSTANCE.getID()).SPACE_AROUND_ASSIGNMENT_OPERATORS)
|
||||||
.before(SimpleTypes.PROPERTY)
|
.before(SimpleTypes.PROPERTY)
|
||||||
.none();
|
.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull FormattingModel createModel(@NotNull FormattingContext formattingContext) {
|
public @NotNull FormattingModel createModel(@NotNull FormattingContext formattingContext) {
|
||||||
final CodeStyleSettings codeStyleSettings = formattingContext.getCodeStyleSettings();
|
final CodeStyleSettings codeStyleSettings = formattingContext.getCodeStyleSettings();
|
||||||
return FormattingModelProvider
|
return FormattingModelProvider
|
||||||
.createFormattingModelForPsiFile(formattingContext.getContainingFile(),
|
.createFormattingModelForPsiFile(formattingContext.getContainingFile(),
|
||||||
new SimpleBlock(formattingContext.getNode(),
|
new SimpleBlock(formattingContext.getNode(),
|
||||||
Wrap.createWrap(WrapType.NONE, false),
|
Wrap.createWrap(WrapType.NONE, false),
|
||||||
Alignment.createAlignment(),
|
Alignment.createAlignment(),
|
||||||
createSpaceBuilder(codeStyleSettings)),
|
createSpaceBuilder(codeStyleSettings)),
|
||||||
codeStyleSettings);
|
codeStyleSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,18 +28,18 @@ public class SimpleLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe
|
|||||||
@Override
|
@Override
|
||||||
public String getCodeSample(@NotNull SettingsType settingsType) {
|
public String getCodeSample(@NotNull SettingsType settingsType) {
|
||||||
return "# You are reading the \".properties\" entry.\n" +
|
return "# You are reading the \".properties\" entry.\n" +
|
||||||
"! The exclamation mark can also mark text as comments.\n" +
|
"! The exclamation mark can also mark text as comments.\n" +
|
||||||
"website = https://en.wikipedia.org/\n" +
|
"website = https://en.wikipedia.org/\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"language = English\n" +
|
"language = English\n" +
|
||||||
"# The backslash below tells the application to continue reading\n" +
|
"# The backslash below tells the application to continue reading\n" +
|
||||||
"# the value onto the next line.\n" +
|
"# the value onto the next line.\n" +
|
||||||
"message = Welcome to \\\n" +
|
"message = Welcome to \\\n" +
|
||||||
" Wikipedia!\n" +
|
" Wikipedia!\n" +
|
||||||
"# Add spaces to the key\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" +
|
"key\\ with\\ spaces = This is the value that could be looked up with the key \"key with spaces\".\n" +
|
||||||
"# Unicode\n" +
|
"# Unicode\n" +
|
||||||
"tab : \\u0009";
|
"tab : \\u0009";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,22 +29,22 @@ public class SimpleLineMarkerProvider extends RelatedItemLineMarkerProvider {
|
|||||||
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element.getParent();
|
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element.getParent();
|
||||||
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
|
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
|
||||||
if ((value == null) ||
|
if ((value == null) ||
|
||||||
!value.startsWith(SimpleAnnotator.SIMPLE_PREFIX_STR + SimpleAnnotator.SIMPLE_SEPARATOR_STR)) {
|
!value.startsWith(SimpleAnnotator.SIMPLE_PREFIX_STR + SimpleAnnotator.SIMPLE_SEPARATOR_STR)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Simple language property usage
|
// Get the Simple language property usage
|
||||||
Project project = element.getProject();
|
Project project = element.getProject();
|
||||||
String possibleProperties = value.substring(
|
String possibleProperties = value.substring(
|
||||||
SimpleAnnotator.SIMPLE_PREFIX_STR.length() + SimpleAnnotator.SIMPLE_SEPARATOR_STR.length()
|
SimpleAnnotator.SIMPLE_PREFIX_STR.length() + SimpleAnnotator.SIMPLE_SEPARATOR_STR.length()
|
||||||
);
|
);
|
||||||
final List<SimpleProperty> properties = SimpleUtil.findProperties(project, possibleProperties);
|
final List<SimpleProperty> properties = SimpleUtil.findProperties(project, possibleProperties);
|
||||||
if (properties.size() > 0) {
|
if (properties.size() > 0) {
|
||||||
// Add the property to a collection of line marker info
|
// Add the property to a collection of line marker info
|
||||||
NavigationGutterIconBuilder<PsiElement> builder =
|
NavigationGutterIconBuilder<PsiElement> builder =
|
||||||
NavigationGutterIconBuilder.create(SimpleIcons.FILE)
|
NavigationGutterIconBuilder.create(SimpleIcons.FILE)
|
||||||
.setTargets(properties)
|
.setTargets(properties)
|
||||||
.setTooltipText("Navigate to Simple language property");
|
.setTooltipText("Navigate to Simple language property");
|
||||||
result.add(builder.createLineMarkerInfo(element));
|
result.add(builder.createLineMarkerInfo(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ public class SimpleReference extends PsiReferenceBase<PsiElement> implements Psi
|
|||||||
for (final SimpleProperty property : properties) {
|
for (final SimpleProperty property : properties) {
|
||||||
if (property.getKey() != null && property.getKey().length() > 0) {
|
if (property.getKey() != null && property.getKey().length() > 0) {
|
||||||
variants.add(LookupElementBuilder
|
variants.add(LookupElementBuilder
|
||||||
.create(property).withIcon(SimpleIcons.FILE)
|
.create(property).withIcon(SimpleIcons.FILE)
|
||||||
.withTypeText(property.getContainingFile().getName())
|
.withTypeText(property.getContainingFile().getName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,21 +16,21 @@ public class SimpleReferenceContributor extends PsiReferenceContributor {
|
|||||||
@Override
|
@Override
|
||||||
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
|
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
|
||||||
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class),
|
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class),
|
||||||
new PsiReferenceProvider() {
|
new PsiReferenceProvider() {
|
||||||
@Override
|
@Override
|
||||||
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element,
|
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element,
|
||||||
@NotNull ProcessingContext context) {
|
@NotNull ProcessingContext context) {
|
||||||
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
|
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
|
||||||
String value = literalExpression.getValue() instanceof String ?
|
String value = literalExpression.getValue() instanceof String ?
|
||||||
(String) literalExpression.getValue() : null;
|
(String) literalExpression.getValue() : null;
|
||||||
if ((value != null && value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR))) {
|
if ((value != null && value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR))) {
|
||||||
TextRange property = new TextRange(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length() + 1,
|
TextRange property = new TextRange(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length() + 1,
|
||||||
value.length() + 1);
|
value.length() + 1);
|
||||||
return new PsiReference[]{new SimpleReference(element, property)};
|
return new PsiReference[]{new SimpleReference(element, property)};
|
||||||
}
|
}
|
||||||
return PsiReference.EMPTY_ARRAY;
|
return PsiReference.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,63 +18,63 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class SimpleSpellcheckingStrategy extends SpellcheckingStrategy {
|
public class SimpleSpellcheckingStrategy extends SpellcheckingStrategy {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Tokenizer<?> getTokenizer(PsiElement element) {
|
||||||
|
if (element instanceof PsiComment) {
|
||||||
|
return new SimpleCommentTokenizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element instanceof SimpleProperty) {
|
||||||
|
return new SimplePropertyTokenizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EMPTY_TOKENIZER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SimpleCommentTokenizer extends Tokenizer<PsiComment> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Tokenizer<?> getTokenizer(PsiElement element) {
|
public void tokenize(@NotNull PsiComment element, TokenConsumer consumer) {
|
||||||
if (element instanceof PsiComment) {
|
// Exclude the start of the comment with its # characters from spell checking
|
||||||
return new SimpleCommentTokenizer();
|
int startIndex = 0;
|
||||||
|
for (char c : element.textToCharArray()) {
|
||||||
|
if (c == '#' || Character.isWhitespace(c)) {
|
||||||
|
startIndex++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (element instanceof SimpleProperty) {
|
consumer.consumeToken(element, element.getText(), false, 0,
|
||||||
return new SimplePropertyTokenizer();
|
TextRange.create(startIndex, element.getTextLength()),
|
||||||
}
|
CommentSplitter.getInstance());
|
||||||
|
|
||||||
return EMPTY_TOKENIZER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SimpleCommentTokenizer extends Tokenizer<PsiComment> {
|
}
|
||||||
|
|
||||||
@Override
|
private static class SimplePropertyTokenizer extends Tokenizer<SimpleProperty> {
|
||||||
public void tokenize(@NotNull PsiComment element, TokenConsumer consumer) {
|
|
||||||
// Exclude the start of the comment with its # characters from spell checking
|
|
||||||
int startIndex = 0;
|
|
||||||
for (char c : element.textToCharArray()) {
|
|
||||||
if (c == '#' || Character.isWhitespace(c)) {
|
|
||||||
startIndex++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
consumer.consumeToken(element, element.getText(), false, 0,
|
|
||||||
TextRange.create(startIndex, element.getTextLength()),
|
|
||||||
CommentSplitter.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public void tokenize(@NotNull SimpleProperty element, TokenConsumer consumer) {
|
||||||
|
//Spell check the keys and values of properties with different splitters
|
||||||
|
final ASTNode key = element.getNode().findChildByType(SimpleTypes.KEY);
|
||||||
|
if (key != null && key.getTextLength() > 0) {
|
||||||
|
final PsiElement keyPsi = key.getPsi();
|
||||||
|
final String text = key.getText();
|
||||||
|
//For keys, use a splitter for identifiers
|
||||||
|
//Note we set "useRename" to true so that keys will be properly refactored (renamed)
|
||||||
|
consumer.consumeToken(keyPsi, text, true, 0,
|
||||||
|
TextRange.allOf(text), IdentifierSplitter.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
final ASTNode value = element.getNode().findChildByType(SimpleTypes.VALUE);
|
||||||
|
if (value != null && value.getTextLength() > 0) {
|
||||||
|
final PsiElement valuePsi = value.getPsi();
|
||||||
|
final String text = valuePsi.getText();
|
||||||
|
//For values, use a splitter for plain text
|
||||||
|
consumer.consumeToken(valuePsi, text, false, 0,
|
||||||
|
TextRange.allOf(text), PlainTextSplitter.getInstance());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SimplePropertyTokenizer extends Tokenizer<SimpleProperty> {
|
}
|
||||||
|
|
||||||
public void tokenize(@NotNull SimpleProperty element, TokenConsumer consumer) {
|
|
||||||
//Spell check the keys and values of properties with different splitters
|
|
||||||
final ASTNode key = element.getNode().findChildByType(SimpleTypes.KEY);
|
|
||||||
if (key != null && key.getTextLength() > 0) {
|
|
||||||
final PsiElement keyPsi = key.getPsi();
|
|
||||||
final String text = key.getText();
|
|
||||||
//For keys, use a splitter for identifiers
|
|
||||||
//Note we set "useRename" to true so that keys will be properly refactored (renamed)
|
|
||||||
consumer.consumeToken(keyPsi, text, true, 0,
|
|
||||||
TextRange.allOf(text), IdentifierSplitter.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
final ASTNode value = element.getNode().findChildByType(SimpleTypes.VALUE);
|
|
||||||
if (value != null && value.getTextLength() > 0) {
|
|
||||||
final PsiElement valuePsi = value.getPsi();
|
|
||||||
final String text = valuePsi.getText();
|
|
||||||
//For values, use a splitter for plain text
|
|
||||||
consumer.consumeToken(valuePsi, text, false, 0,
|
|
||||||
TextRange.allOf(text), PlainTextSplitter.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,32 +13,33 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
public class SimpleStructureAwareNavbar extends StructureAwareNavBarModelExtension {
|
public class SimpleStructureAwareNavbar extends StructureAwareNavBarModelExtension {
|
||||||
@NotNull
|
|
||||||
@Override
|
@NotNull
|
||||||
protected Language getLanguage() {
|
@Override
|
||||||
return SimpleLanguage.INSTANCE;
|
protected Language getLanguage() {
|
||||||
|
return SimpleLanguage.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String getPresentableText(Object object) {
|
||||||
|
if (object instanceof SimpleFile) {
|
||||||
|
return ((SimpleFile) object).getName();
|
||||||
|
}
|
||||||
|
if (object instanceof SimpleProperty) {
|
||||||
|
return ((SimpleProperty) object).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return null;
|
||||||
public @Nullable String getPresentableText(Object object) {
|
}
|
||||||
if (object instanceof SimpleFile) {
|
|
||||||
return ((SimpleFile) object).getName();
|
|
||||||
}
|
|
||||||
if (object instanceof SimpleProperty) {
|
|
||||||
return ((SimpleProperty) object).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Icon getIcon(Object object) {
|
||||||
|
if (object instanceof SimpleProperty) {
|
||||||
|
return AllIcons.Nodes.Property;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return null;
|
||||||
@Nullable
|
}
|
||||||
public Icon getIcon(Object object) {
|
|
||||||
if (object instanceof SimpleProperty) {
|
|
||||||
return AllIcons.Nodes.Property;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class SimpleStructureViewModel extends StructureViewModelBase implements
|
public class SimpleStructureViewModel extends StructureViewModelBase implements
|
||||||
StructureViewModel.ElementInfoProvider {
|
StructureViewModel.ElementInfoProvider {
|
||||||
|
|
||||||
public SimpleStructureViewModel(@Nullable Editor editor, PsiFile psiFile) {
|
public SimpleStructureViewModel(@Nullable Editor editor, PsiFile psiFile) {
|
||||||
super(psiFile, editor, new SimpleStructureViewElement(psiFile));
|
super(psiFile, editor, new SimpleStructureViewElement(psiFile));
|
||||||
@ -39,4 +39,5 @@ public class SimpleStructureViewModel extends StructureViewModelBase implements
|
|||||||
protected Class<?> @NotNull [] getSuitableClasses() {
|
protected Class<?> @NotNull [] getSuitableClasses() {
|
||||||
return new Class[]{SimpleProperty.class};
|
return new Class[]{SimpleProperty.class};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,15 @@ import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAtt
|
|||||||
public class SimpleSyntaxHighlighter extends SyntaxHighlighterBase {
|
public class SimpleSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||||
|
|
||||||
public static final TextAttributesKey SEPARATOR =
|
public static final TextAttributesKey SEPARATOR =
|
||||||
createTextAttributesKey("SIMPLE_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
|
createTextAttributesKey("SIMPLE_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
|
||||||
public static final TextAttributesKey KEY =
|
public static final TextAttributesKey KEY =
|
||||||
createTextAttributesKey("SIMPLE_KEY", DefaultLanguageHighlighterColors.KEYWORD);
|
createTextAttributesKey("SIMPLE_KEY", DefaultLanguageHighlighterColors.KEYWORD);
|
||||||
public static final TextAttributesKey VALUE =
|
public static final TextAttributesKey VALUE =
|
||||||
createTextAttributesKey("SIMPLE_VALUE", DefaultLanguageHighlighterColors.STRING);
|
createTextAttributesKey("SIMPLE_VALUE", DefaultLanguageHighlighterColors.STRING);
|
||||||
public static final TextAttributesKey COMMENT =
|
public static final TextAttributesKey COMMENT =
|
||||||
createTextAttributesKey("SIMPLE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
|
createTextAttributesKey("SIMPLE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
|
||||||
public static final TextAttributesKey BAD_CHARACTER =
|
public static final TextAttributesKey BAD_CHARACTER =
|
||||||
createTextAttributesKey("SIMPLE_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
|
createTextAttributesKey("SIMPLE_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
|
||||||
|
|
||||||
|
|
||||||
private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
|
private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
|
||||||
|
@ -31,7 +31,7 @@ public class SimpleUtil {
|
|||||||
public static List<SimpleProperty> findProperties(Project project, String key) {
|
public static List<SimpleProperty> findProperties(Project project, String key) {
|
||||||
List<SimpleProperty> result = new ArrayList<>();
|
List<SimpleProperty> result = new ArrayList<>();
|
||||||
Collection<VirtualFile> virtualFiles =
|
Collection<VirtualFile> virtualFiles =
|
||||||
FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project));
|
FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project));
|
||||||
for (VirtualFile virtualFile : virtualFiles) {
|
for (VirtualFile virtualFile : virtualFiles) {
|
||||||
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);
|
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);
|
||||||
if (simpleFile != null) {
|
if (simpleFile != null) {
|
||||||
@ -51,7 +51,7 @@ public class SimpleUtil {
|
|||||||
public static List<SimpleProperty> findProperties(Project project) {
|
public static List<SimpleProperty> findProperties(Project project) {
|
||||||
List<SimpleProperty> result = new ArrayList<>();
|
List<SimpleProperty> result = new ArrayList<>();
|
||||||
Collection<VirtualFile> virtualFiles =
|
Collection<VirtualFile> virtualFiles =
|
||||||
FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project));
|
FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project));
|
||||||
for (VirtualFile virtualFile : virtualFiles) {
|
for (VirtualFile virtualFile : virtualFiles) {
|
||||||
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);
|
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);
|
||||||
if (simpleFile != null) {
|
if (simpleFile != null) {
|
||||||
@ -77,7 +77,7 @@ public class SimpleUtil {
|
|||||||
}
|
}
|
||||||
element = element.getPrevSibling();
|
element = element.getPrevSibling();
|
||||||
}
|
}
|
||||||
return StringUtil.join(Lists.reverse(result),"\n ");
|
return StringUtil.join(Lists.reverse(result), "\n ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,10 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
|
|||||||
CodeStyle.getLanguageSettings(myFixture.getFile()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
|
CodeStyle.getLanguageSettings(myFixture.getFile()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
|
||||||
CodeStyle.getLanguageSettings(myFixture.getFile()).KEEP_BLANK_LINES_IN_CODE = 2;
|
CodeStyle.getLanguageSettings(myFixture.getFile()).KEEP_BLANK_LINES_IN_CODE = 2;
|
||||||
WriteCommandAction.writeCommandAction(getProject()).run(() ->
|
WriteCommandAction.writeCommandAction(getProject()).run(() ->
|
||||||
CodeStyleManager.getInstance(getProject()).reformatText(
|
CodeStyleManager.getInstance(getProject()).reformatText(
|
||||||
myFixture.getFile(),
|
myFixture.getFile(),
|
||||||
ContainerUtil.newArrayList(myFixture.getFile().getTextRange())
|
ContainerUtil.newArrayList(myFixture.getFile().getTextRange())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
myFixture.checkResultByFile("DefaultTestData.simple");
|
myFixture.checkResultByFile("DefaultTestData.simple");
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
|
|||||||
|
|
||||||
public void testReference() {
|
public void testReference() {
|
||||||
PsiReference referenceAtCaret =
|
PsiReference referenceAtCaret =
|
||||||
myFixture.getReferenceAtCaretPositionWithAssertion("ReferenceTestData.java", "DefaultTestData.simple");
|
myFixture.getReferenceAtCaretPositionWithAssertion("ReferenceTestData.java", "DefaultTestData.simple");
|
||||||
final SimpleProperty resolvedSimpleProperty = assertInstanceOf(referenceAtCaret.resolve(), SimpleProperty.class);
|
final SimpleProperty resolvedSimpleProperty = assertInstanceOf(referenceAtCaret.resolve(), SimpleProperty.class);
|
||||||
assertEquals("https://en.wikipedia.org/", resolvedSimpleProperty.getValue());
|
assertEquals("https://en.wikipedia.org/", resolvedSimpleProperty.getValue());
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,8 @@ public class CalendarToolWindowFactory implements ToolWindowFactory, DumbAware {
|
|||||||
|
|
||||||
private String getCurrentDate(Calendar calendar) {
|
private String getCurrentDate(Calendar calendar) {
|
||||||
return calendar.get(Calendar.DAY_OF_MONTH) + "/"
|
return calendar.get(Calendar.DAY_OF_MONTH) + "/"
|
||||||
+ (calendar.get(Calendar.MONTH) + 1) + "/"
|
+ (calendar.get(Calendar.MONTH) + 1) + "/"
|
||||||
+ calendar.get(Calendar.YEAR);
|
+ calendar.get(Calendar.YEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTimeZone(Calendar calendar) {
|
private String getTimeZone(Calendar calendar) {
|
||||||
@ -102,5 +102,7 @@ public class CalendarToolWindowFactory implements ToolWindowFactory, DumbAware {
|
|||||||
public JPanel getContentPanel() {
|
public JPanel getContentPanel() {
|
||||||
return contentPanel;
|
return contentPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user