Skip to content

Commit 45890d5

Browse files
committed
[NONE] DOT Editor - Fixing BadLocationException in DotProposalProvider.
- Modify the content assist proposal calculation logic to avoid throwing org.eclipse.jface.text.BadLocationException. - Implement corresponding DotContentAssistTest test cases.
1 parent 99e2abf commit 45890d5

File tree

2 files changed

+80
-7
lines changed

2 files changed

+80
-7
lines changed

org.eclipse.gef.dot.tests/src/org/eclipse/gef/dot/tests/DotContentAssistTest.xtend

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2020 itemis AG and others.
2+
* Copyright (c) 2016, 2021 itemis AG and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -3019,6 +3019,19 @@ class DotContentAssistTest extends AbstractContentAssistTest {
30193019
}
30203020
''')
30213021

3022+
'''
3023+
graph {
3024+
1[color="blue"«c»]
3025+
}
3026+
'''.testContentAssistant(#[",", ";", "]", "color", "colorscheme", "distortion", "fillcolor", "fixedsize", "fontcolor", "fontname", "fontsize",
3027+
"height", "id", "label", "penwidth", "pos", "shape", "sides", "skew", "style", "tooltip", "width",
3028+
"xlabel", "xlp"], "fixedsize",
3029+
'''
3030+
graph {
3031+
1[color="blue"fixedsize=]
3032+
}
3033+
''')
3034+
30223035
// test local attribute names with prefix
30233036
'''
30243037
graph {
@@ -3054,6 +3067,16 @@ class DotContentAssistTest extends AbstractContentAssistTest {
30543067
}
30553068
''')
30563069

3070+
'''
3071+
graph {
3072+
1[ color=«c»"" ]
3073+
}
3074+
'''.testContentAssistant(combine(expectedX11ColorNames, #["#", "/"]), "#", '''
3075+
graph {
3076+
1[ color=#"" ]
3077+
}
3078+
''')
3079+
30573080
// test local attribute values with quotes
30583081
'''
30593082
graph {
@@ -3458,6 +3481,18 @@ class DotContentAssistTest extends AbstractContentAssistTest {
34583481
''')
34593482

34603483
// test html-like label attribute
3484+
'''
3485+
graph {
3486+
1[ label=«c»<> ]
3487+
}
3488+
'''.testContentAssistant(#["HTMLLabel - Insert a template"], "HTMLLabel - Insert a template", '''
3489+
graph {
3490+
1[ label=<
3491+
3492+
><> ]
3493+
}
3494+
''')
3495+
34613496
'''
34623497
graph {
34633498
1[ label=<

org.eclipse.gef.dot.ui/src/org/eclipse/gef/dot/internal/ui/language/contentassist/DotProposalProvider.java

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*******************************************************************************/
2222
package org.eclipse.gef.dot.internal.ui.language.contentassist;
2323

24+
import static org.eclipse.gef.dot.internal.language.dot.DotPackage.Literals.ATTRIBUTE__VALUE;
25+
2426
import java.lang.reflect.Field;
2527
import java.lang.reflect.Modifier;
2628
import java.util.ArrayList;
@@ -69,6 +71,7 @@
6971
import org.eclipse.xtext.EcoreUtil2;
7072
import org.eclipse.xtext.Keyword;
7173
import org.eclipse.xtext.nodemodel.INode;
74+
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
7275
import org.eclipse.xtext.ui.IImageHelper;
7376
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal;
7477
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal.IReplacementTextApplier;
@@ -313,6 +316,28 @@ public void completeAttribute_Value(EObject model, Assignment assignment,
313316
.setMatcher(new AttributeValueMatcher(context.getMatcher()))
314317
.toContext();
315318

319+
/*
320+
* do not propose any attribute values if it is already properly
321+
* enclosed with double quotes and the cursor is located directly
322+
* after the closing quote
323+
*/
324+
ID attributeValue = attribute.getValue();
325+
if (attributeValue != null) {
326+
String attributeValueText = attributeValue.toString();
327+
int cursorPosition = context.getOffset();
328+
329+
int attributeValueEndOffset = NodeModelUtils
330+
.findNodesForFeature(attribute, ATTRIBUTE__VALUE).get(0)
331+
.getTotalEndOffset();
332+
333+
if (attributeValueText.startsWith("\"") //$NON-NLS-1$
334+
&& attributeValueText.endsWith("\"") //$NON-NLS-1$
335+
&& attributeValueText.length() > 1
336+
&& cursorPosition >= attributeValueEndOffset) {
337+
return;
338+
}
339+
}
340+
316341
switch (attributeContext) {
317342
case EDGE:
318343
switch (attributeName) {
@@ -600,7 +625,9 @@ private void proposeAttributeValues(String subgrammarName,
600625
} else {
601626
text = text.substring(1, text.length() - 1);
602627
}
603-
offset++;
628+
if (context.getOffset() > offset) {
629+
offset++;
630+
}
604631
}
605632
}
606633

@@ -681,11 +708,22 @@ private void proposeHtmlLabelAttributeValues(Attribute attribute,
681708
DotColorProposalProvider.globalColorScheme = DotAstHelper
682709
.getColorSchemeAttributeValue(attribute);
683710

684-
if (attribute.getValue() != null
685-
&& attribute.getValue().getType() == Type.HTML_STRING) {
686-
proposeAttributeValues(
687-
DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTHTMLLABEL,
688-
context, acceptor);
711+
ID attributeValue = attribute.getValue();
712+
if (attributeValue != null) {
713+
int cursorPosition = context.getOffset();
714+
int attributeValueStartOffset = NodeModelUtils
715+
.findNodesForFeature(attribute, ATTRIBUTE__VALUE).get(0)
716+
.getOffset();
717+
/*
718+
* do not propose the html-label values if the attribute value is
719+
* set, but the cursor is located before it
720+
*/
721+
if (cursorPosition > attributeValueStartOffset
722+
&& attributeValue.getType() == Type.HTML_STRING) {
723+
proposeAttributeValues(
724+
DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTHTMLLABEL,
725+
context, acceptor);
726+
}
689727
}
690728

691729
// reset the state of the DotColorProposalProvider

0 commit comments

Comments
 (0)