Removed some more warnings and cleaned more SWT listeners
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / asm / editor / AsmAutoEditStrategy.java
1 package net.mograsim.plugin.asm.editor;
2
3 import org.eclipse.jface.text.BadLocationException;
4 import org.eclipse.jface.text.DocumentCommand;
5 import org.eclipse.jface.text.IAutoEditStrategy;
6 import org.eclipse.jface.text.IDocument;
7 import org.eclipse.jface.text.IRegion;
8
9 public class AsmAutoEditStrategy implements IAutoEditStrategy
10 {
11
12         @Override
13         public void customizeDocumentCommand(IDocument document, DocumentCommand command)
14         {
15                 if (!">".equals(command.text))
16                 { // NON-NLS-1
17                         return;
18                 }
19                 try
20                 {
21                         IRegion region = document.getLineInformationOfOffset(command.offset);
22                         String line = document.get(region.getOffset(), command.offset - region.getOffset());
23                         int index = line.lastIndexOf('<');
24                         if (index != -1 && (index != line.length() - 1) && line.charAt(index + 1) != '/')
25                         {
26                                 String tag = line.substring(index + 1);
27                                 command.caretOffset = command.offset + 1;
28                                 command.text += "</" + tag + command.text; // NON-NLS-1
29                                 command.shiftsCaret = false;
30                         }
31                 }
32                 catch (@SuppressWarnings("unused") BadLocationException e)
33                 {
34                         // ignore
35                 }
36         }
37
38 }