Invisible Marker in Eclipse - eclipse-plugin

I've got an unusual error and I might be missing something - I've written a test plugin that should simply show an error marker on the first line of a file. I'm using this code, triggered from a button press
public void createMarkerForResource(IResource resource) throws CoreException {
HashMap map = new HashMap();
MarkerUtilities.setLineNumber(map, 1);
MarkerUtilities.setMessage(map, "HAZARD");
map.put(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
MarkerUtilities.createMarker(resource, map, IMarker.TEXT);
}
The code appeared not to work - but on closer inspection something is happening. There is now a 'clickable' area on the ruler, but no icon...
Before:
After:
Any ideas?
(I'm aware there's a similar question - but it was self-solved and as we are using different approaches and getting different responses I thought it was worth opening this one up.)

As far as I can see, you define a org.eclipse.core.resources.textmarker.
But I cannot find a org.eclipse.ui.ide.markerImageProviders with an image for the marker type. So I simply believe, there are no image for this type.
Try using a different type of marker type, define your own marker type or define your own image for the textmarker marker type (not recommended).

Related

stop code formatting through modifying AST in Eclipse CDT

I am editing a cod pragmatically through editing the AST in Eclipse CDT, put after perform the refactor using Change#perform method, I found the code to be formatted, example here I am just cast a function call to be void
//Old code
Publish(Author_id, Content);
//New code
(void) Publish(
Author_id,
Content);
As you see the method has been formatted to be in 3 lines, how to stop this action?
My code sample that do refactoring
INodeFactory factory = ast.getASTNodeFactory();
IASTNode newNode = rewriter.createLiteralNode("( void )"+selectedNode.getRawSignature());
rewriter.replace(selectedNode, newNode, null);
Change change = rewriter.rewriteAST();
change = change.perform(new NullProgressMonitor());
I believe you have two options:
Configure CDT's built-in formatter to format the code the way you like it. In this case, based on the appearance of the "New code", it looks like Line Wrapping -> Function calls -> Arguments -> Line wrapping policy is set to one of the "Wrap all elements" options. You can change it to something you like better.
Implement the org.eclipse.cdt.core.CodeFormatter extension point to provide an alternative formatter that behaves differently from the default code formatter (for example, it could do nothing).
UPDATE: I don't know where to find an example of this, but assuming you're familiar with implementing Eclipse extension points in general, here is the reference for this one. The steps would be:
Write a class that extends org.eclipse.cdt.core.formatter.CodeFormatter and implements the format() method
Ad an <extension ...> tag to your plugin's plugin.xml referencing your class

Intellij Scala Formatter places annotation and method definition in same

I am having problem similar to Intellij Formatter keeps moving method level annotation and method signature in one line.
My annotation and method definition is getting formatted in the same line. As these are two entities, should come in different lines.
Eg,
#Test
public void testMethod(){
..............
}
IntelliJ keeps changing above code to:
#Test public void testMethod(){
..............
}
I tried the same thing which is suggested in the above post, but problem with 'Keep when reformatting , checkbox Line breaks', is it keeps the line breaks everywhere. Lets say I have one long line
input.get(someVariableInput1, someVariableInput2, someVariableInput3, someVariableInput4,
And hit enter after this:
someVariableInput5, someVariableInput6);
And if we format it, it will format in following way:
input.get(someVariableInput1, someVariableInput2, someVariableInput3,
someVariableInput4,
someVariableInput5, someVariableInput6);
Which I don't want. Can someone please help here? Thanks in advance.

dojo.place how to pass parameter without surrounding HTML?

I'd like to do something like this:
dojo.place(this.message.subject, this.apSubject);
But it throw exception in Dojo 1.7 (I'm completely new to Dojo so I don't know if the same problem is under older versions)
To get it work I did:
dojo.place('<span>' + this.message.subject + '</span>', this.apSubject);
It looks like Dojo parse the first parameter of dojo.place and if there is no HTML it throw exception.
How to use it without spans?
Check the docs, In particular, the description of what the first argument receives:
dojo.place(node, refNode, pos)
node
Can be a String or a DOM node. If it is a string starting with “<”, it is assumed to be an HTML fragment, which will be created. Otherwise it is assumed to be an id of a DOM node.
Therefore, one things you can do is create a text node with the text you want
dojo.place( document.createTextNode(this.message.subject), this.apSubject)
And another thing you could try would be setting the innerHTML instead of using dojo.place:
this.apSubject.innerHTML = this.message.subject;
BTW, In my humble opinion, dojo.place is normaly kind of annoying to use. However, since I am not often doing this kind of DOM manipulation, I don't really know what are the alternatives people prefer to use.

How to use the data store to set a toolbar title in Sencha Touch

I am trying to set the toolbar item dynamically. So far I have a back button that resets the toolbar title to 'start' if the user chooses to go back.
But the following code won't work:
menuList.on('itemtap', function(dataView, index, item, e){
viewport.dockedItems.items[0].setTitle('{title}');
});
It tries to use a variable called 'title' out of my data store array. This works great for providing text to my Ext.List items. But the above code sets the toolbar title to the string '{title}' without even thinking of it being a variable.
Can you help me out?
List's use templates so items within curley braces get evaluated... you'll need to pass a reference to a variable without quotes. You haven't provided enough code for me to tell you where that information would be. If you already have a variable in scope called title that you put the data into then you can just reamove the '{ and }' ... otherwise you'll need to get the data you need from your store through some means, like Ext.StoreMgr or [appname].stores
Two things. 1) You will really want to get used to digging into the ST source code. In this case, if you look at the code for "setTitle", you will see that its argument is interpreted as straight HTML, not a template. So you can't use curly bracket syntax here. 2) Note that the type of the "item" argument to the event handler is an Element (i.e. ST's representation of the DOM object, not the selected datastore object. So that's not going to help you. However, the "index" arg gives you an easy way to get the appropriate object from the store. i.e.
[appname].stores.pages.getAt(index).title
I really don't know why, but it works if you put up to variables: One for the record and one for the value inside that record. There is a detailed explanation in the sencha.com-forum

Why does resolveBinding() return null even though I setResolveBindings(true) on my ASTParser?

I am writing an Eclipse plug-in that uses JDT AST's ASTParser to parse a method. I am looking within that method for the creation of a particular type of object.
When I find a ClassInstanceCreation, I call getType() on it to see what type is being instantiated. I want to be sure that the fully-resolved type being dealt with there is the one I think it is, so I tell the resultant Type object to resolveBinding(). I get null back even though there are no compilation errors and even though I called setResolveBindings(true) on my ASTParser. I gave my ASTParser (via setSource()) the ICompilationUnit that contains my method, so the parser has access to the entire workspace context.
final IMethod method = ...;
final ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setResolveBindings(true);
parser.setSource(method.getCompilationUnit());
parser.setSourceRange(method.getSourceRange().getOffset(), method.getSourceRange().getLength());
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
final TypeDeclaration astRoot = (TypeDeclaration) parser.createAST(null);
final ClassInstanceCreation classInstanceCreation = walkAstAndFindMyExpression(astRoot);
final Type instantiatedType = classInstanceCreation.getType();
System.out.println("BINDING: " + instantiatedType.resolveBinding());
Why does resolveBinding() return null? How can I get the binding information?
Tucked away at the bottom of the overview of ASTParser.setKind(), carefully hidden from people troubleshooting resolveBinding() and setResolveBindings(), is the statement
Binding information is only computed when kind is K_COMPILATION_UNIT.
(from the online Javadoc)
I don't understand offhand why this would be the case, but it does seem to point pretty clearly at what needs to be different!