Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralina2016-04-27 17:51:37 +0000
committerVictor Rubezhny2016-04-28 02:12:14 +0000
commit27b79aca6edd34210a38a4738127181c8e2906d5 (patch)
tree7eef742c35114030b4df5fadfc804c7f0d931391
parent0dd03f8063b148fded5052b66269d4e5344ee16c (diff)
downloadwebtools.sourceediting-27b79aca6edd34210a38a4738127181c8e2906d5.tar.gz
webtools.sourceediting-27b79aca6edd34210a38a4738127181c8e2906d5.tar.xz
webtools.sourceediting-27b79aca6edd34210a38a4738127181c8e2906d5.zip
Bug 491944 -JSON empty Array not properly recognized in the outline view
Added a workaround while we fix the JSON lexical analyzer. This workaround looks for the parent object to make JSONTokenizer get the right tokens for the JSONSourceParser, this change doesn't affect the performance or the regions that the JSONModelParser will take. Change-Id: Ia3e7bf0add940167c0a4fe2edd8ef865eac8ae36 Signed-off-by: alina <alina@mx1.ibm.com>
-rw-r--r--bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java14
-rw-r--r--bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/text/JSONStructuredDocumentReParser.java30
2 files changed, 27 insertions, 17 deletions
diff --git a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java
index 9d677ca87d..3f689ef674 100644
--- a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java
+++ b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java
@@ -693,8 +693,18 @@ public class JSONModelImpl extends AbstractStructuredModel implements
/* workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=486860 */
// this.refresh = true;
// handleRefresh();
-
- parser.replaceRegions(flatNode, newRegions, oldRegions);
+ boolean reloadModel = false;
+ // Check if the insertion is between two previously existing JSON Nodes, in that case
+ // the model is reloaded completely.
+ if (flatNode.getType().equals(JSONRegionContexts.JSON_COMMA) && flatNode.getNext() != null) {
+ reloadModel = true;
+ }
+ if(reloadModel) {
+ this.refresh = true;
+ handleRefresh();
+ } else {
+ parser.replaceRegions(flatNode, newRegions, oldRegions);
+ }
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
diff --git a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/text/JSONStructuredDocumentReParser.java b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/text/JSONStructuredDocumentReParser.java
index 8bb8eb60ac..e37b9c4080 100644
--- a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/text/JSONStructuredDocumentReParser.java
+++ b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/text/JSONStructuredDocumentReParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,7 +8,8 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Angelo Zerr <angelo.zerr@gmail.com> - copied from org.eclipse.wst.css.core.internal.text.CSSStructuredDocumentReParser
- * modified in order to process JSON Objects.
+ * modified in order to process JSON Objects.
+ * Alina Marin <alina@mx.ibm.com> - added a workaround while we fix the JSON lexical analyzer.
*******************************************************************************/
package org.eclipse.wst.json.core.internal.text;
@@ -261,21 +262,20 @@ public class JSONStructuredDocumentReParser extends StructuredDocumentReParser {
private IStructuredDocumentRegion findRuleStart(
IStructuredDocumentRegion startRegion) {
- IStructuredDocumentRegion region = startRegion;
// find '{'
- while (region != null
- && (region.getType() != JSONRegionContexts.JSON_OBJECT_OPEN && region
- .getType() != JSONRegionContexts.JSON_ARRAY_OPEN)) {
- region = region.getPrevious();
- }
- // if (region == startRegion) {
- // return null;
- // } else
+// while (region != null
+// && (region.getType() != JSONRegionContexts.JSON_OBJECT_OPEN && region
+// .getType() != JSONRegionContexts.JSON_ARRAY_OPEN)) {
+// region = region.getPrevious();
+// }
+ /*
+ * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=491944
+ * Look for the parent object to make JSONTokenizer get the right tokens
+ * for the JSONSourceParser, this change doesn't affect the performance
+ * or the regions that the JSONModelParser will take
+ */
+ IStructuredDocumentRegion region = startRegion.getParentDocument().getFirstStructuredDocumentRegion();
if (region != null) { // '{' is found
- // region = region.getPrevious();
- // if (isLeadingDeclarationType(region.getType())) {
- // return region;
- // }
return region;
}
return null;

Back to the top