Blog moved to The.Berlin.Factor
From now on I'll post new stuff at The.Berlin.Factor.
tfdj
I mean.. What I'm trying to say is.. In a way I think.. You know? In a world gone mad..
[SetUp]
public void Setup()
{
mocks = new MockRepository();
}
[Test]
public void CallMethodOnObject()
public void testCallMethodOnObject()
IDemo demo = (IDemo)mocks.CreateMock(typeof(IDemo));
@NotNull
public final String getDemoText()
@Nullable
public final StructureViewBuilder getStructureViewBuilder( final @NotNull VirtualFile file, final @NotNull Project project )
@NotNull
@NonNls
public final String getDefaultExtension()
public interface Something
{
public final ExtensionString getDefaultExtension();
}
public final class ExtensionString
{
public static final ExtensionString newInstance( final String aExtension )
{
if ( isValidAndCorrect( aExtension ) == false )
{
throw new YouSuckException( aExtension );
}
return new ExtensionString( aExtension )
}
(...)
// From Object
public final String toString()
{
return myExtension;
}
// Implementation Details
private ExtensionString( final String aExtension )
{
myExtension = aExtension;
}
private static final void isValidAndCorrect( final String aExtension )
{
(...)
}
private final String myExtension;
}
[SimpleSyntax:V1.0]I removed the dirty/incomplete parts.. :) Support for easier keyword specification, etc is still missing. For now only the "regex" rules are supported. Which is pretty clumsy for specifiying keywords..
Name: Ruby
Icon: simplesyntax_ruby.png
Description: Ruby Script File
ExampleCode: simplesyntax_ruby.rb
# Braces Configuration
Braces.Pairs: (),[]
Braces.Structural: {}
# Commenter Configuration
Comment.Line: #
Comment.BlockPrefix:
Comment.BlockSuffix:
# FileType Configuration
FileType.Icon: simplesyntax_ruby.png
FileType.Extensions: rb, ruby
FileType.DefaultExtension: rb
# Syntax Configuration
regex BLOCK_COMMENT => (?m)^(?:\s*#.*$){2,}
regex LINE_COMMENT => (?m)#.*$
(...)
regex SPECIAL_QUOTED_STRING => %[qQ](.).*\1
regex SINGLE_QUOTED_STRING => \'(?:[^\']|\\')*\'
regex DOUBLE_QUOTED_STRING => \"(?:[^\"]|\\")*\"
(...)
# Element Descriptions
descriptions[ BLOCK_COMMENT ] = Block comment
descriptions[ LINE_COMMENT ] = Line comment
descriptions[ DOC_COMMENT ] = Documentation
(...)
# Element Default Attributes
attributes[ BLOCK_COMMENT ] = #303030,BOLD,ITALIC
attributes[ LINE_COMMENT ] = #305030,BOLD,ITALIC
attributes[ DOC_COMMENT ] = #503030,BOLD,ITALIC
(...)
A more complex example for getting a container inside the event handler is presented below. In this example, the DataContext class is used for passing context references for the considered action. This class deserves special attention, and we will consider it in detail in another article devoted to actions and passing context parameters principles.And here's some following example code from this article:
public class MyAction extends AnAction {In context of my previous post, this is just another example of what I mean when I ask for more declarative APIs. Sure, I understand certain reasons for using "identifiers" to retrieve Objects from some kind of object container. And it may very well make absolute sense for the JetBrains guys to do it this way. But expose such an API? To a potential external plugin developer? Smells strange, doesn't it?
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Project project = (Project)dataContext.getData(DataConstants.PROJECT);
Module module = (Module)dataContext.getData(DataConstants.MODULE);
}
}
... {Of course, you can't have a million getThis, getThat, etc methods in the DataContext API. But is this a valid argument against a more declarative API? Or an argument for an ID-based "query-API"? I don't think so. All it means is, that something is not they way it should be.
project = dataContext.getProject();
module = dataContext.getModule();
...
}