mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
Merge pull request #1448 from eclipse/cd_evenMoreX2J
[eclipse/xtext#1679] converted code to java
This commit is contained in:
commit
780ba573dd
37 changed files with 1195 additions and 2223 deletions
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.tests.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.DocumentHighlightKind;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.util.DocumentHighlightComparator;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Test for the null-safe {@link DocumentHighlightComparator}.
|
||||
*
|
||||
* <p>
|
||||
* This test focuses on the {@link DocumentHighlightKind} and the null-safety.
|
||||
* Other orderings are checked via the {@link RangeComparatorTest}.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider.class)
|
||||
public class DocumentHighlightComparatorTest extends Assert {
|
||||
@Inject
|
||||
private DocumentHighlightComparator comparator;
|
||||
|
||||
@Test
|
||||
public void withoutNull() {
|
||||
List<? extends DocumentHighlight> input = sort(
|
||||
Lists.newArrayList(newHighlight(DocumentHighlightKind.Text, newRange(2, 2, 2, 2)),
|
||||
newHighlight(DocumentHighlightKind.Text, newRange(1, 1, 1, 1)),
|
||||
newHighlight(DocumentHighlightKind.Write, newRange(2, 2, 2, 2)),
|
||||
newHighlight(DocumentHighlightKind.Write, newRange(1, 1, 1, 1)),
|
||||
newHighlight(DocumentHighlightKind.Read, newRange(2, 2, 2, 2)),
|
||||
newHighlight(DocumentHighlightKind.Read, newRange(1, 1, 1, 1))));
|
||||
assertEquals(1, input.get(0).getRange().getStart().getLine());
|
||||
assertEquals(1, input.get(0).getRange().getStart().getCharacter());
|
||||
assertEquals(1, input.get(0).getRange().getEnd().getLine());
|
||||
assertEquals(1, input.get(0).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Text, input.get(0).getKind());
|
||||
assertEquals(1, input.get(1).getRange().getStart().getLine());
|
||||
assertEquals(1, input.get(1).getRange().getStart().getCharacter());
|
||||
assertEquals(1, input.get(1).getRange().getEnd().getLine());
|
||||
assertEquals(1, input.get(1).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Read, input.get(1).getKind());
|
||||
assertEquals(1, input.get(2).getRange().getStart().getLine());
|
||||
assertEquals(1, input.get(2).getRange().getStart().getCharacter());
|
||||
assertEquals(1, input.get(2).getRange().getEnd().getLine());
|
||||
assertEquals(1, input.get(2).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Write, input.get(2).getKind());
|
||||
assertEquals(2, input.get(3).getRange().getStart().getLine());
|
||||
assertEquals(2, input.get(3).getRange().getStart().getCharacter());
|
||||
assertEquals(2, input.get(3).getRange().getEnd().getLine());
|
||||
assertEquals(2, input.get(3).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Text, input.get(3).getKind());
|
||||
assertEquals(2, input.get(4).getRange().getStart().getLine());
|
||||
assertEquals(2, input.get(4).getRange().getStart().getCharacter());
|
||||
assertEquals(2, input.get(4).getRange().getEnd().getLine());
|
||||
assertEquals(2, input.get(4).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Read, input.get(4).getKind());
|
||||
assertEquals(2, input.get(5).getRange().getStart().getLine());
|
||||
assertEquals(2, input.get(5).getRange().getStart().getCharacter());
|
||||
assertEquals(2, input.get(5).getRange().getEnd().getLine());
|
||||
assertEquals(2, input.get(5).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Write, input.get(5).getKind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNull() {
|
||||
List<? extends DocumentHighlight> input = sort(
|
||||
Lists.newArrayList(null, newHighlight(DocumentHighlightKind.Text, newRange(1, 1, 1, 1)),
|
||||
newHighlight(DocumentHighlightKind.Write, newRange(1, 1, 1, 1)),
|
||||
newHighlight(DocumentHighlightKind.Read, newRange(1, 1, 1, 1))));
|
||||
assertEquals(1, input.get(0).getRange().getStart().getLine());
|
||||
assertEquals(1, input.get(0).getRange().getStart().getCharacter());
|
||||
assertEquals(1, input.get(0).getRange().getEnd().getLine());
|
||||
assertEquals(1, input.get(0).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Text, input.get(0).getKind());
|
||||
assertEquals(1, input.get(1).getRange().getStart().getLine());
|
||||
assertEquals(1, input.get(1).getRange().getStart().getCharacter());
|
||||
assertEquals(1, input.get(1).getRange().getEnd().getLine());
|
||||
assertEquals(1, input.get(1).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Read, input.get(1).getKind());
|
||||
assertEquals(1, input.get(2).getRange().getStart().getLine());
|
||||
assertEquals(1, input.get(2).getRange().getStart().getCharacter());
|
||||
assertEquals(1, input.get(2).getRange().getEnd().getLine());
|
||||
assertEquals(1, input.get(2).getRange().getEnd().getCharacter());
|
||||
assertEquals(DocumentHighlightKind.Write, input.get(2).getKind());
|
||||
assertNull(IterableExtensions.last(input));
|
||||
}
|
||||
|
||||
private DocumentHighlight newHighlight(DocumentHighlightKind kind, Range range) {
|
||||
return new DocumentHighlight(range, kind);
|
||||
}
|
||||
|
||||
private Range newRange(int startLine, int startChar, int endLine, int endChar) {
|
||||
return new Range(new Position(startLine, startChar), new Position(endLine, endChar));
|
||||
}
|
||||
|
||||
private List<? extends DocumentHighlight> sort(List<? extends DocumentHighlight> toSort) {
|
||||
toSort.sort(comparator);
|
||||
return toSort;
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.tests.util
|
||||
|
||||
import com.google.inject.Inject
|
||||
import java.util.List
|
||||
import org.eclipse.lsp4j.DocumentHighlight
|
||||
import org.eclipse.lsp4j.DocumentHighlightKind
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.Range
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider
|
||||
import org.eclipse.xtext.ide.util.DocumentHighlightComparator
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import static org.eclipse.lsp4j.DocumentHighlightKind.*
|
||||
|
||||
/**
|
||||
* Test for the null-safe {@link DocumentHighlightComparator}.
|
||||
*
|
||||
* <p>
|
||||
* This test focuses on the {@link DocumentHighlightKind} and the null-safety
|
||||
* other orderings are checked via the {@link RangeComparatorTest}.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider)
|
||||
class DocumentHighlightComparatorTest extends Assert {
|
||||
|
||||
@Inject
|
||||
DocumentHighlightComparator comparator;
|
||||
|
||||
@Test
|
||||
def void withoutNull() {
|
||||
val input = newArrayList(Text.newHighlight(newRange(2, 2, 2, 2)), Text.newHighlight(newRange(1, 1, 1, 1)),
|
||||
Write.newHighlight(newRange(2, 2, 2, 2)), Write.newHighlight(newRange(1, 1, 1, 1)),
|
||||
Read.newHighlight(newRange(2, 2, 2, 2)), Read.newHighlight(newRange(1, 1, 1, 1))).sort;
|
||||
|
||||
assertEquals(1, input.get(0).range.start.line);
|
||||
assertEquals(1, input.get(0).range.start.character);
|
||||
assertEquals(1, input.get(0).range.end.line);
|
||||
assertEquals(1, input.get(0).range.end.character);
|
||||
assertEquals(Text, input.get(0).kind);
|
||||
|
||||
assertEquals(1, input.get(1).range.start.line);
|
||||
assertEquals(1, input.get(1).range.start.character);
|
||||
assertEquals(1, input.get(1).range.end.line);
|
||||
assertEquals(1, input.get(1).range.end.character);
|
||||
assertEquals(Read, input.get(1).kind);
|
||||
|
||||
assertEquals(1, input.get(2).range.start.line);
|
||||
assertEquals(1, input.get(2).range.start.character);
|
||||
assertEquals(1, input.get(2).range.end.line);
|
||||
assertEquals(1, input.get(2).range.end.character);
|
||||
assertEquals(Write, input.get(2).kind);
|
||||
|
||||
assertEquals(2, input.get(3).range.start.line);
|
||||
assertEquals(2, input.get(3).range.start.character);
|
||||
assertEquals(2, input.get(3).range.end.line);
|
||||
assertEquals(2, input.get(3).range.end.character);
|
||||
assertEquals(Text, input.get(3).kind);
|
||||
|
||||
assertEquals(2, input.get(4).range.start.line);
|
||||
assertEquals(2, input.get(4).range.start.character);
|
||||
assertEquals(2, input.get(4).range.end.line);
|
||||
assertEquals(2, input.get(4).range.end.character);
|
||||
assertEquals(Read, input.get(4).kind);
|
||||
|
||||
assertEquals(2, input.get(5).range.start.line);
|
||||
assertEquals(2, input.get(5).range.start.character);
|
||||
assertEquals(2, input.get(5).range.end.line);
|
||||
assertEquals(2, input.get(5).range.end.character);
|
||||
assertEquals(Write, input.get(5).kind);
|
||||
}
|
||||
|
||||
@Test
|
||||
def void withNull() {
|
||||
val input = newArrayList(null, Text.newHighlight(newRange(1, 1, 1, 1)),
|
||||
Write.newHighlight(newRange(1, 1, 1, 1)), Read.newHighlight(newRange(1, 1, 1, 1))).sort;
|
||||
|
||||
assertEquals(1, input.get(0).range.start.line);
|
||||
assertEquals(1, input.get(0).range.start.character);
|
||||
assertEquals(1, input.get(0).range.end.line);
|
||||
assertEquals(1, input.get(0).range.end.character);
|
||||
assertEquals(Text, input.get(0).kind);
|
||||
|
||||
assertEquals(1, input.get(1).range.start.line);
|
||||
assertEquals(1, input.get(1).range.start.character);
|
||||
assertEquals(1, input.get(1).range.end.line);
|
||||
assertEquals(1, input.get(1).range.end.character);
|
||||
assertEquals(Read, input.get(1).kind);
|
||||
|
||||
assertEquals(1, input.get(2).range.start.line);
|
||||
assertEquals(1, input.get(2).range.start.character);
|
||||
assertEquals(1, input.get(2).range.end.line);
|
||||
assertEquals(1, input.get(2).range.end.character);
|
||||
assertEquals(Write, input.get(2).kind);
|
||||
|
||||
assertNull(input.last);
|
||||
}
|
||||
|
||||
private def newHighlight(DocumentHighlightKind kind, Range range) {
|
||||
new DocumentHighlight(range, kind);
|
||||
}
|
||||
|
||||
private def newRange(int startLine, int startChar, int endLine, int endChar) {
|
||||
return new Range(new Position(startLine, startChar), new Position(endLine, endChar));
|
||||
}
|
||||
|
||||
private def sort(List<? extends DocumentHighlight> toSort) {
|
||||
toSort.sort(comparator);
|
||||
return toSort;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.tests.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.util.RangeComparator;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Test for the null-safe {@link RangeComparator}.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider.class)
|
||||
public class RangeComparatorTest extends Assert {
|
||||
@Inject
|
||||
private RangeComparator comparator;
|
||||
|
||||
@Test
|
||||
public void withoutNull() {
|
||||
List<? extends Range> input = sort(Lists.newArrayList(newRange(1, 2, 1, 2), newRange(1, 1, 2, 1),
|
||||
newRange(1, 1, 1, 2), newRange(1, 1, 1, 1), newRange(2, 2, 2, 3)));
|
||||
assertEquals(1, input.get(0).getStart().getLine());
|
||||
assertEquals(1, input.get(0).getStart().getCharacter());
|
||||
assertEquals(1, input.get(0).getEnd().getLine());
|
||||
assertEquals(1, input.get(0).getEnd().getCharacter());
|
||||
assertEquals(1, input.get(1).getStart().getLine());
|
||||
assertEquals(1, input.get(1).getStart().getCharacter());
|
||||
assertEquals(1, input.get(1).getEnd().getLine());
|
||||
assertEquals(2, input.get(1).getEnd().getCharacter());
|
||||
assertEquals(1, input.get(2).getStart().getLine());
|
||||
assertEquals(1, input.get(2).getStart().getCharacter());
|
||||
assertEquals(2, input.get(2).getEnd().getLine());
|
||||
assertEquals(1, input.get(2).getEnd().getCharacter());
|
||||
assertEquals(1, input.get(3).getStart().getLine());
|
||||
assertEquals(2, input.get(3).getStart().getCharacter());
|
||||
assertEquals(1, input.get(3).getEnd().getLine());
|
||||
assertEquals(2, input.get(3).getEnd().getCharacter());
|
||||
assertEquals(2, input.get(4).getStart().getLine());
|
||||
assertEquals(2, input.get(4).getStart().getCharacter());
|
||||
assertEquals(2, input.get(4).getEnd().getLine());
|
||||
assertEquals(3, input.get(4).getEnd().getCharacter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNull() {
|
||||
List<? extends Range> input = sort(Lists.newArrayList(newRange(2, 2, 2, 3), null, newRange(1, 1, 1, 1)));
|
||||
assertEquals(1, input.get(0).getStart().getLine());
|
||||
assertEquals(1, input.get(0).getStart().getCharacter());
|
||||
assertEquals(1, input.get(0).getEnd().getLine());
|
||||
assertEquals(1, input.get(0).getEnd().getCharacter());
|
||||
assertEquals(2, input.get(1).getStart().getLine());
|
||||
assertEquals(2, input.get(1).getStart().getCharacter());
|
||||
assertEquals(2, input.get(1).getEnd().getLine());
|
||||
assertEquals(3, input.get(1).getEnd().getCharacter());
|
||||
assertNull(IterableExtensions.last(input));
|
||||
}
|
||||
|
||||
private Range newRange(int startLine, int startChar, int endLine, int endChar) {
|
||||
return new Range(new Position(startLine, startChar), new Position(endLine, endChar));
|
||||
}
|
||||
|
||||
private List<? extends Range> sort(List<? extends Range> toSort) {
|
||||
toSort.sort(comparator);
|
||||
return toSort;
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.tests.util
|
||||
|
||||
import com.google.inject.Inject
|
||||
import java.util.List
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.Range
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider
|
||||
import org.eclipse.xtext.ide.util.RangeComparator
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Test for the null-safe {@link RangeComparator}.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider)
|
||||
class RangeComparatorTest extends Assert {
|
||||
|
||||
@Inject
|
||||
RangeComparator comparator;
|
||||
|
||||
@Test
|
||||
def void withoutNull() {
|
||||
val input = newArrayList(newRange(1, 2, 1, 2), newRange(1, 1, 2, 1), newRange(1, 1, 1, 2), newRange(1, 1, 1, 1),
|
||||
newRange(2, 2, 2, 3)).sort;
|
||||
|
||||
assertEquals(1, input.get(0).start.line);
|
||||
assertEquals(1, input.get(0).start.character);
|
||||
assertEquals(1, input.get(0).end.line);
|
||||
assertEquals(1, input.get(0).end.character);
|
||||
|
||||
assertEquals(1, input.get(1).start.line);
|
||||
assertEquals(1, input.get(1).start.character);
|
||||
assertEquals(1, input.get(1).end.line);
|
||||
assertEquals(2, input.get(1).end.character);
|
||||
|
||||
assertEquals(1, input.get(2).start.line);
|
||||
assertEquals(1, input.get(2).start.character);
|
||||
assertEquals(2, input.get(2).end.line);
|
||||
assertEquals(1, input.get(2).end.character);
|
||||
|
||||
assertEquals(1, input.get(3).start.line);
|
||||
assertEquals(2, input.get(3).start.character);
|
||||
assertEquals(1, input.get(3).end.line);
|
||||
assertEquals(2, input.get(3).end.character);
|
||||
|
||||
assertEquals(2, input.get(4).start.line);
|
||||
assertEquals(2, input.get(4).start.character);
|
||||
assertEquals(2, input.get(4).end.line);
|
||||
assertEquals(3, input.get(4).end.character);
|
||||
}
|
||||
|
||||
@Test
|
||||
def void withNull() {
|
||||
val input = newArrayList(newRange(2, 2, 2, 3), null, newRange(1, 1, 1, 1)).sort;
|
||||
|
||||
assertEquals(1, input.get(0).start.line);
|
||||
assertEquals(1, input.get(0).start.character);
|
||||
assertEquals(1, input.get(0).end.line);
|
||||
assertEquals(1, input.get(0).end.character);
|
||||
|
||||
assertEquals(2, input.get(1).start.line);
|
||||
assertEquals(2, input.get(1).start.character);
|
||||
assertEquals(2, input.get(1).end.line);
|
||||
assertEquals(3, input.get(1).end.character);
|
||||
|
||||
assertNull(input.last);
|
||||
}
|
||||
|
||||
private def newRange(int startLine, int startChar, int endLine, int endChar) {
|
||||
return new Range(new Position(startLine, startChar), new Position(endLine, endChar));
|
||||
}
|
||||
|
||||
private def sort(List<? extends Range> toSort) {
|
||||
toSort.sort(comparator);
|
||||
return toSort;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.tests.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.DocumentHighlightKind;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.util.DocumentHighlightComparator;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Test for the null-safe {@link DocumentHighlightComparator}.
|
||||
*
|
||||
* <p>
|
||||
* This test focuses on the {@link DocumentHighlightKind} and the null-safety
|
||||
* other orderings are checked via the {@link RangeComparatorTest}.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class DocumentHighlightComparatorTest extends Assert {
|
||||
@Inject
|
||||
private DocumentHighlightComparator comparator;
|
||||
|
||||
@Test
|
||||
public void withoutNull() {
|
||||
final List<? extends DocumentHighlight> input = this.sort(CollectionLiterals.<DocumentHighlight>newArrayList(this.newHighlight(DocumentHighlightKind.Text, this.newRange(2, 2, 2, 2)), this.newHighlight(DocumentHighlightKind.Text, this.newRange(1, 1, 1, 1)),
|
||||
this.newHighlight(DocumentHighlightKind.Write, this.newRange(2, 2, 2, 2)), this.newHighlight(DocumentHighlightKind.Write, this.newRange(1, 1, 1, 1)),
|
||||
this.newHighlight(DocumentHighlightKind.Read, this.newRange(2, 2, 2, 2)), this.newHighlight(DocumentHighlightKind.Read, this.newRange(1, 1, 1, 1))));
|
||||
Assert.assertEquals(1, input.get(0).getRange().getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(0).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Text, input.get(0).getKind());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Read, input.get(1).getKind());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Write, input.get(2).getKind());
|
||||
Assert.assertEquals(2, input.get(3).getRange().getStart().getLine());
|
||||
Assert.assertEquals(2, input.get(3).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(2, input.get(3).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(2, input.get(3).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Text, input.get(3).getKind());
|
||||
Assert.assertEquals(2, input.get(4).getRange().getStart().getLine());
|
||||
Assert.assertEquals(2, input.get(4).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(2, input.get(4).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(2, input.get(4).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Read, input.get(4).getKind());
|
||||
Assert.assertEquals(2, input.get(5).getRange().getStart().getLine());
|
||||
Assert.assertEquals(2, input.get(5).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(2, input.get(5).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(2, input.get(5).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Write, input.get(5).getKind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNull() {
|
||||
final List<? extends DocumentHighlight> input = this.sort(CollectionLiterals.<DocumentHighlight>newArrayList(null, this.newHighlight(DocumentHighlightKind.Text, this.newRange(1, 1, 1, 1)),
|
||||
this.newHighlight(DocumentHighlightKind.Write, this.newRange(1, 1, 1, 1)), this.newHighlight(DocumentHighlightKind.Read, this.newRange(1, 1, 1, 1))));
|
||||
Assert.assertEquals(1, input.get(0).getRange().getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(0).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Text, input.get(0).getKind());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(1).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Read, input.get(1).getKind());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(2).getRange().getEnd().getCharacter());
|
||||
Assert.assertEquals(DocumentHighlightKind.Write, input.get(2).getKind());
|
||||
Assert.assertNull(IterableExtensions.last(input));
|
||||
}
|
||||
|
||||
private DocumentHighlight newHighlight(final DocumentHighlightKind kind, final Range range) {
|
||||
return new DocumentHighlight(range, kind);
|
||||
}
|
||||
|
||||
private Range newRange(final int startLine, final int startChar, final int endLine, final int endChar) {
|
||||
Position _position = new Position(startLine, startChar);
|
||||
Position _position_1 = new Position(endLine, endChar);
|
||||
return new Range(_position, _position_1);
|
||||
}
|
||||
|
||||
private List<? extends DocumentHighlight> sort(final List<? extends DocumentHighlight> toSort) {
|
||||
toSort.sort(this.comparator);
|
||||
return toSort;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.tests.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.util.RangeComparator;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Test for the null-safe {@link RangeComparator}.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class RangeComparatorTest extends Assert {
|
||||
@Inject
|
||||
private RangeComparator comparator;
|
||||
|
||||
@Test
|
||||
public void withoutNull() {
|
||||
final List<? extends Range> input = this.sort(CollectionLiterals.<Range>newArrayList(this.newRange(1, 2, 1, 2), this.newRange(1, 1, 2, 1), this.newRange(1, 1, 1, 2), this.newRange(1, 1, 1, 1),
|
||||
this.newRange(2, 2, 2, 3)));
|
||||
Assert.assertEquals(1, input.get(0).getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(0).getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getEnd().getCharacter());
|
||||
Assert.assertEquals(1, input.get(1).getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(1).getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(1).getEnd().getLine());
|
||||
Assert.assertEquals(2, input.get(1).getEnd().getCharacter());
|
||||
Assert.assertEquals(1, input.get(2).getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(2).getStart().getCharacter());
|
||||
Assert.assertEquals(2, input.get(2).getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(2).getEnd().getCharacter());
|
||||
Assert.assertEquals(1, input.get(3).getStart().getLine());
|
||||
Assert.assertEquals(2, input.get(3).getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(3).getEnd().getLine());
|
||||
Assert.assertEquals(2, input.get(3).getEnd().getCharacter());
|
||||
Assert.assertEquals(2, input.get(4).getStart().getLine());
|
||||
Assert.assertEquals(2, input.get(4).getStart().getCharacter());
|
||||
Assert.assertEquals(2, input.get(4).getEnd().getLine());
|
||||
Assert.assertEquals(3, input.get(4).getEnd().getCharacter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNull() {
|
||||
final List<? extends Range> input = this.sort(CollectionLiterals.<Range>newArrayList(this.newRange(2, 2, 2, 3), null, this.newRange(1, 1, 1, 1)));
|
||||
Assert.assertEquals(1, input.get(0).getStart().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getStart().getCharacter());
|
||||
Assert.assertEquals(1, input.get(0).getEnd().getLine());
|
||||
Assert.assertEquals(1, input.get(0).getEnd().getCharacter());
|
||||
Assert.assertEquals(2, input.get(1).getStart().getLine());
|
||||
Assert.assertEquals(2, input.get(1).getStart().getCharacter());
|
||||
Assert.assertEquals(2, input.get(1).getEnd().getLine());
|
||||
Assert.assertEquals(3, input.get(1).getEnd().getCharacter());
|
||||
Assert.assertNull(IterableExtensions.last(input));
|
||||
}
|
||||
|
||||
private Range newRange(final int startLine, final int startChar, final int endLine, final int endChar) {
|
||||
Position _position = new Position(startLine, startChar);
|
||||
Position _position_1 = new Position(endLine, endChar);
|
||||
return new Range(_position, _position_1);
|
||||
}
|
||||
|
||||
private List<? extends Range> sort(final List<? extends Range> toSort) {
|
||||
toSort.sort(this.comparator);
|
||||
return toSort;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,289 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.util.ReplaceRegion;
|
||||
import org.eclipse.xtext.util.TextRegion;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @noreference
|
||||
*/
|
||||
public class ContentAssistEntry {
|
||||
|
||||
public static final String KIND_TEXT = "TEXT";
|
||||
|
||||
public static final String KIND_METHOD = "METHOD";
|
||||
|
||||
public static final String KIND_FUNCTION = "FUNCTION";
|
||||
|
||||
public static final String KIND_CONSTRUCTOR = "CONSTRUCTOR";
|
||||
|
||||
public static final String KIND_FIELD = "FIELD";
|
||||
|
||||
public static final String KIND_VARIABLE = "VARIABLE";
|
||||
|
||||
public static final String KIND_CLASS = "CLASS";
|
||||
|
||||
public static final String KIND_INTERFACE = "INTERFACE";
|
||||
|
||||
public static final String KIND_MODULE = "MODULE";
|
||||
|
||||
public static final String KIND_PROPERTY = "PROPERTY";
|
||||
|
||||
public static final String KIND_UNIT = "UNIT";
|
||||
|
||||
public static final String KIND_VALUE = "VALUE";
|
||||
|
||||
public static final String KIND_ENUM = "ENUM";
|
||||
|
||||
public static final String KIND_KEYWORD = "KEYWORD";
|
||||
|
||||
public static final String KIND_SNIPPET = "SNIPPET";
|
||||
|
||||
public static final String KIND_COLOR = "COLOR";
|
||||
|
||||
public static final String KIND_FILE = "FILE";
|
||||
|
||||
public static final String KIND_REFERENCE = "REFERENCE";
|
||||
|
||||
public static final String KIND_UNKNOWN = "UNKNOWN";
|
||||
|
||||
/**
|
||||
* The prefix that should be replaced with this proposal.
|
||||
*/
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* The proposed text to be inserted.
|
||||
*/
|
||||
private String proposal;
|
||||
|
||||
/**
|
||||
* The text seen by the user in the list of proposals.
|
||||
*/
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* Additional description to include in the list of proposals.
|
||||
* <p>
|
||||
* This property may not be supported by all editor frameworks.
|
||||
* </p>
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Documentation for the proposal proposals.
|
||||
* <p>
|
||||
* This property may not be supported by all editor frameworks.
|
||||
* </p>
|
||||
*/
|
||||
private String documentation;
|
||||
|
||||
/**
|
||||
* The absolute cursor position to apply after the proposal has been inserted. If omitted, the cursor it set to the
|
||||
* end of the inserted proposal.
|
||||
* <p>
|
||||
* This property may not be supported by all editor frameworks.
|
||||
* </p>
|
||||
*/
|
||||
private Integer escapePosition;
|
||||
|
||||
/**
|
||||
* Additional text replacements to apply when this proposal is selected.
|
||||
* <p>
|
||||
* This property may not be supported by all editor frameworks.
|
||||
* </p>
|
||||
*/
|
||||
private final List<ReplaceRegion> textReplacements = new ArrayList<ReplaceRegion>();
|
||||
|
||||
/**
|
||||
* Regions to be edited by the user after the proposal has been inserted. Usually the <em>tab</em> key navigates
|
||||
* through the edit positions, and <em>enter</em> jumps to the {@code escapePosition}.
|
||||
* <p>
|
||||
* This property may not be supported by all editor frameworks.
|
||||
* </p>
|
||||
*/
|
||||
private final List<TextRegion> editPositions = new ArrayList<TextRegion>();
|
||||
|
||||
/**
|
||||
* The EObject or IEObjectDescription for which this entry has been created, if any. This field is <em>not</em>
|
||||
* serialized when the entry is sent over a communication channel.
|
||||
*/
|
||||
private transient Object source;
|
||||
|
||||
/**
|
||||
* The kind of element that is proposed. Could be one of the constants below or something specific a concrete client
|
||||
* understands. Must not be null.
|
||||
*/
|
||||
private String kind = ContentAssistEntry.KIND_UNKNOWN;
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getProposal() {
|
||||
return proposal;
|
||||
}
|
||||
|
||||
public void setProposal(String proposal) {
|
||||
this.proposal = proposal;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDocumentation() {
|
||||
return documentation;
|
||||
}
|
||||
|
||||
public void setDocumentation(String documentation) {
|
||||
this.documentation = documentation;
|
||||
}
|
||||
|
||||
public Integer getEscapePosition() {
|
||||
return escapePosition;
|
||||
}
|
||||
|
||||
public void setEscapePosition(Integer escapePosition) {
|
||||
this.escapePosition = escapePosition;
|
||||
}
|
||||
|
||||
public List<ReplaceRegion> getTextReplacements() {
|
||||
return textReplacements;
|
||||
}
|
||||
|
||||
public List<TextRegion> getEditPositions() {
|
||||
return editPositions;
|
||||
}
|
||||
|
||||
public Object getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setKind(String kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this);
|
||||
b.skipNulls();
|
||||
b.add("prefix", this.prefix);
|
||||
b.add("proposal", this.proposal);
|
||||
b.add("label", this.label);
|
||||
b.add("description", this.description);
|
||||
b.add("documentation", this.documentation);
|
||||
b.add("escapePosition", this.escapePosition);
|
||||
b.add("textReplacements", this.textReplacements);
|
||||
b.add("editPositions", this.editPositions);
|
||||
b.add("kind", this.kind);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ContentAssistEntry other = (ContentAssistEntry) obj;
|
||||
if (this.prefix == null) {
|
||||
if (other.prefix != null)
|
||||
return false;
|
||||
} else if (!this.prefix.equals(other.prefix))
|
||||
return false;
|
||||
if (this.proposal == null) {
|
||||
if (other.proposal != null)
|
||||
return false;
|
||||
} else if (!this.proposal.equals(other.proposal))
|
||||
return false;
|
||||
if (this.label == null) {
|
||||
if (other.label != null)
|
||||
return false;
|
||||
} else if (!this.label.equals(other.label))
|
||||
return false;
|
||||
if (this.description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!this.description.equals(other.description))
|
||||
return false;
|
||||
if (this.documentation == null) {
|
||||
if (other.documentation != null)
|
||||
return false;
|
||||
} else if (!this.documentation.equals(other.documentation))
|
||||
return false;
|
||||
if (this.escapePosition == null) {
|
||||
if (other.escapePosition != null)
|
||||
return false;
|
||||
} else if (!this.escapePosition.equals(other.escapePosition))
|
||||
return false;
|
||||
if (this.textReplacements == null) {
|
||||
if (other.textReplacements != null)
|
||||
return false;
|
||||
} else if (!this.textReplacements.equals(other.textReplacements))
|
||||
return false;
|
||||
if (this.editPositions == null) {
|
||||
if (other.editPositions != null)
|
||||
return false;
|
||||
} else if (!this.editPositions.equals(other.editPositions))
|
||||
return false;
|
||||
if (this.kind == null) {
|
||||
if (other.kind != null)
|
||||
return false;
|
||||
} else if (!this.kind.equals(other.kind))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.prefix == null) ? 0 : this.prefix.hashCode());
|
||||
result = prime * result + ((this.proposal == null) ? 0 : this.proposal.hashCode());
|
||||
result = prime * result + ((this.label == null) ? 0 : this.label.hashCode());
|
||||
result = prime * result + ((this.description == null) ? 0 : this.description.hashCode());
|
||||
result = prime * result + ((this.documentation == null) ? 0 : this.documentation.hashCode());
|
||||
result = prime * result + ((this.escapePosition == null) ? 0 : this.escapePosition.hashCode());
|
||||
result = prime * result + ((this.textReplacements == null) ? 0 : this.textReplacements.hashCode());
|
||||
result = prime * result + ((this.editPositions == null) ? 0 : this.editPositions.hashCode());
|
||||
return prime * result + ((this.kind == null) ? 0 : this.kind.hashCode());
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.contentassist
|
||||
|
||||
import java.util.ArrayList
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.EqualsHashCode
|
||||
import org.eclipse.xtend.lib.annotations.ToString
|
||||
import org.eclipse.xtext.util.ReplaceRegion
|
||||
import org.eclipse.xtext.util.TextRegion
|
||||
|
||||
/**
|
||||
* @noreference
|
||||
*/
|
||||
@Accessors
|
||||
@ToString(skipNulls = true)
|
||||
@EqualsHashCode
|
||||
class ContentAssistEntry {
|
||||
|
||||
/**
|
||||
* The prefix that should be replaced with this proposal.
|
||||
*/
|
||||
String prefix
|
||||
|
||||
/**
|
||||
* The proposed text to be inserted.
|
||||
*/
|
||||
String proposal
|
||||
|
||||
/**
|
||||
* The text seen by the user in the list of proposals.
|
||||
*/
|
||||
String label
|
||||
|
||||
/**
|
||||
* Additional description to include in the list of proposals.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
String description
|
||||
|
||||
/**
|
||||
* Documentation for the proposal proposals.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
String documentation
|
||||
|
||||
/**
|
||||
* The absolute cursor position to apply after the proposal has been inserted.
|
||||
* If omitted, the cursor it set to the end of the inserted proposal.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
Integer escapePosition
|
||||
|
||||
/**
|
||||
* Additional text replacements to apply when this proposal is selected.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
val textReplacements = new ArrayList<ReplaceRegion>
|
||||
|
||||
/**
|
||||
* Regions to be edited by the user after the proposal has been inserted.
|
||||
* Usually the <em>tab</em> key navigates through the edit positions, and <em>enter</em>
|
||||
* jumps to the {@code escapePosition}.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
val editPositions = new ArrayList<TextRegion>
|
||||
|
||||
/**
|
||||
* The EObject or IEObjectDescription for which this entry has been created, if any.
|
||||
* This field is <em>not</em> serialized when the entry is sent over a communication channel.
|
||||
*/
|
||||
transient Object source
|
||||
|
||||
/**
|
||||
* The kind of element that is proposed. Could be one of the constants below or something specific a concrete client understands.
|
||||
* Must not be null.
|
||||
*/
|
||||
String kind = KIND_UNKNOWN
|
||||
|
||||
public static val KIND_TEXT = "TEXT"
|
||||
public static val KIND_METHOD = "METHOD"
|
||||
public static val KIND_FUNCTION = "FUNCTION"
|
||||
public static val KIND_CONSTRUCTOR = "CONSTRUCTOR"
|
||||
public static val KIND_FIELD = "FIELD"
|
||||
public static val KIND_VARIABLE = "VARIABLE"
|
||||
public static val KIND_CLASS = "CLASS"
|
||||
public static val KIND_INTERFACE = "INTERFACE"
|
||||
public static val KIND_MODULE = "MODULE"
|
||||
public static val KIND_PROPERTY = "PROPERTY"
|
||||
public static val KIND_UNIT = "UNIT"
|
||||
public static val KIND_VALUE = "VALUE"
|
||||
public static val KIND_ENUM = "ENUM"
|
||||
public static val KIND_KEYWORD = "KEYWORD"
|
||||
public static val KIND_SNIPPET = "SNIPPET"
|
||||
public static val KIND_COLOR = "COLOR"
|
||||
public static val KIND_FILE = "FILE"
|
||||
public static val KIND_REFERENCE = "REFERENCE"
|
||||
public static val KIND_UNKNOWN = "UNKNOWN"
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*
|
||||
* @since 2.11
|
||||
*/
|
||||
public class IdeContentProposalAcceptor
|
||||
implements IIdeContentProposalAcceptor, Comparator<Pair<Integer, ContentAssistEntry>> {
|
||||
|
||||
protected final Set<Pair<Integer, ContentAssistEntry>> entries = new TreeSet<Pair<Integer, ContentAssistEntry>>(
|
||||
this);
|
||||
|
||||
@Override
|
||||
public void accept(ContentAssistEntry entry, int priority) {
|
||||
if (entry != null) {
|
||||
if (entry.getProposal() == null)
|
||||
throw new IllegalArgumentException("Proposal must not be null.");
|
||||
entries.add(Pair.of(priority, entry));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptMoreProposals() {
|
||||
return entries.size() < 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Pair<Integer, ContentAssistEntry> p1, Pair<Integer, ContentAssistEntry> p2) {
|
||||
int prioResult = p2.getKey().compareTo(p1.getKey());
|
||||
if (prioResult != 0)
|
||||
return prioResult;
|
||||
String s1 = p1.getValue().getLabel() != null ? p1.getValue().getLabel() : p1.getValue().getProposal();
|
||||
String s2 = p2.getValue().getLabel() != null ? p2.getValue().getLabel() : p2.getValue().getProposal();
|
||||
int ignoreCase = s1.compareToIgnoreCase(s2);
|
||||
if (ignoreCase == 0) {
|
||||
return s1.compareTo(s2);
|
||||
}
|
||||
return ignoreCase;
|
||||
}
|
||||
|
||||
public Iterable<ContentAssistEntry> getEntries() {
|
||||
return Iterables.transform(entries, e -> e.getValue());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.contentassist
|
||||
|
||||
import java.util.Comparator
|
||||
import java.util.TreeSet
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*
|
||||
* @since 2.11
|
||||
*/
|
||||
class IdeContentProposalAcceptor implements IIdeContentProposalAcceptor, Comparator<Pair<Integer, ContentAssistEntry>> {
|
||||
|
||||
protected val entries = new TreeSet<Pair<Integer, ContentAssistEntry>>(this)
|
||||
|
||||
override accept(ContentAssistEntry entry, int priority) {
|
||||
if (entry !== null) {
|
||||
if (entry.proposal === null)
|
||||
throw new IllegalArgumentException('proposal must not be null.')
|
||||
entries.add(priority -> entry)
|
||||
}
|
||||
}
|
||||
|
||||
override canAcceptMoreProposals() {
|
||||
entries.size < 100
|
||||
}
|
||||
|
||||
override compare(Pair<Integer, ContentAssistEntry> p1, Pair<Integer, ContentAssistEntry> p2) {
|
||||
val prioResult = p2.key.compareTo(p1.key)
|
||||
if (prioResult != 0)
|
||||
return prioResult
|
||||
val s1 = p1.value.label ?: p1.value.proposal
|
||||
val s2 = p2.value.label ?: p2.value.proposal
|
||||
val ignoreCase = s1.compareToIgnoreCase(s2)
|
||||
if (ignoreCase === 0) {
|
||||
return s1.compareTo(s2)
|
||||
}
|
||||
return ignoreCase
|
||||
}
|
||||
|
||||
def Iterable<ContentAssistEntry> getEntries() {
|
||||
entries.map[value]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Factory for content assist entries. Whenever possible, you should use this creator instead of building entries
|
||||
* directly, since prefix matching and conflict handling is done here.
|
||||
*
|
||||
* @since 2.10
|
||||
* @noreference
|
||||
*/
|
||||
public class IdeContentProposalCreator {
|
||||
@Inject
|
||||
private IPrefixMatcher prefixMatcher;
|
||||
|
||||
@Inject
|
||||
private IProposalConflictHelper conflictHelper;
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(String proposal, ContentAssistContext context) {
|
||||
return createProposal(proposal, context.getPrefix(), context, ContentAssistEntry.KIND_UNKNOWN, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry of kind snippet with the given proposal and label and the prefix from the context, or null if
|
||||
* the proposal is not valid.
|
||||
*
|
||||
* @since 2.16
|
||||
*/
|
||||
public ContentAssistEntry createSnippet(String proposal, String label, ContentAssistContext context) {
|
||||
return createProposal(proposal, context.getPrefix(), context, ContentAssistEntry.KIND_SNIPPET,
|
||||
(it) -> it.setLabel(label));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(String proposal, ContentAssistContext context,
|
||||
Procedure1<? super ContentAssistEntry> init) {
|
||||
return createProposal(proposal, context.getPrefix(), context, ContentAssistEntry.KIND_UNKNOWN, init);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(String proposal, ContentAssistContext context, String kind,
|
||||
Procedure1<? super ContentAssistEntry> init) {
|
||||
return createProposal(proposal, context.getPrefix(), context, kind, init);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and prefix, or null if the proposal is not valid. If it is valid, the
|
||||
* initializer function is applied to it.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(String proposal, String prefix, ContentAssistContext context, String kind,
|
||||
Procedure1<? super ContentAssistEntry> init) {
|
||||
if (isValidProposal(proposal, prefix, context)) {
|
||||
ContentAssistEntry result = new ContentAssistEntry();
|
||||
result.setProposal(proposal);
|
||||
result.setPrefix(prefix);
|
||||
if (kind != null) {
|
||||
result.setKind(kind);
|
||||
}
|
||||
if (init != null) {
|
||||
init.apply(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isValidProposal(String proposal, String prefix, ContentAssistContext context) {
|
||||
return !Strings.isNullOrEmpty(proposal) && prefixMatcher.isCandidateMatchingPrefix(proposal, prefix)
|
||||
&& !conflictHelper.existsConflict(proposal, context);
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.contentassist
|
||||
|
||||
import com.google.inject.Inject
|
||||
|
||||
/**
|
||||
* Factory for content assist entries. Whenever possible, you should use this creator instead of building entries
|
||||
* directly, since prefix matching and conflict handling is done here.
|
||||
*
|
||||
* @since 2.10
|
||||
* @noreference
|
||||
*/
|
||||
class IdeContentProposalCreator {
|
||||
|
||||
@Inject IPrefixMatcher prefixMatcher
|
||||
|
||||
@Inject IProposalConflictHelper conflictHelper
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
*/
|
||||
def ContentAssistEntry createProposal(String proposal, ContentAssistContext context) {
|
||||
createProposal(proposal, context.prefix, context, ContentAssistEntry.KIND_UNKNOWN, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry of kind snippet with the given proposal and label and the prefix from the context, or null if the proposal is not valid.
|
||||
* @since 2.16
|
||||
*/
|
||||
def ContentAssistEntry createSnippet(String proposal, String label, ContentAssistContext context) {
|
||||
createProposal(proposal, context.prefix, context, ContentAssistEntry.KIND_SNIPPET) [
|
||||
it.label = label
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
def ContentAssistEntry createProposal(String proposal, ContentAssistContext context, (ContentAssistEntry)=>void init) {
|
||||
createProposal(proposal, context.prefix, context, ContentAssistEntry.KIND_UNKNOWN, init)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
def ContentAssistEntry createProposal(String proposal, ContentAssistContext context, String kind, (ContentAssistEntry)=>void init) {
|
||||
createProposal(proposal, context.prefix, context, kind, init)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and prefix, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
def ContentAssistEntry createProposal(String proposal, String prefix, ContentAssistContext context, String kind,
|
||||
(ContentAssistEntry)=>void init) {
|
||||
if (isValidProposal(proposal, prefix, context)) {
|
||||
val result = new ContentAssistEntry
|
||||
result.proposal = proposal
|
||||
result.prefix = prefix
|
||||
if (kind !== null)
|
||||
result.kind = kind
|
||||
if (init !== null)
|
||||
init.apply(result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
def boolean isValidProposal(String proposal, String prefix, ContentAssistContext context) {
|
||||
!proposal.nullOrEmpty && prefixMatcher.isCandidateMatchingPrefix(proposal, prefix)
|
||||
&& !conflictHelper.existsConflict(proposal, context)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Determines priorities for content assist proposal entries. The priorities can be used to sort the list of proposals.
|
||||
*
|
||||
* @noreference
|
||||
*/
|
||||
@Singleton
|
||||
public class IdeContentProposalPriorities {
|
||||
private int crossRefPriority = 500;
|
||||
|
||||
private int defaultPriority = 400;
|
||||
|
||||
private int keywordPriority = 300;
|
||||
|
||||
protected int adjustPriority(ContentAssistEntry entry, int priority) {
|
||||
if (entry == null) {
|
||||
return priority;
|
||||
}
|
||||
int adjustedPriority = priority;
|
||||
if (!Character.isLetter(entry.getProposal().charAt(0))) {
|
||||
adjustedPriority = adjustedPriority - 30;
|
||||
}
|
||||
if (Objects.equal(entry.getProposal(), entry.getPrefix())) {
|
||||
adjustedPriority = adjustedPriority - 20;
|
||||
}
|
||||
return adjustedPriority;
|
||||
}
|
||||
|
||||
public int getCrossRefPriority(IEObjectDescription objectDesc, ContentAssistEntry entry) {
|
||||
return adjustPriority(entry, this.crossRefPriority);
|
||||
}
|
||||
|
||||
public int getDefaultPriority(ContentAssistEntry entry) {
|
||||
return adjustPriority(entry, this.defaultPriority);
|
||||
}
|
||||
|
||||
public int getKeywordPriority(String keyword, ContentAssistEntry entry) {
|
||||
return adjustPriority(entry, this.keywordPriority);
|
||||
}
|
||||
|
||||
protected int getCrossRefPriority() {
|
||||
return crossRefPriority;
|
||||
}
|
||||
|
||||
protected void setCrossRefPriority(int crossRefPriority) {
|
||||
this.crossRefPriority = crossRefPriority;
|
||||
}
|
||||
|
||||
protected int getDefaultPriority() {
|
||||
return defaultPriority;
|
||||
}
|
||||
|
||||
protected void setDefaultPriority(int defaultPriority) {
|
||||
this.defaultPriority = defaultPriority;
|
||||
}
|
||||
|
||||
protected int getKeywordPriority() {
|
||||
return keywordPriority;
|
||||
}
|
||||
|
||||
protected void setKeywordPriority(int keywordPriority) {
|
||||
this.keywordPriority = keywordPriority;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.contentassist
|
||||
|
||||
import com.google.inject.Singleton
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry
|
||||
import org.eclipse.xtext.resource.IEObjectDescription
|
||||
|
||||
/**
|
||||
* Determines priorities for content assist proposal entries. The priorities can be used
|
||||
* to sort the list of proposals.
|
||||
* @noreference
|
||||
*/
|
||||
@Singleton
|
||||
@Accessors(PROTECTED_GETTER, PROTECTED_SETTER)
|
||||
class IdeContentProposalPriorities {
|
||||
|
||||
int crossRefPriority = 500
|
||||
|
||||
int defaultPriority = 400
|
||||
|
||||
int keywordPriority = 300
|
||||
|
||||
protected def adjustPriority(ContentAssistEntry entry, int priority) {
|
||||
if (entry === null)
|
||||
return priority
|
||||
var adjustedPriority = priority
|
||||
if (!Character.isLetter(entry.proposal.charAt(0)))
|
||||
adjustedPriority -= 30
|
||||
if (entry.proposal == entry.prefix)
|
||||
adjustedPriority -= 20
|
||||
return adjustedPriority
|
||||
}
|
||||
|
||||
def int getCrossRefPriority(IEObjectDescription objectDesc, ContentAssistEntry entry) {
|
||||
adjustPriority(entry, crossRefPriority)
|
||||
}
|
||||
|
||||
def int getDefaultPriority(ContentAssistEntry entry) {
|
||||
adjustPriority(entry, defaultPriority)
|
||||
}
|
||||
|
||||
def int getKeywordPriority(String keyword, ContentAssistEntry entry) {
|
||||
adjustPriority(entry, keywordPriority)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.xtext.CrossReference;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.scoping.IScope;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Special content assist proposal provider for cross-references.
|
||||
*
|
||||
* @noreference
|
||||
*/
|
||||
public class IdeCrossrefProposalProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(IdeCrossrefProposalProvider.class);
|
||||
|
||||
@Inject
|
||||
private IQualifiedNameConverter qualifiedNameConverter;
|
||||
|
||||
@Inject
|
||||
private IdeContentProposalCreator proposalCreator;
|
||||
|
||||
@Inject
|
||||
private IdeContentProposalPriorities proposalPriorities;
|
||||
|
||||
public void lookupCrossReference(IScope scope, CrossReference crossReference, ContentAssistContext context,
|
||||
IIdeContentProposalAcceptor acceptor, Predicate<IEObjectDescription> filter) {
|
||||
try {
|
||||
for (IEObjectDescription candidate : queryScope(scope, crossReference, context)) {
|
||||
if (!acceptor.canAcceptMoreProposals()) {
|
||||
return;
|
||||
}
|
||||
if (filter.apply(candidate)) {
|
||||
ContentAssistEntry entry = createProposal(candidate, crossReference, context);
|
||||
acceptor.accept(entry, proposalPriorities.getCrossRefPriority(candidate, entry));
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
LOG.error("Failed to create content assist proposals for cross-reference.", uoe);
|
||||
}
|
||||
}
|
||||
|
||||
protected Iterable<IEObjectDescription> queryScope(IScope scope, CrossReference crossReference,
|
||||
ContentAssistContext context) {
|
||||
return scope.getAllElements();
|
||||
}
|
||||
|
||||
protected ContentAssistEntry createProposal(IEObjectDescription candidate, CrossReference crossRef,
|
||||
ContentAssistContext context) {
|
||||
return proposalCreator.createProposal(qualifiedNameConverter.toString(candidate.getName()), context, (e) -> {
|
||||
e.setSource(candidate);
|
||||
e.setDescription(candidate.getEClass() != null ? candidate.getEClass().getName() : null);
|
||||
e.setKind(ContentAssistEntry.KIND_REFERENCE);
|
||||
});
|
||||
}
|
||||
|
||||
protected IQualifiedNameConverter getQualifiedNameConverter() {
|
||||
return qualifiedNameConverter;
|
||||
}
|
||||
|
||||
protected IdeContentProposalCreator getProposalCreator() {
|
||||
return proposalCreator;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.contentassist
|
||||
|
||||
import com.google.common.base.Predicate
|
||||
import com.google.inject.Inject
|
||||
import org.apache.log4j.Logger
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.CrossReference
|
||||
import org.eclipse.xtext.naming.IQualifiedNameConverter
|
||||
import org.eclipse.xtext.resource.IEObjectDescription
|
||||
import org.eclipse.xtext.scoping.IScope
|
||||
|
||||
/**
|
||||
* Special content assist proposal provider for cross-references.
|
||||
* @noreference
|
||||
*/
|
||||
class IdeCrossrefProposalProvider {
|
||||
|
||||
static val LOG = Logger.getLogger(IdeCrossrefProposalProvider)
|
||||
|
||||
@Accessors(PROTECTED_GETTER)
|
||||
@Inject IQualifiedNameConverter qualifiedNameConverter
|
||||
|
||||
@Accessors(PROTECTED_GETTER)
|
||||
@Inject IdeContentProposalCreator proposalCreator
|
||||
|
||||
@Inject IdeContentProposalPriorities proposalPriorities
|
||||
|
||||
def void lookupCrossReference(IScope scope, CrossReference crossReference, ContentAssistContext context,
|
||||
IIdeContentProposalAcceptor acceptor, Predicate<IEObjectDescription> filter) {
|
||||
try {
|
||||
for (candidate : queryScope(scope, crossReference, context)) {
|
||||
if (!acceptor.canAcceptMoreProposals) {
|
||||
return
|
||||
}
|
||||
if (filter.apply(candidate)) {
|
||||
val entry = createProposal(candidate, crossReference, context)
|
||||
acceptor.accept(entry, proposalPriorities.getCrossRefPriority(candidate, entry))
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
LOG.error('Failed to create content assist proposals for cross-reference.', uoe)
|
||||
}
|
||||
}
|
||||
|
||||
protected def queryScope(IScope scope, CrossReference crossReference, ContentAssistContext context) {
|
||||
return scope.allElements
|
||||
}
|
||||
|
||||
protected def ContentAssistEntry createProposal(IEObjectDescription candidate, CrossReference crossRef, ContentAssistContext context) {
|
||||
proposalCreator.createProposal(qualifiedNameConverter.toString(candidate.name), context) [
|
||||
source = candidate
|
||||
description = candidate.getEClass?.name
|
||||
kind = ContentAssistEntry.KIND_REFERENCE
|
||||
]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.util.Wrapper;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
public class DefaultHierarchyNode implements IHierarchyNode {
|
||||
private IHierarchyNode parent;
|
||||
|
||||
private boolean mayHaveChildren;
|
||||
|
||||
private IEObjectDescription element;
|
||||
|
||||
private final List<IHierarchyNodeReference> references = new ArrayList<>();
|
||||
|
||||
private Wrapper<Boolean> recursive;
|
||||
|
||||
@Override
|
||||
public Object getNavigationElement() {
|
||||
if (!references.isEmpty()) {
|
||||
return references.get(0);
|
||||
} else {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecursive() {
|
||||
if (recursive == null) {
|
||||
recursive = Wrapper.wrap(internalIsRecursive());
|
||||
}
|
||||
return recursive.get().booleanValue();
|
||||
}
|
||||
|
||||
protected boolean internalIsRecursive() {
|
||||
IHierarchyNode node = parent;
|
||||
while (node != null) {
|
||||
URI nodeElementUri = node.getElement().getEObjectURI();
|
||||
URI elementUri = this.element.getEObjectURI();
|
||||
if (Objects.equal(nodeElementUri, elementUri)) {
|
||||
return true;
|
||||
}
|
||||
node = node.getParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayHaveChildren() {
|
||||
return mayHaveChildren;
|
||||
}
|
||||
|
||||
public IHierarchyNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(IHierarchyNode parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void setMayHaveChildren(boolean mayHaveChildren) {
|
||||
this.mayHaveChildren = mayHaveChildren;
|
||||
}
|
||||
|
||||
public IEObjectDescription getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public void setElement(IEObjectDescription element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public List<IHierarchyNodeReference> getReferences() {
|
||||
return references;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy
|
||||
|
||||
import java.util.List
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.resource.IEObjectDescription
|
||||
import org.eclipse.xtext.util.Wrapper
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
class DefaultHierarchyNode implements IHierarchyNode {
|
||||
|
||||
@Accessors
|
||||
IHierarchyNode parent
|
||||
|
||||
@Accessors(PUBLIC_SETTER)
|
||||
boolean mayHaveChildren
|
||||
|
||||
@Accessors
|
||||
IEObjectDescription element
|
||||
|
||||
@Accessors(PUBLIC_GETTER)
|
||||
val List<IHierarchyNodeReference> references = <IHierarchyNodeReference>newArrayList
|
||||
|
||||
Wrapper<Boolean> recursive
|
||||
|
||||
override getNavigationElement() {
|
||||
return references.head ?: element
|
||||
}
|
||||
|
||||
override boolean isRecursive() {
|
||||
if (recursive === null)
|
||||
recursive = Wrapper.wrap(internalIsRecursive)
|
||||
return recursive.get
|
||||
}
|
||||
|
||||
protected def boolean internalIsRecursive() {
|
||||
var node = parent
|
||||
while (node !== null) {
|
||||
if (node.element.EObjectURI == element.EObjectURI)
|
||||
return true
|
||||
node = node.parent
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override mayHaveChildren() {
|
||||
mayHaveChildren
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy;
|
||||
|
||||
import org.eclipse.xtext.util.ITextRegion;
|
||||
import org.eclipse.xtext.util.ITextRegionWithLineInformation;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
public class DefaultHierarchyNodeReference implements IHierarchyNodeReference {
|
||||
private final String text;
|
||||
|
||||
private final ITextRegionWithLineInformation textRegion;
|
||||
|
||||
private final Object navigationElement;
|
||||
|
||||
public DefaultHierarchyNodeReference(String text, ITextRegionWithLineInformation textRegion,
|
||||
Object navigationElement) {
|
||||
this.text = text;
|
||||
this.textRegion = textRegion;
|
||||
this.navigationElement = navigationElement;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public ITextRegionWithLineInformation getTextRegion() {
|
||||
return textRegion;
|
||||
}
|
||||
|
||||
public Object getNavigationElement() {
|
||||
return navigationElement;
|
||||
}
|
||||
|
||||
public boolean contains(ITextRegion other) {
|
||||
return textRegion.contains(other);
|
||||
}
|
||||
|
||||
public boolean contains(int offset) {
|
||||
return textRegion.contains(offset);
|
||||
}
|
||||
|
||||
public int getEndLineNumber() {
|
||||
return textRegion.getEndLineNumber();
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return textRegion.getLength();
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return textRegion.getLineNumber();
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return textRegion.getOffset();
|
||||
}
|
||||
|
||||
public ITextRegion merge(ITextRegion region) {
|
||||
return textRegion.merge(region);
|
||||
}
|
||||
|
||||
public ITextRegionWithLineInformation merge(ITextRegionWithLineInformation other) {
|
||||
return textRegion.merge(other);
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy
|
||||
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.Delegate
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import org.eclipse.xtext.util.ITextRegionWithLineInformation
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
@Accessors
|
||||
@FinalFieldsConstructor
|
||||
class DefaultHierarchyNodeReference implements IHierarchyNodeReference {
|
||||
val String text
|
||||
@Delegate
|
||||
val ITextRegionWithLineInformation textRegion
|
||||
val Object navigationElement
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
public class DefaultHierarchyRoot implements IHierarchyRoot {
|
||||
private final List<IHierarchyNode> roots = new ArrayList<>();
|
||||
|
||||
public List<IHierarchyNode> getRoots() {
|
||||
return roots;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy
|
||||
|
||||
import java.util.List
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
@Accessors
|
||||
class DefaultHierarchyRoot implements IHierarchyRoot {
|
||||
val List<IHierarchyNode> roots = <IHierarchyNode>newArrayList
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2014, 2017 itemis AG (http://www.itemis.eu) and others.
|
||||
* Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
|
@ -14,9 +14,8 @@ import org.eclipse.xtext.ide.editor.model.TokenTypeToStringMapper;
|
|||
* @author Anton Kosyakov - Initial contribution and API
|
||||
* @since 2.9
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public abstract class AbstractAntlrTokenToAttributeIdMapper extends TokenTypeToStringMapper {
|
||||
public String getId(final int tokenType) {
|
||||
return this.getMappedValue(tokenType);
|
||||
}
|
||||
public String getId(int tokenType) {
|
||||
return getMappedValue(tokenType);
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2014, 2017 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.syntaxcoloring
|
||||
|
||||
import org.eclipse.xtext.ide.editor.model.TokenTypeToStringMapper
|
||||
|
||||
/**
|
||||
* @author Anton Kosyakov - Initial contribution and API
|
||||
* @since 2.9
|
||||
*/
|
||||
abstract class AbstractAntlrTokenToAttributeIdMapper extends TokenTypeToStringMapper {
|
||||
|
||||
def String getId(int tokenType) {
|
||||
getMappedValue(tokenType)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,192 @@
|
|||
/**
|
||||
* Copyright (c) 2018, 2020 TypeFox and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.server.symbol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.SymbolKind;
|
||||
import org.eclipse.xtext.ide.server.DocumentExtensions;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameProvider;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Maps an EObject to the corresponding {@link DocumentSymbol document symbol}.
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public class DocumentSymbolMapper {
|
||||
/**
|
||||
* Provides {@link DocumentSymbol#detail detail} for a {@link DocumentSymbol document symbol}.
|
||||
* <p>
|
||||
* Always returns an empty string by default.
|
||||
*
|
||||
* @see DocumentSymbol#detail
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolDetailsProvider {
|
||||
public String getDetails(EObject object) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a human-readable name for the document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#name
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolNameProvider {
|
||||
@Inject
|
||||
private IQualifiedNameProvider qualifiedNameProvider;
|
||||
|
||||
public String getName(EObject object) {
|
||||
return getName(object != null ? qualifiedNameProvider.getFullyQualifiedName(object) : null);
|
||||
}
|
||||
|
||||
public String getName(IEObjectDescription description) {
|
||||
return getName(description != null ? description.getName() : null);
|
||||
}
|
||||
|
||||
protected String getName(QualifiedName qualifiedName) {
|
||||
if (qualifiedName != null) {
|
||||
return qualifiedName.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the {@link SymbolKind symbol kind} information for the document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#kind
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolKindProvider {
|
||||
public SymbolKind getSymbolKind(EObject object) {
|
||||
return getSymbolKind(object != null ? object.eClass() : null);
|
||||
}
|
||||
|
||||
public SymbolKind getSymbolKind(IEObjectDescription description) {
|
||||
return this.getSymbolKind(description != null ? description.getEClass() : null);
|
||||
}
|
||||
|
||||
protected SymbolKind getSymbolKind(EClass clazz) {
|
||||
return SymbolKind.Property;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides {@link DocumentSymbol#range range} and {@link DocumentSymbol#selectionRange selection range} for a
|
||||
* document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#range
|
||||
* @see DocumentSymbol#selectionRange
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolRangeProvider {
|
||||
@Inject
|
||||
private DocumentExtensions documentExtensions;
|
||||
|
||||
/**
|
||||
* The range enclosing this symbol not including leading/trailing whitespace but everything else like comments.
|
||||
*/
|
||||
public Range getRange(EObject object) {
|
||||
Location newFullLocation = documentExtensions.newFullLocation(object);
|
||||
if (newFullLocation != null) {
|
||||
return newFullLocation.getRange();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
|
||||
*/
|
||||
public Range getSelectionRange(EObject object) {
|
||||
Location newLocation = documentExtensions.newLocation(object);
|
||||
if (newLocation != null) {
|
||||
return newLocation.getRange();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a document symbol can be marked as {@link DocumentSymbol#deprecated deprecated}.
|
||||
*
|
||||
* @see DocumentSymbol#deprecated
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolDeprecationInfoProvider {
|
||||
public boolean isDeprecated(EObject object) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDeprecated(IEObjectDescription description) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolNameProvider nameProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolKindProvider kindProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolRangeProvider rangeProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolDetailsProvider detailsProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolDeprecationInfoProvider deprecationInfoProvider;
|
||||
|
||||
/**
|
||||
* Converts the {@code EObject} argument into a {@link DocumentSymbol document symbol} without the
|
||||
* {@link DocumentSymbol#children children} information filled in.
|
||||
*/
|
||||
public DocumentSymbol toDocumentSymbol(EObject object) {
|
||||
DocumentSymbol documentSymbol = new DocumentSymbol();
|
||||
String objectName = nameProvider.getName(object);
|
||||
if (objectName != null) {
|
||||
documentSymbol.setName(objectName);
|
||||
}
|
||||
SymbolKind objectKind = kindProvider.getSymbolKind(object);
|
||||
if (objectKind != null) {
|
||||
documentSymbol.setKind(objectKind);
|
||||
}
|
||||
Range objectRange = rangeProvider.getRange(object);
|
||||
if (objectRange != null) {
|
||||
documentSymbol.setRange(objectRange);
|
||||
}
|
||||
Range objectSelectionRange = rangeProvider.getSelectionRange(object);
|
||||
if (objectSelectionRange != null) {
|
||||
documentSymbol.setSelectionRange(objectSelectionRange);
|
||||
}
|
||||
documentSymbol.setDetail(detailsProvider.getDetails(object));
|
||||
documentSymbol.setDeprecated(deprecationInfoProvider.isDeprecated(object));
|
||||
documentSymbol.setChildren(new ArrayList<>());
|
||||
return documentSymbol;
|
||||
}
|
||||
}
|
|
@ -1,188 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2018 TypeFox and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.server.symbol
|
||||
|
||||
import com.google.common.annotations.Beta
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
import org.eclipse.emf.ecore.EClass
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.lsp4j.DocumentSymbol
|
||||
import org.eclipse.lsp4j.Range
|
||||
import org.eclipse.lsp4j.SymbolKind
|
||||
import org.eclipse.xtext.ide.server.DocumentExtensions
|
||||
import org.eclipse.xtext.naming.IQualifiedNameProvider
|
||||
import org.eclipse.xtext.naming.QualifiedName
|
||||
import org.eclipse.xtext.resource.IEObjectDescription
|
||||
|
||||
/**
|
||||
* Maps an EObject to the corresponding {@link DocumentSymbol document symbol}.
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
class DocumentSymbolMapper {
|
||||
|
||||
@Inject
|
||||
DocumentSymbolNameProvider nameProvider;
|
||||
|
||||
@Inject
|
||||
DocumentSymbolKindProvider kindProvider;
|
||||
|
||||
@Inject
|
||||
DocumentSymbolRangeProvider rangeProvider;
|
||||
|
||||
@Inject
|
||||
DocumentSymbolDetailsProvider detailsProvider;
|
||||
|
||||
@Inject
|
||||
DocumentSymbolDeprecationInfoProvider deprecationInfoProvider;
|
||||
|
||||
/**
|
||||
* Converts the {@code EObject} argument into a {@link DocumentSymbol document symbol} without
|
||||
* the {@link DocumentSymbol#children children} information filled in.
|
||||
*/
|
||||
def DocumentSymbol toDocumentSymbol(EObject object) {
|
||||
return new DocumentSymbol => [
|
||||
val objectName = nameProvider.getName(object)
|
||||
if (objectName !== null) {
|
||||
name = objectName;
|
||||
}
|
||||
val objectKind = kindProvider.getSymbolKind(object);
|
||||
if (objectKind !== null) {
|
||||
kind = objectKind
|
||||
}
|
||||
val objectRange = rangeProvider.getRange(object);
|
||||
if (objectRange !== null) {
|
||||
range = objectRange
|
||||
}
|
||||
val objectSelectionRange = rangeProvider.getSelectionRange(object);
|
||||
if (objectSelectionRange !== null) {
|
||||
selectionRange = objectSelectionRange
|
||||
}
|
||||
detail = detailsProvider.getDetails(object);
|
||||
deprecated = deprecationInfoProvider.isDeprecated(object);
|
||||
children = newArrayList;
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides {@link DocumentSymbol#detail detail} for a {@link DocumentSymbol document symbol}.
|
||||
* <p>
|
||||
* Always returns with an empty string by default.
|
||||
*
|
||||
* @see DocumentSymbol#detail
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
static class DocumentSymbolDetailsProvider {
|
||||
|
||||
def String getDetails(EObject object) {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a human-readable name for the document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#name
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
static class DocumentSymbolNameProvider {
|
||||
|
||||
@Inject
|
||||
extension IQualifiedNameProvider;
|
||||
|
||||
def String getName(EObject object) {
|
||||
return object?.fullyQualifiedName.name;
|
||||
}
|
||||
|
||||
def String getName(IEObjectDescription description) {
|
||||
return description?.name.name;
|
||||
}
|
||||
|
||||
protected def String getName(QualifiedName qualifiedName) {
|
||||
return qualifiedName?.toString;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the {@link SymbolKind symbol kind} information for the document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#kind
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
static class DocumentSymbolKindProvider {
|
||||
|
||||
def SymbolKind getSymbolKind(EObject object) {
|
||||
return object?.eClass.symbolKind;
|
||||
}
|
||||
|
||||
def SymbolKind getSymbolKind(IEObjectDescription description) {
|
||||
return description?.EClass.symbolKind;
|
||||
}
|
||||
|
||||
protected def SymbolKind getSymbolKind(EClass clazz) {
|
||||
return SymbolKind.Property;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides {@link DocumentSymbol#range range} and {@link DocumentSymbol#selectionRange selection range} for a document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#range
|
||||
* @see DocumentSymbol#selectionRange
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
static class DocumentSymbolRangeProvider {
|
||||
|
||||
@Inject
|
||||
extension DocumentExtensions;
|
||||
|
||||
/**
|
||||
* The range enclosing this symbol not including leading/trailing whitespace but everything else
|
||||
* like comments.
|
||||
*/
|
||||
def Range getRange(EObject object) {
|
||||
return object.newFullLocation?.range;
|
||||
}
|
||||
|
||||
/**
|
||||
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
|
||||
*/
|
||||
def Range getSelectionRange(EObject object) {
|
||||
return object.newLocation?.range;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a document symbol can be marked as {@link DocumentSymbol#deprecated deprecated}.
|
||||
*
|
||||
* @see DocumentSymbol#deprecated
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
static class DocumentSymbolDeprecationInfoProvider {
|
||||
|
||||
def boolean isDeprecated(EObject object) {
|
||||
return false;
|
||||
}
|
||||
|
||||
def boolean isDeprecated(IEObjectDescription description) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -114,9 +114,10 @@ public abstract class AbstractIdeTemplateProposalProvider {
|
|||
int _offset = this.context.getReplaceRegion().getOffset();
|
||||
int _currentOffset = this.getCurrentOffset();
|
||||
final int offset = (_offset + _currentOffset);
|
||||
List<TextRegion> _editPositions = this.entry.getEditPositions();
|
||||
int _length = varName.length();
|
||||
TextRegion _textRegion = new TextRegion(offset, _length);
|
||||
this.entry.getEditPositions().add(_textRegion);
|
||||
_editPositions.add(_textRegion);
|
||||
return varName;
|
||||
} else {
|
||||
if ((object instanceof AbstractIdeTemplateProposalProvider.Cursor)) {
|
||||
|
|
|
@ -1,298 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtend.lib.annotations.EqualsHashCode;
|
||||
import org.eclipse.xtend.lib.annotations.ToString;
|
||||
import org.eclipse.xtext.util.ReplaceRegion;
|
||||
import org.eclipse.xtext.util.TextRegion;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @noreference
|
||||
*/
|
||||
@Accessors
|
||||
@ToString(skipNulls = true)
|
||||
@EqualsHashCode
|
||||
@SuppressWarnings("all")
|
||||
public class ContentAssistEntry {
|
||||
/**
|
||||
* The prefix that should be replaced with this proposal.
|
||||
*/
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* The proposed text to be inserted.
|
||||
*/
|
||||
private String proposal;
|
||||
|
||||
/**
|
||||
* The text seen by the user in the list of proposals.
|
||||
*/
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* Additional description to include in the list of proposals.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Documentation for the proposal proposals.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
private String documentation;
|
||||
|
||||
/**
|
||||
* The absolute cursor position to apply after the proposal has been inserted.
|
||||
* If omitted, the cursor it set to the end of the inserted proposal.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
private Integer escapePosition;
|
||||
|
||||
/**
|
||||
* Additional text replacements to apply when this proposal is selected.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
private final ArrayList<ReplaceRegion> textReplacements = new ArrayList<ReplaceRegion>();
|
||||
|
||||
/**
|
||||
* Regions to be edited by the user after the proposal has been inserted.
|
||||
* Usually the <em>tab</em> key navigates through the edit positions, and <em>enter</em>
|
||||
* jumps to the {@code escapePosition}.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
private final ArrayList<TextRegion> editPositions = new ArrayList<TextRegion>();
|
||||
|
||||
/**
|
||||
* The EObject or IEObjectDescription for which this entry has been created, if any.
|
||||
* This field is <em>not</em> serialized when the entry is sent over a communication channel.
|
||||
*/
|
||||
private transient Object source;
|
||||
|
||||
/**
|
||||
* The kind of element that is proposed. Could be one of the constants below or something specific a concrete client understands.
|
||||
* Must not be null.
|
||||
*/
|
||||
private String kind = ContentAssistEntry.KIND_UNKNOWN;
|
||||
|
||||
public static final String KIND_TEXT = "TEXT";
|
||||
|
||||
public static final String KIND_METHOD = "METHOD";
|
||||
|
||||
public static final String KIND_FUNCTION = "FUNCTION";
|
||||
|
||||
public static final String KIND_CONSTRUCTOR = "CONSTRUCTOR";
|
||||
|
||||
public static final String KIND_FIELD = "FIELD";
|
||||
|
||||
public static final String KIND_VARIABLE = "VARIABLE";
|
||||
|
||||
public static final String KIND_CLASS = "CLASS";
|
||||
|
||||
public static final String KIND_INTERFACE = "INTERFACE";
|
||||
|
||||
public static final String KIND_MODULE = "MODULE";
|
||||
|
||||
public static final String KIND_PROPERTY = "PROPERTY";
|
||||
|
||||
public static final String KIND_UNIT = "UNIT";
|
||||
|
||||
public static final String KIND_VALUE = "VALUE";
|
||||
|
||||
public static final String KIND_ENUM = "ENUM";
|
||||
|
||||
public static final String KIND_KEYWORD = "KEYWORD";
|
||||
|
||||
public static final String KIND_SNIPPET = "SNIPPET";
|
||||
|
||||
public static final String KIND_COLOR = "COLOR";
|
||||
|
||||
public static final String KIND_FILE = "FILE";
|
||||
|
||||
public static final String KIND_REFERENCE = "REFERENCE";
|
||||
|
||||
public static final String KIND_UNKNOWN = "UNKNOWN";
|
||||
|
||||
@Pure
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(final String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getProposal() {
|
||||
return this.proposal;
|
||||
}
|
||||
|
||||
public void setProposal(final String proposal) {
|
||||
this.proposal = proposal;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setLabel(final String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getDocumentation() {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
public void setDocumentation(final String documentation) {
|
||||
this.documentation = documentation;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public Integer getEscapePosition() {
|
||||
return this.escapePosition;
|
||||
}
|
||||
|
||||
public void setEscapePosition(final Integer escapePosition) {
|
||||
this.escapePosition = escapePosition;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public ArrayList<ReplaceRegion> getTextReplacements() {
|
||||
return this.textReplacements;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public ArrayList<TextRegion> getEditPositions() {
|
||||
return this.editPositions;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public Object getSource() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public void setSource(final Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getKind() {
|
||||
return this.kind;
|
||||
}
|
||||
|
||||
public void setKind(final String kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this);
|
||||
b.skipNulls();
|
||||
b.add("prefix", this.prefix);
|
||||
b.add("proposal", this.proposal);
|
||||
b.add("label", this.label);
|
||||
b.add("description", this.description);
|
||||
b.add("documentation", this.documentation);
|
||||
b.add("escapePosition", this.escapePosition);
|
||||
b.add("textReplacements", this.textReplacements);
|
||||
b.add("editPositions", this.editPositions);
|
||||
b.add("kind", this.kind);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ContentAssistEntry other = (ContentAssistEntry) obj;
|
||||
if (this.prefix == null) {
|
||||
if (other.prefix != null)
|
||||
return false;
|
||||
} else if (!this.prefix.equals(other.prefix))
|
||||
return false;
|
||||
if (this.proposal == null) {
|
||||
if (other.proposal != null)
|
||||
return false;
|
||||
} else if (!this.proposal.equals(other.proposal))
|
||||
return false;
|
||||
if (this.label == null) {
|
||||
if (other.label != null)
|
||||
return false;
|
||||
} else if (!this.label.equals(other.label))
|
||||
return false;
|
||||
if (this.description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!this.description.equals(other.description))
|
||||
return false;
|
||||
if (this.documentation == null) {
|
||||
if (other.documentation != null)
|
||||
return false;
|
||||
} else if (!this.documentation.equals(other.documentation))
|
||||
return false;
|
||||
if (this.escapePosition == null) {
|
||||
if (other.escapePosition != null)
|
||||
return false;
|
||||
} else if (!this.escapePosition.equals(other.escapePosition))
|
||||
return false;
|
||||
if (this.textReplacements == null) {
|
||||
if (other.textReplacements != null)
|
||||
return false;
|
||||
} else if (!this.textReplacements.equals(other.textReplacements))
|
||||
return false;
|
||||
if (this.editPositions == null) {
|
||||
if (other.editPositions != null)
|
||||
return false;
|
||||
} else if (!this.editPositions.equals(other.editPositions))
|
||||
return false;
|
||||
if (this.kind == null) {
|
||||
if (other.kind != null)
|
||||
return false;
|
||||
} else if (!this.kind.equals(other.kind))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.prefix== null) ? 0 : this.prefix.hashCode());
|
||||
result = prime * result + ((this.proposal== null) ? 0 : this.proposal.hashCode());
|
||||
result = prime * result + ((this.label== null) ? 0 : this.label.hashCode());
|
||||
result = prime * result + ((this.description== null) ? 0 : this.description.hashCode());
|
||||
result = prime * result + ((this.documentation== null) ? 0 : this.documentation.hashCode());
|
||||
result = prime * result + ((this.escapePosition== null) ? 0 : this.escapePosition.hashCode());
|
||||
result = prime * result + ((this.textReplacements== null) ? 0 : this.textReplacements.hashCode());
|
||||
result = prime * result + ((this.editPositions== null) ? 0 : this.editPositions.hashCode());
|
||||
return prime * result + ((this.kind== null) ? 0 : this.kind.hashCode());
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.TreeSet;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*
|
||||
* @since 2.11
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class IdeContentProposalAcceptor implements IIdeContentProposalAcceptor, Comparator<Pair<Integer, ContentAssistEntry>> {
|
||||
protected final TreeSet<Pair<Integer, ContentAssistEntry>> entries = new TreeSet<Pair<Integer, ContentAssistEntry>>(this);
|
||||
|
||||
@Override
|
||||
public void accept(final ContentAssistEntry entry, final int priority) {
|
||||
if ((entry != null)) {
|
||||
String _proposal = entry.getProposal();
|
||||
boolean _tripleEquals = (_proposal == null);
|
||||
if (_tripleEquals) {
|
||||
throw new IllegalArgumentException("proposal must not be null.");
|
||||
}
|
||||
Pair<Integer, ContentAssistEntry> _mappedTo = Pair.<Integer, ContentAssistEntry>of(Integer.valueOf(priority), entry);
|
||||
this.entries.add(_mappedTo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptMoreProposals() {
|
||||
int _size = this.entries.size();
|
||||
return (_size < 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(final Pair<Integer, ContentAssistEntry> p1, final Pair<Integer, ContentAssistEntry> p2) {
|
||||
final int prioResult = p2.getKey().compareTo(p1.getKey());
|
||||
if ((prioResult != 0)) {
|
||||
return prioResult;
|
||||
}
|
||||
String _elvis = null;
|
||||
String _label = p1.getValue().getLabel();
|
||||
if (_label != null) {
|
||||
_elvis = _label;
|
||||
} else {
|
||||
String _proposal = p1.getValue().getProposal();
|
||||
_elvis = _proposal;
|
||||
}
|
||||
final String s1 = _elvis;
|
||||
String _elvis_1 = null;
|
||||
String _label_1 = p2.getValue().getLabel();
|
||||
if (_label_1 != null) {
|
||||
_elvis_1 = _label_1;
|
||||
} else {
|
||||
String _proposal_1 = p2.getValue().getProposal();
|
||||
_elvis_1 = _proposal_1;
|
||||
}
|
||||
final String s2 = _elvis_1;
|
||||
final int ignoreCase = s1.compareToIgnoreCase(s2);
|
||||
if ((ignoreCase == 0)) {
|
||||
return s1.compareTo(s2);
|
||||
}
|
||||
return ignoreCase;
|
||||
}
|
||||
|
||||
public Iterable<ContentAssistEntry> getEntries() {
|
||||
final Function1<Pair<Integer, ContentAssistEntry>, ContentAssistEntry> _function = (Pair<Integer, ContentAssistEntry> it) -> {
|
||||
return it.getValue();
|
||||
};
|
||||
return IterableExtensions.<Pair<Integer, ContentAssistEntry>, ContentAssistEntry>map(this.entries, _function);
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.IPrefixMatcher;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.IProposalConflictHelper;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xbase.lib.StringExtensions;
|
||||
|
||||
/**
|
||||
* Factory for content assist entries. Whenever possible, you should use this creator instead of building entries
|
||||
* directly, since prefix matching and conflict handling is done here.
|
||||
*
|
||||
* @since 2.10
|
||||
* @noreference
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class IdeContentProposalCreator {
|
||||
@Inject
|
||||
private IPrefixMatcher prefixMatcher;
|
||||
|
||||
@Inject
|
||||
private IProposalConflictHelper conflictHelper;
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(final String proposal, final ContentAssistContext context) {
|
||||
return this.createProposal(proposal, context.getPrefix(), context, ContentAssistEntry.KIND_UNKNOWN, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry of kind snippet with the given proposal and label and the prefix from the context, or null if the proposal is not valid.
|
||||
* @since 2.16
|
||||
*/
|
||||
public ContentAssistEntry createSnippet(final String proposal, final String label, final ContentAssistContext context) {
|
||||
final Procedure1<ContentAssistEntry> _function = (ContentAssistEntry it) -> {
|
||||
it.setLabel(label);
|
||||
};
|
||||
return this.createProposal(proposal, context.getPrefix(), context, ContentAssistEntry.KIND_SNIPPET, _function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(final String proposal, final ContentAssistContext context, final Procedure1<? super ContentAssistEntry> init) {
|
||||
return this.createProposal(proposal, context.getPrefix(), context, ContentAssistEntry.KIND_UNKNOWN, init);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and the prefix from the context, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(final String proposal, final ContentAssistContext context, final String kind, final Procedure1<? super ContentAssistEntry> init) {
|
||||
return this.createProposal(proposal, context.getPrefix(), context, kind, init);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entry with the given proposal and prefix, or null if the proposal is not valid.
|
||||
* If it is valid, the initializer function is applied to it.
|
||||
*/
|
||||
public ContentAssistEntry createProposal(final String proposal, final String prefix, final ContentAssistContext context, final String kind, final Procedure1<? super ContentAssistEntry> init) {
|
||||
boolean _isValidProposal = this.isValidProposal(proposal, prefix, context);
|
||||
if (_isValidProposal) {
|
||||
final ContentAssistEntry result = new ContentAssistEntry();
|
||||
result.setProposal(proposal);
|
||||
result.setPrefix(prefix);
|
||||
if ((kind != null)) {
|
||||
result.setKind(kind);
|
||||
}
|
||||
if ((init != null)) {
|
||||
init.apply(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isValidProposal(final String proposal, final String prefix, final ContentAssistContext context) {
|
||||
return (((!StringExtensions.isNullOrEmpty(proposal)) && this.prefixMatcher.isCandidateMatchingPrefix(proposal, prefix)) && (!this.conflictHelper.existsConflict(proposal, context)));
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.inject.Singleton;
|
||||
import org.eclipse.xtend.lib.annotations.AccessorType;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* Determines priorities for content assist proposal entries. The priorities can be used
|
||||
* to sort the list of proposals.
|
||||
* @noreference
|
||||
*/
|
||||
@Singleton
|
||||
@Accessors({ AccessorType.PROTECTED_GETTER, AccessorType.PROTECTED_SETTER })
|
||||
@SuppressWarnings("all")
|
||||
public class IdeContentProposalPriorities {
|
||||
private int crossRefPriority = 500;
|
||||
|
||||
private int defaultPriority = 400;
|
||||
|
||||
private int keywordPriority = 300;
|
||||
|
||||
protected int adjustPriority(final ContentAssistEntry entry, final int priority) {
|
||||
if ((entry == null)) {
|
||||
return priority;
|
||||
}
|
||||
int adjustedPriority = priority;
|
||||
boolean _isLetter = Character.isLetter(entry.getProposal().charAt(0));
|
||||
boolean _not = (!_isLetter);
|
||||
if (_not) {
|
||||
int _adjustedPriority = adjustedPriority;
|
||||
adjustedPriority = (_adjustedPriority - 30);
|
||||
}
|
||||
String _proposal = entry.getProposal();
|
||||
String _prefix = entry.getPrefix();
|
||||
boolean _equals = Objects.equal(_proposal, _prefix);
|
||||
if (_equals) {
|
||||
int _adjustedPriority_1 = adjustedPriority;
|
||||
adjustedPriority = (_adjustedPriority_1 - 20);
|
||||
}
|
||||
return adjustedPriority;
|
||||
}
|
||||
|
||||
public int getCrossRefPriority(final IEObjectDescription objectDesc, final ContentAssistEntry entry) {
|
||||
return this.adjustPriority(entry, this.crossRefPriority);
|
||||
}
|
||||
|
||||
public int getDefaultPriority(final ContentAssistEntry entry) {
|
||||
return this.adjustPriority(entry, this.defaultPriority);
|
||||
}
|
||||
|
||||
public int getKeywordPriority(final String keyword, final ContentAssistEntry entry) {
|
||||
return this.adjustPriority(entry, this.keywordPriority);
|
||||
}
|
||||
|
||||
@Pure
|
||||
protected int getCrossRefPriority() {
|
||||
return this.crossRefPriority;
|
||||
}
|
||||
|
||||
protected void setCrossRefPriority(final int crossRefPriority) {
|
||||
this.crossRefPriority = crossRefPriority;
|
||||
}
|
||||
|
||||
@Pure
|
||||
protected int getDefaultPriority() {
|
||||
return this.defaultPriority;
|
||||
}
|
||||
|
||||
protected void setDefaultPriority(final int defaultPriority) {
|
||||
this.defaultPriority = defaultPriority;
|
||||
}
|
||||
|
||||
@Pure
|
||||
protected int getKeywordPriority() {
|
||||
return this.keywordPriority;
|
||||
}
|
||||
|
||||
protected void setKeywordPriority(final int keywordPriority) {
|
||||
this.keywordPriority = keywordPriority;
|
||||
}
|
||||
}
|
|
@ -13,9 +13,9 @@ import com.google.common.base.Predicate;
|
|||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.emf.ecore.EClassifier;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
|
@ -128,7 +128,7 @@ public class IdeContentProposalProvider {
|
|||
String _name_1 = rule.getName();
|
||||
boolean _equals_1 = Objects.equal(_name_1, "STRING");
|
||||
if (_equals_1) {
|
||||
ArrayList<TextRegion> _editPositions = it.getEditPositions();
|
||||
List<TextRegion> _editPositions = it.getEditPositions();
|
||||
int _offset = context.getOffset();
|
||||
int _plus_1 = (_offset + 1);
|
||||
int _length = proposal.length();
|
||||
|
@ -137,7 +137,7 @@ public class IdeContentProposalProvider {
|
|||
_editPositions.add(_textRegion);
|
||||
it.setKind(ContentAssistEntry.KIND_TEXT);
|
||||
} else {
|
||||
ArrayList<TextRegion> _editPositions_1 = it.getEditPositions();
|
||||
List<TextRegion> _editPositions_1 = it.getEditPositions();
|
||||
int _offset_1 = context.getOffset();
|
||||
int _length_1 = proposal.length();
|
||||
TextRegion _textRegion_1 = new TextRegion(_offset_1, _length_1);
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.contentassist;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.xtend.lib.annotations.AccessorType;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.CrossReference;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalCreator;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalPriorities;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.scoping.IScope;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* Special content assist proposal provider for cross-references.
|
||||
* @noreference
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class IdeCrossrefProposalProvider {
|
||||
private static final Logger LOG = Logger.getLogger(IdeCrossrefProposalProvider.class);
|
||||
|
||||
@Accessors(AccessorType.PROTECTED_GETTER)
|
||||
@Inject
|
||||
private IQualifiedNameConverter qualifiedNameConverter;
|
||||
|
||||
@Accessors(AccessorType.PROTECTED_GETTER)
|
||||
@Inject
|
||||
private IdeContentProposalCreator proposalCreator;
|
||||
|
||||
@Inject
|
||||
private IdeContentProposalPriorities proposalPriorities;
|
||||
|
||||
public void lookupCrossReference(final IScope scope, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor, final Predicate<IEObjectDescription> filter) {
|
||||
try {
|
||||
Iterable<IEObjectDescription> _queryScope = this.queryScope(scope, crossReference, context);
|
||||
for (final IEObjectDescription candidate : _queryScope) {
|
||||
{
|
||||
boolean _canAcceptMoreProposals = acceptor.canAcceptMoreProposals();
|
||||
boolean _not = (!_canAcceptMoreProposals);
|
||||
if (_not) {
|
||||
return;
|
||||
}
|
||||
boolean _apply = filter.apply(candidate);
|
||||
if (_apply) {
|
||||
final ContentAssistEntry entry = this.createProposal(candidate, crossReference, context);
|
||||
acceptor.accept(entry, this.proposalPriorities.getCrossRefPriority(candidate, entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof UnsupportedOperationException) {
|
||||
final UnsupportedOperationException uoe = (UnsupportedOperationException)_t;
|
||||
IdeCrossrefProposalProvider.LOG.error("Failed to create content assist proposals for cross-reference.", uoe);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Iterable<IEObjectDescription> queryScope(final IScope scope, final CrossReference crossReference, final ContentAssistContext context) {
|
||||
return scope.getAllElements();
|
||||
}
|
||||
|
||||
protected ContentAssistEntry createProposal(final IEObjectDescription candidate, final CrossReference crossRef, final ContentAssistContext context) {
|
||||
final Procedure1<ContentAssistEntry> _function = (ContentAssistEntry it) -> {
|
||||
it.setSource(candidate);
|
||||
EClass _eClass = candidate.getEClass();
|
||||
String _name = null;
|
||||
if (_eClass!=null) {
|
||||
_name=_eClass.getName();
|
||||
}
|
||||
it.setDescription(_name);
|
||||
it.setKind(ContentAssistEntry.KIND_REFERENCE);
|
||||
};
|
||||
return this.proposalCreator.createProposal(this.qualifiedNameConverter.toString(candidate.getName()), context, _function);
|
||||
}
|
||||
|
||||
@Pure
|
||||
protected IQualifiedNameConverter getQualifiedNameConverter() {
|
||||
return this.qualifiedNameConverter;
|
||||
}
|
||||
|
||||
@Pure
|
||||
protected IdeContentProposalCreator getProposalCreator() {
|
||||
return this.proposalCreator;
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.AccessorType;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNode;
|
||||
import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNodeReference;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.util.Wrapper;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class DefaultHierarchyNode implements IHierarchyNode {
|
||||
@Accessors
|
||||
private IHierarchyNode parent;
|
||||
|
||||
@Accessors(AccessorType.PUBLIC_SETTER)
|
||||
private boolean mayHaveChildren;
|
||||
|
||||
@Accessors
|
||||
private IEObjectDescription element;
|
||||
|
||||
@Accessors(AccessorType.PUBLIC_GETTER)
|
||||
private final List<IHierarchyNodeReference> references = CollectionLiterals.<IHierarchyNodeReference>newArrayList();
|
||||
|
||||
private Wrapper<Boolean> recursive;
|
||||
|
||||
@Override
|
||||
public Object getNavigationElement() {
|
||||
Object _elvis = null;
|
||||
IHierarchyNodeReference _head = IterableExtensions.<IHierarchyNodeReference>head(this.references);
|
||||
if (_head != null) {
|
||||
_elvis = _head;
|
||||
} else {
|
||||
_elvis = this.element;
|
||||
}
|
||||
return _elvis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecursive() {
|
||||
if ((this.recursive == null)) {
|
||||
this.recursive = Wrapper.<Boolean>wrap(Boolean.valueOf(this.internalIsRecursive()));
|
||||
}
|
||||
return (this.recursive.get()).booleanValue();
|
||||
}
|
||||
|
||||
protected boolean internalIsRecursive() {
|
||||
IHierarchyNode node = this.parent;
|
||||
while ((node != null)) {
|
||||
{
|
||||
URI _eObjectURI = node.getElement().getEObjectURI();
|
||||
URI _eObjectURI_1 = this.element.getEObjectURI();
|
||||
boolean _equals = Objects.equal(_eObjectURI, _eObjectURI_1);
|
||||
if (_equals) {
|
||||
return true;
|
||||
}
|
||||
node = node.getParent();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayHaveChildren() {
|
||||
return this.mayHaveChildren;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IHierarchyNode getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public void setParent(final IHierarchyNode parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void setMayHaveChildren(final boolean mayHaveChildren) {
|
||||
this.mayHaveChildren = mayHaveChildren;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IEObjectDescription getElement() {
|
||||
return this.element;
|
||||
}
|
||||
|
||||
public void setElement(final IEObjectDescription element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public List<IHierarchyNodeReference> getReferences() {
|
||||
return this.references;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy;
|
||||
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtend.lib.annotations.Delegate;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNodeReference;
|
||||
import org.eclipse.xtext.util.ITextRegion;
|
||||
import org.eclipse.xtext.util.ITextRegionWithLineInformation;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
@Accessors
|
||||
@FinalFieldsConstructor
|
||||
@SuppressWarnings("all")
|
||||
public class DefaultHierarchyNodeReference implements IHierarchyNodeReference {
|
||||
private final String text;
|
||||
|
||||
@Delegate
|
||||
private final ITextRegionWithLineInformation textRegion;
|
||||
|
||||
private final Object navigationElement;
|
||||
|
||||
public DefaultHierarchyNodeReference(final String text, final ITextRegionWithLineInformation textRegion, final Object navigationElement) {
|
||||
super();
|
||||
this.text = text;
|
||||
this.textRegion = textRegion;
|
||||
this.navigationElement = navigationElement;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public ITextRegionWithLineInformation getTextRegion() {
|
||||
return this.textRegion;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public Object getNavigationElement() {
|
||||
return this.navigationElement;
|
||||
}
|
||||
|
||||
public boolean contains(final ITextRegion other) {
|
||||
return this.textRegion.contains(other);
|
||||
}
|
||||
|
||||
public boolean contains(final int offset) {
|
||||
return this.textRegion.contains(offset);
|
||||
}
|
||||
|
||||
public int getEndLineNumber() {
|
||||
return this.textRegion.getEndLineNumber();
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return this.textRegion.getLength();
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return this.textRegion.getLineNumber();
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return this.textRegion.getOffset();
|
||||
}
|
||||
|
||||
public ITextRegion merge(final ITextRegion region) {
|
||||
return this.textRegion.merge(region);
|
||||
}
|
||||
|
||||
public ITextRegionWithLineInformation merge(final ITextRegionWithLineInformation other) {
|
||||
return this.textRegion.merge(other);
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.editor.hierarchy;
|
||||
|
||||
import java.util.List;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNode;
|
||||
import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyRoot;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
* @since 2.10
|
||||
*/
|
||||
@Accessors
|
||||
@SuppressWarnings("all")
|
||||
public class DefaultHierarchyRoot implements IHierarchyRoot {
|
||||
private final List<IHierarchyNode> roots = CollectionLiterals.<IHierarchyNode>newArrayList();
|
||||
|
||||
@Pure
|
||||
public List<IHierarchyNode> getRoots() {
|
||||
return this.roots;
|
||||
}
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2018 TypeFox and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.server.symbol;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.SymbolKind;
|
||||
import org.eclipse.xtext.ide.server.DocumentExtensions;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameProvider;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
|
||||
/**
|
||||
* Maps an EObject to the corresponding {@link DocumentSymbol document symbol}.
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
@SuppressWarnings("all")
|
||||
public class DocumentSymbolMapper {
|
||||
/**
|
||||
* Provides {@link DocumentSymbol#detail detail} for a {@link DocumentSymbol document symbol}.
|
||||
* <p>
|
||||
* Always returns with an empty string by default.
|
||||
*
|
||||
* @see DocumentSymbol#detail
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolDetailsProvider {
|
||||
public String getDetails(final EObject object) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a human-readable name for the document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#name
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolNameProvider {
|
||||
@Inject
|
||||
@Extension
|
||||
private IQualifiedNameProvider _iQualifiedNameProvider;
|
||||
|
||||
public String getName(final EObject object) {
|
||||
QualifiedName _fullyQualifiedName = null;
|
||||
if (object!=null) {
|
||||
_fullyQualifiedName=this._iQualifiedNameProvider.getFullyQualifiedName(object);
|
||||
}
|
||||
return this.getName(_fullyQualifiedName);
|
||||
}
|
||||
|
||||
public String getName(final IEObjectDescription description) {
|
||||
QualifiedName _name = null;
|
||||
if (description!=null) {
|
||||
_name=description.getName();
|
||||
}
|
||||
return this.getName(_name);
|
||||
}
|
||||
|
||||
protected String getName(final QualifiedName qualifiedName) {
|
||||
String _string = null;
|
||||
if (qualifiedName!=null) {
|
||||
_string=qualifiedName.toString();
|
||||
}
|
||||
return _string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the {@link SymbolKind symbol kind} information for the document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#kind
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolKindProvider {
|
||||
public SymbolKind getSymbolKind(final EObject object) {
|
||||
EClass _eClass = null;
|
||||
if (object!=null) {
|
||||
_eClass=object.eClass();
|
||||
}
|
||||
return this.getSymbolKind(_eClass);
|
||||
}
|
||||
|
||||
public SymbolKind getSymbolKind(final IEObjectDescription description) {
|
||||
EClass _eClass = null;
|
||||
if (description!=null) {
|
||||
_eClass=description.getEClass();
|
||||
}
|
||||
return this.getSymbolKind(_eClass);
|
||||
}
|
||||
|
||||
protected SymbolKind getSymbolKind(final EClass clazz) {
|
||||
return SymbolKind.Property;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides {@link DocumentSymbol#range range} and {@link DocumentSymbol#selectionRange selection range} for a document symbol.
|
||||
*
|
||||
* @see DocumentSymbol#range
|
||||
* @see DocumentSymbol#selectionRange
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolRangeProvider {
|
||||
@Inject
|
||||
@Extension
|
||||
private DocumentExtensions _documentExtensions;
|
||||
|
||||
/**
|
||||
* The range enclosing this symbol not including leading/trailing whitespace but everything else
|
||||
* like comments.
|
||||
*/
|
||||
public Range getRange(final EObject object) {
|
||||
Location _newFullLocation = this._documentExtensions.newFullLocation(object);
|
||||
Range _range = null;
|
||||
if (_newFullLocation!=null) {
|
||||
_range=_newFullLocation.getRange();
|
||||
}
|
||||
return _range;
|
||||
}
|
||||
|
||||
/**
|
||||
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
|
||||
*/
|
||||
public Range getSelectionRange(final EObject object) {
|
||||
Location _newLocation = this._documentExtensions.newLocation(object);
|
||||
Range _range = null;
|
||||
if (_newLocation!=null) {
|
||||
_range=_newLocation.getRange();
|
||||
}
|
||||
return _range;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a document symbol can be marked as {@link DocumentSymbol#deprecated deprecated}.
|
||||
*
|
||||
* @see DocumentSymbol#deprecated
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public static class DocumentSymbolDeprecationInfoProvider {
|
||||
public boolean isDeprecated(final EObject object) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDeprecated(final IEObjectDescription description) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolNameProvider nameProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolKindProvider kindProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolRangeProvider rangeProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolDetailsProvider detailsProvider;
|
||||
|
||||
@Inject
|
||||
private DocumentSymbolMapper.DocumentSymbolDeprecationInfoProvider deprecationInfoProvider;
|
||||
|
||||
/**
|
||||
* Converts the {@code EObject} argument into a {@link DocumentSymbol document symbol} without
|
||||
* the {@link DocumentSymbol#children children} information filled in.
|
||||
*/
|
||||
public DocumentSymbol toDocumentSymbol(final EObject object) {
|
||||
DocumentSymbol _documentSymbol = new DocumentSymbol();
|
||||
final Procedure1<DocumentSymbol> _function = (DocumentSymbol it) -> {
|
||||
final String objectName = this.nameProvider.getName(object);
|
||||
if ((objectName != null)) {
|
||||
it.setName(objectName);
|
||||
}
|
||||
final SymbolKind objectKind = this.kindProvider.getSymbolKind(object);
|
||||
if ((objectKind != null)) {
|
||||
it.setKind(objectKind);
|
||||
}
|
||||
final Range objectRange = this.rangeProvider.getRange(object);
|
||||
if ((objectRange != null)) {
|
||||
it.setRange(objectRange);
|
||||
}
|
||||
final Range objectSelectionRange = this.rangeProvider.getSelectionRange(object);
|
||||
if ((objectSelectionRange != null)) {
|
||||
it.setSelectionRange(objectSelectionRange);
|
||||
}
|
||||
it.setDetail(this.detailsProvider.getDetails(object));
|
||||
it.setDeprecated(Boolean.valueOf(this.deprecationInfoProvider.isDeprecated(object)));
|
||||
it.setChildren(CollectionLiterals.<DocumentSymbol>newArrayList());
|
||||
};
|
||||
return ObjectExtensions.<DocumentSymbol>operator_doubleArrow(_documentSymbol, _function);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue