Posts

Showing posts with the label extends

Eclipse PDE: Everything about Editor Part 4

Auto-Edit Strategy This post of Everything About Editor series explains about editors auto complete feature. Auto edit feature of any editor helps developer while writing code, for example in java editor of eclipse provides auto complete features for string quotes , open braces etc. When you type open curly braces ‘{‘ , eclipse java editor auto inserts closing curly braces considering line and indentation. Here I am going to implement auto-edit strategy for open single , double quotes and opening curly braces ‘{‘. To use auto edits, you must implement the org.eclipse.jface.text.IAutoEditStrategy interface, which contains just one method: void customizeDocumentCommand(IDocument document,DocumentCommand command); This is called each time you make a change to the document with the DocumentCommand object containing the information about that change. So, adding indents or making any change to the text being changed is as simple as modifying the DocumentCommand object. 1. Implement IA...

Eclipse PDE: Everything about Editor Part 2

Document Partition In this series of “ Eclipse PDE: Everything about Editor ”, this post explains how to configure your document to represent different partition. Document partitions helps to manipulate different part of document in different way. For example there is not need to showing content assist in single line comment or multi line comment. Here I am explaining defining partition for single and multi line comments 1. Define a custom partition scanner Eclipse framework provides Rule based partition scanner, which allows us to define single or multi line rule for partitioning document content. We need to define Custome partition scanner extending org.eclipse.jface.text.rules.RuleBasedPartitionScanner . Override the constructor and define rules for partition . Below code snippets defines rule for single and multi line comments public class MyPartitionScanner extends RuleBasedPartitionScanner { //Define COnstants for supported partition types public static ...

Non-extendable Class

First thing comes in mind when somebody say Non-extendable class , that is final class. Marking a class as “final” , no one can extends the particular class. But there is another tricky way to restricting any other class from extending your class. Thinking how ….? Simple, marking all available constructors of  a class as private. As per constructor chaining principle in class hierarchy , every child class constructor should delegate call to super class explicitly or implicitly. In implicit case, call get delegate to class’s default constructor. If all available constructors of the class are private then no other class can not extend it. 1: public class MyClass { 2: 3: private MyClass(){ 4: System.out.println(" Inside Singleton Constructor "); 5: } 6: 7: } 8: 9: class MyChildClass extends MyClass{ // compilation error 10: 11: }