1 | package com.framsticks.framclipse.editors.folding; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | |
---|
5 | import org.eclipse.jface.text.IDocument; |
---|
6 | import org.eclipse.jface.text.source.projection.ProjectionAnnotation; |
---|
7 | |
---|
8 | import com.framsticks.framclipse.internal.parser.ASTCodeSection; |
---|
9 | import com.framsticks.framclipse.internal.parser.ASTFunction; |
---|
10 | import com.framsticks.framclipse.internal.parser.ASTProperty; |
---|
11 | import com.framsticks.framclipse.internal.parser.ElementWithOffset; |
---|
12 | |
---|
13 | |
---|
14 | public class FramclipseFoldingAnnotation extends ProjectionAnnotation |
---|
15 | { |
---|
16 | ElementWithOffset annotatedElement; |
---|
17 | |
---|
18 | public FramclipseFoldingAnnotation(ElementWithOffset element) |
---|
19 | { |
---|
20 | this.annotatedElement = element; |
---|
21 | } |
---|
22 | |
---|
23 | public ElementWithOffset getAnnotatedElement() |
---|
24 | { |
---|
25 | return annotatedElement; |
---|
26 | } |
---|
27 | |
---|
28 | public int getAnnotationLength() |
---|
29 | { |
---|
30 | int defaultLen = annotatedElement.getEndOffset() - annotatedElement.getBeginOffset() + 1; |
---|
31 | |
---|
32 | int lineSepLen = System.getProperty("line.separator").length(); |
---|
33 | |
---|
34 | if(annotatedElement instanceof ASTFunction) |
---|
35 | return defaultLen + lineSepLen; |
---|
36 | |
---|
37 | if(annotatedElement instanceof ASTProperty) |
---|
38 | return defaultLen + lineSepLen; |
---|
39 | |
---|
40 | if(annotatedElement instanceof ASTCodeSection) |
---|
41 | return defaultLen + lineSepLen; |
---|
42 | |
---|
43 | return defaultLen; |
---|
44 | } |
---|
45 | |
---|
46 | public boolean isEquivalent(FramclipseFoldingAnnotation annot, IDocument doc) |
---|
47 | { |
---|
48 | return annotatedElement.isEquivalent(annot.annotatedElement, doc); |
---|
49 | |
---|
50 | } |
---|
51 | |
---|
52 | public FramclipseFoldingAnnotation hasEquivalent(List<FramclipseFoldingAnnotation> list, IDocument doc) |
---|
53 | { |
---|
54 | for(FramclipseFoldingAnnotation annot : list) |
---|
55 | if(annot.isEquivalent(this, doc)) |
---|
56 | return annot; |
---|
57 | |
---|
58 | return null; |
---|
59 | } |
---|
60 | } |
---|