This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 217730
Collapse All | Expand All

(-)a/editor.bracesmatching/apichanges.xml (+16 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        
111
        <change id="brace.context">
112
            <summary>Semantic context can be provided for a brace</summary>
113
            <version major="1" minor="30"/>
114
            <date day="6" month="5" year="2013"/>
115
            <author login="sdedic"/>
116
            <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible"/>
117
            <description>
118
                The brace tooltip may need to display additional text, if for example if-condition spans multiple lines,
119
                or for an else-branch, where the important information (if-condition text) is located elsewhere. BraceMatcher
120
                can implement the optional mixin BraceMatcher.ContextLocator and provide boundaries for this additional text.
121
            </description>
122
            <class package="org.netbeans.spi.editor.bracesmatching" name="BracesMatcher"/>
123
            <class package="org.netbeans.spi.editor.bracesmatching" name="BraceContext"/>
124
            <issue number="217730"/>
125
        </change>
110
126
111
        <change id="document.locking.changed">
127
        <change id="document.locking.changed">
112
            <summary>Document locking changed</summary>
128
            <summary>Document locking changed</summary>
(-)a/editor.bracesmatching/nbproject/project.properties (-1 / +1 lines)
Lines 3-9 Link Here
3
javadoc.arch=${basedir}/arch.xml
3
javadoc.arch=${basedir}/arch.xml
4
javadoc.apichanges=${basedir}/apichanges.xml
4
javadoc.apichanges=${basedir}/apichanges.xml
5
5
6
spec.version.base=1.29.0
6
spec.version.base=1.30.0
7
test.config.stableBTD.includes=**/*Test.class
7
test.config.stableBTD.includes=**/*Test.class
8
test.config.stableBTD.excludes=\
8
test.config.stableBTD.excludes=\
9
    **/MasterMatcherTest.class
9
    **/MasterMatcherTest.class
(-)a/editor.bracesmatching/src/org/netbeans/spi/editor/bracesmatching/BraceContext.java (+141 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.editor.bracesmatching;
43
44
import javax.swing.text.Position;
45
46
/**
47
 * Provides context information for a single brace. The brace may be preceded or followed
48
 * by a semantically connected text, such as `if' statement or `while' statement in a do-while
49
 * loop in Java. Such text may be displayed as a context for the brace highlight. The marked text
50
 * should include the brace sign itself.
51
 * <p/>
52
 * It may be necessary to provide a completely unrelated context, such is in the example
53
 * of if-else statement. The 'else' does not provide enough information itself as it is 
54
 * just a negation of earlier condition. Such related piece of text can be reported as 'related' 
55
 * BraceContext instance. Note that <i>related</b> instances may be chained - see the example below.
56
 * <p/>
57
 * The infrastructure uses the provided information to present the context to the user. If 
58
 * a 'related' positions are present the infrastructure will attempt to present the source
59
 * on the 'context' and 'related' positions in the source text order (e.g. displays portion of the document);
60
 * contents between 'context' and 'related' positions may be suppressed.
61
 * <p/>
62
 * An example of context and related areas for Java (PHP) if-elseif-else, with the origin t
63
 * <code><pre>
64
 *  //  vvvvvvvvvvvvvvvvv -- related
65
 *      if (condition1) {
66
 *  //  vvvvvvvvvvvvvvvvvvvvvvvvvvv -- related
67
 *      } else if (elsecondition) {
68
 *      ...
69
 *      } else {
70
 *  //    ^^^^^^ -- context
71
 *      ...
72
 *      }
73
 * //   ^ -- origin/caret location
74
 * </pre></code>
75
 * @author sdedic
76
 */
77
public final class BraceContext {
78
    /**
79
     * @return Starting position of the context text content
80
     */
81
    public Position getOpenContextStart() {
82
        return start;
83
    }
84
85
    /**
86
     * @return Ending position of the context text content
87
     */
88
    public Position getCloseContextEnd() {
89
        return end;
90
    }
91
92
    /**
93
     * @return the related range, or {@code null} for none.
94
     */
95
    public BraceContext getRelated() {
96
        return related;
97
    }
98
99
    /**
100
     * Creates a new BraceContext related to this one.
101
     * 
102
     * @param start start of the contextual text
103
     * @param end end of the text 
104
     * @return the new instance of BraceContext
105
     */
106
    public BraceContext createRelated(Position start, Position end) {
107
        return new BraceContext(start, end, this);
108
    }
109
    
110
    /**
111
     * Creates a new context area for the brace.
112
     * @param start start of the text
113
     * @param end end of the text
114
     * @return a new instance of BraceContext
115
     */
116
    public static BraceContext create(Position start, Position end) {
117
        return new BraceContext(start, end, null);
118
    }
119
    
120
    /**
121
     * Start of the related text
122
     */
123
    private final Position start;
124
    
125
    /**
126
     * End of the related text
127
     */
128
    private final Position end;
129
    
130
    /**
131
     * The related area(s)
132
     */
133
    private final BraceContext related;
134
135
    private BraceContext(Position openContextStart, Position closeContextEnd,
136
            BraceContext related) {
137
        this.start = openContextStart;
138
        this.end = closeContextEnd;
139
        this.related = related;
140
    }
141
}
(-)a/editor.bracesmatching/src/org/netbeans/spi/editor/bracesmatching/BracesMatcher.java (+21 lines)
Lines 44-49 Link Here
44
package org.netbeans.spi.editor.bracesmatching;
44
package org.netbeans.spi.editor.bracesmatching;
45
45
46
import javax.swing.text.BadLocationException;
46
import javax.swing.text.BadLocationException;
47
import javax.swing.text.Position;
47
48
48
/**
49
/**
49
 * The common interface for all matchers. Implementations of this interface
50
 * The common interface for all matchers. Implementations of this interface
Lines 168-171 Link Here
168
     * @throws javax.swing.text.BadLocationException If a document operation fails.
169
     * @throws javax.swing.text.BadLocationException If a document operation fails.
169
     */
170
     */
170
    public int [] findMatches() throws InterruptedException, BadLocationException;
171
    public int [] findMatches() throws InterruptedException, BadLocationException;
172
    
173
    /**
174
     * Mixin interface, which provides context ranges for brace matches.
175
     * The interface is expected to be implemented on the {@link BracesMatcher} instances
176
     * produced by {@link BracesMatcherFactory}. If implemented, the infrastructure may
177
     * call the method to obtain additional context for display along with brace highlight. 
178
     * See the {@link BraceContext} for more information.
179
     */
180
    public interface ContextLocator {
181
        /**
182
         * Obtains context for the given text position. At this moment, only start offset
183
         * of the origin will be passed in, but the implementation should be prepared to
184
         * handle (or ignore) each of the starting offsets reported by {@link #findOrigin()} or 
185
         * {@link #findMatches()}.
186
         * 
187
         * @param originOrMatchPosition position of 'origin' or 'match' brace
188
         * @return context information or {@code null} if the context cannot be provided.
189
         */
190
        public BraceContext findContext(int originOrMatchPosition);
191
    }
171
}
192
}

Return to bug 217730