Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions enterprise/web.el/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@
<specification-version>1.11</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.awt</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.98</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.filesystems</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,21 @@

import com.sun.el.parser.AstIdentifier;
import com.sun.el.parser.Node;
import com.sun.el.parser.NodeVisitor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.el.ELException;
import javax.lang.model.element.Element;
import org.netbeans.api.java.source.ClasspathInfo;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.Task;
import org.netbeans.modules.csl.api.ColoringAttributes;
import org.netbeans.modules.csl.api.OccurrencesFinder;
import org.netbeans.modules.csl.api.OffsetRange;
import org.netbeans.modules.parsing.spi.Parser.Result;
import org.netbeans.modules.parsing.spi.Scheduler;
import org.netbeans.modules.parsing.spi.SchedulerEvent;
import org.netbeans.modules.web.el.options.MarkOccurencesSettings;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions;
import org.openide.util.Pair;
Expand All @@ -49,7 +45,7 @@
*
* @author Erno Mononen
*/
final class ELOccurrencesFinder extends OccurrencesFinder {
final class ELOccurrencesFinder extends OccurrencesFinder<ELParserResult> {

private int caretPosition;
private boolean cancelled;
Expand All @@ -64,17 +60,17 @@ public void setCaretPosition(int position) {
}

@Override
public Map getOccurrences() {
public Map<OffsetRange, ColoringAttributes> getOccurrences() {
return occurrences;
}

@Override
public void run(Result result, SchedulerEvent event) {
public void run(ELParserResult result, SchedulerEvent event) {
occurrences.clear();
if (checkAndResetCancel()) {
return;
}
computeOccurrences((ELParserResult) result);
computeOccurrences(result);
}

@Override
Expand All @@ -92,6 +88,20 @@ public void cancel() {
this.cancelled = true;
}

@Override
public boolean isKeepMarks() {
return MarkOccurencesSettings
.getCurrentNode()
.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true);
}

@Override
public boolean isMarkOccurrencesEnabled() {
return MarkOccurencesSettings
.getCurrentNode()
.getBoolean(MarkOccurencesSettings.ON_OFF, true);
}

private void computeOccurrences(final ELParserResult parserResult) {
ELElement current = parserResult.getElementAt(caretPosition);
if (current == null) {
Expand All @@ -111,33 +121,24 @@ private void computeOccurrences(final ELParserResult parserResult) {
if (!eLElement.isValid()) {
continue;
}
eLElement.getNode().accept(new NodeVisitor() {

@Override
public void visit(Node node) throws ELException {
if (node.getClass().equals(targetNode.getClass())
&& targetNode.getImage().equals(node.getImage())) {
matching.add(Pair.of(eLElement, node));
}
eLElement.getNode().accept((Node node) -> {
if (node.getClass().equals(targetNode.getClass())
&& targetNode.getImage().equals(node.getImage())) {
matching.add(Pair.of(eLElement, node));
}
});
}
final FileObject file = parserResult.getFileObject();
JavaSource jsource = JavaSource.create(ELTypeUtilities.getElimplExtendedCPI(file));
try {
jsource.runUserActionTask(new Task<CompilationController>() {

@Override
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.RESOLVED);
occurrences.putAll(findMatchingTypes(CompilationContext.create(file, info), parserResult, target, matching));

}
jsource.runUserActionTask((CompilationController info) -> {
info.toPhase(JavaSource.Phase.RESOLVED);
occurrences.putAll(findMatchingTypes(CompilationContext.create(file, info), target, matching));
}, true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}

if (this.occurrences.isEmpty()) {
// perhaps the caret is on a resource bundle key node
occurrences.putAll(findMatchingResourceBundleKeys(target, parserResult));
Expand Down Expand Up @@ -185,7 +186,7 @@ private Map<OffsetRange, ColoringAttributes> findMatchingResourceBundleKeys(Pair
return result;
}

private Map<OffsetRange, ColoringAttributes> findMatchingTypes(CompilationContext info, ELParserResult parserResult, Pair<ELElement,Node> target, List<Pair<ELElement,Node>> candidates) {
private Map<OffsetRange, ColoringAttributes> findMatchingTypes(CompilationContext info, Pair<ELElement,Node> target, List<Pair<ELElement,Node>> candidates) {
Element targetType = ELTypeUtilities.resolveElement(info, target.first(), target.second());
Map<OffsetRange, ColoringAttributes> result = new HashMap<>();

Expand Down
10 changes: 10 additions & 0 deletions enterprise/web.el/src/org/netbeans/modules/web/el/layer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
</folder>
</folder>
</folder>
<folder name="MarkOccurrences">
<folder name="text">
<folder name="x-el">
<file name="MarkOccurences.instance">
<attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
<attr name="instanceCreate" newvalue="org.netbeans.modules.web.el.options.MarkOccurencesOptionsPanelController"/>
</file>
</folder>
</folder>
</folder>
</folder>
</folder>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

CTL_OnOff_CheckBox=Mark &Occurrences Of Symbol Under Caret
ACSD_OnOff_CB=Checkbox switching mark occurrences on/off
MarkOccurrencesPanel.AccessibleContext.accessibleDescription=Panel for Expression Language Mark Occurrences
MarkOccurrencesPanel.AccessibleContext.accessibleName=Expression Language Mark Occurrences Panel
MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName=Mark Occurrences Of Symbol Under Caret
MarkOccurencesPanel.keepMarksCheckBox.text=Keep Marks
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.web.el.options;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import javax.swing.JComponent;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.HelpCtx;
import org.openide.util.Lookup;

public final class MarkOccurencesOptionsPanelController extends OptionsPanelController {

private MarkOccurencesPanel panel;

private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private boolean changed;

@Override
public void update() {
getPanel().load(this);
}

@Override
public void applyChanges() {
getPanel().store();
}

@Override
public void cancel() {
// need not do anything special, if no changes have been persisted yet
}

@Override
public boolean isValid() {
return true; // Always valid
}

@Override
public boolean isChanged() {
return getPanel().changed();
}

@Override
public HelpCtx getHelpCtx() {
return new HelpCtx("netbeans.optionsDialog.el.markoccurrences");
}

@Override
public synchronized JComponent getComponent(Lookup masterLookup) {
return getPanel();
}

public synchronized MarkOccurencesPanel getPanel() {
if (panel == null) {
panel = new MarkOccurencesPanel(this);
}
return panel;
}

@Override
public void addPropertyChangeListener(PropertyChangeListener l) {
pcs.addPropertyChangeListener(l);
}

@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
pcs.removePropertyChangeListener(l);
}

void changed() {
if (!changed) {
changed = true;
pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
}
pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->

<Form version="1.4" maxVersion="1.4" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="8" left="8" right="8" top="8"/>
</Border>
</Property>
<Property name="focusCycleRoot" type="boolean" value="true"/>
<Property name="focusTraversalPolicy" type="java.awt.FocusTraversalPolicy" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new java.awt.FocusTraversalPolicy() {&#xa; public java.awt.Component getDefaultComponent(java.awt.Container focusCycleRoot){&#xa; return onOffCheckBox;&#xa; }//end getDefaultComponent&#xa;&#xa; public java.awt.Component getFirstComponent(java.awt.Container focusCycleRoot){&#xa; return onOffCheckBox;&#xa; }//end getFirstComponent&#xa;&#xa; public java.awt.Component getLastComponent(java.awt.Container focusCycleRoot){&#xa; return onOffCheckBox;&#xa; }//end getLastComponent&#xa;&#xa; public java.awt.Component getComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent){&#xa; return onOffCheckBox;//end getComponentAfter&#xa; }&#xa; public java.awt.Component getComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent){&#xa; return onOffCheckBox;//end getComponentBefore&#xa;&#xa; }}&#xa; " type="code"/>
</Property>
</Properties>
<AccessibilityProperties>
<Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/web/el/options/Bundle.properties" key="MarkOccurrencesPanel.AccessibleContext.accessibleName" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/web/el/options/Bundle.properties" key="MarkOccurrencesPanel.AccessibleContext.accessibleDescription" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</AccessibilityProperties>
<AuxValues>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,75,0,0,2,18"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JCheckBox" name="onOffCheckBox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/web/el/options/Bundle.properties" key="CTL_OnOff_CheckBox" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
</Properties>
<AccessibilityProperties>
<Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/web/el/options/Bundle.properties" key="MarkOccurrencesPanel.onOffCheckBox.AccessibleContext.accessibleName" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/web/el/options/Bundle.properties" key="ACSD_OnOff_CB" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</AccessibilityProperties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="0" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="12" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="keepMarksCheckBox">
<Properties>
<Property name="mnemonic" type="int" value="115"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/web/el/options/Bundle.properties" key="MarkOccurencesPanel.keepMarksCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<AccessibilityProperties>
<Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/web/el/options/Bundle.properties" key="MarkOccurencesPanel.keepMarksCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</AccessibilityProperties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="0" gridHeight="0" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="20" insetsBottom="8" insetsRight="0" anchor="18" weightX="0.0" weightY="1.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Form>
Loading
Loading