类org.eclipse.lsp4j.SymbolKind源码实例Demo

下面列出了怎么用org.eclipse.lsp4j.SymbolKind的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lsp4intellij   文件: LSPDefaultIconProvider.java
public Icon getSymbolIcon(SymbolKind kind) {

        if (kind == null) {
            return null;
        }

        switch (kind) {
            case Field:
            case EnumMember:
                return Nodes.Field;
            case Method:
                return Nodes.Method;
            case Variable:
                return Nodes.Variable;
            case Class:
                return Nodes.Class;
            case Constructor:
                return Nodes.ClassInitializer;
            case Enum:
                return Nodes.Enum;
            default:
                return Nodes.Tag;
        }
    }
 
public static SymbolKind astNodeToSymbolKind(ASTNode node) {
	if (node instanceof ClassNode) {
		ClassNode classNode = (ClassNode) node;
		if (classNode.isInterface()) {
			return SymbolKind.Interface;
		} else if (classNode.isEnum()) {
			return SymbolKind.Enum;
		}
		return SymbolKind.Class;
	} else if (node instanceof MethodNode) {
		return SymbolKind.Method;
	} else if (node instanceof Variable) {
		if (node instanceof FieldNode || node instanceof PropertyNode) {
			return SymbolKind.Field;
		}
		return SymbolKind.Variable;
	}
	return SymbolKind.Property;
}
 
源代码3 项目: lemminx   文件: XMLSymbolsProvider.java
private static SymbolKind getSymbolKind(DOMNode node) {
	if (node.isProcessingInstruction() || node.isProlog()) {
		return SymbolKind.Property;
	} else if (node.isDoctype()) {
		return SymbolKind.Struct;
	} else if (node.isDTDElementDecl()) {
		return SymbolKind.Property;
	} else if (node.isDTDEntityDecl()) {
		return SymbolKind.Namespace;
	} else if (node.isDTDAttListDecl()) {
		return SymbolKind.Key;
	} else if (node.isDTDNotationDecl()) {
		return SymbolKind.Variable;
	}
	return SymbolKind.Field;
}
 
源代码4 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedSymbol() {
	String xmlText = "<project><inside></inside></project>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 36, xmlDocument);
	currentSymbolInfo = createSymbolInformation("project", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 9, 26, xmlDocument);
	currentSymbolInfo = createSymbolInformation("inside", SymbolKind.Field, currentLocation, "project");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码5 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testTwoNestedSymbols() {
	String xmlText = "<a><b></b><c></c></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 21, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 10, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 10, 17, xmlDocument);
	currentSymbolInfo = createSymbolInformation("c", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码6 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedTwice() {
	String xmlText = "<a><b><c></c></b></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 21, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 17, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 6, 13, xmlDocument);
	currentSymbolInfo = createSymbolInformation("c", SymbolKind.Field, currentLocation, "b");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码7 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedSelfClosingTag() {
	String xmlText = "<a><b/></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 11, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 7, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码8 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedUnclosedTag() {
	String xmlText = "<a><b></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 10, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码9 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testAllTagsUnclosed() {
	String xmlText = "<a><b>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码10 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void externalDTD() {
	String xmlText = "<!ELEMENT br EMPTY>\n" + //
			"<!ATTLIST br\n" + //
			"	%all;>";
	String testURI = "test.dtd";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 19, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Property, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 34, 39, xmlDocument);
	currentSymbolInfo = createSymbolInformation("%all;", SymbolKind.Key, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码11 项目: n4js   文件: N4JSDocumentSymbolMapper.java
@Override
public DocumentSymbol toDocumentSymbol(EObject object) {
	SymbolKind symbolKind = kindCalculationHelper.getSymbolKind(object);
	if (symbolKind == null) {
		return null;
	}

	DocumentSymbol documentSymbol = super.toDocumentSymbol(object);
	documentSymbol.setKind(symbolKind);

	String symbolLabel = labelHelper.getSymbolLabel(object);
	if (symbolLabel != null) {
		documentSymbol.setName(symbolLabel);
	}
	return documentSymbol;
}
 
源代码12 项目: eclipse.jdt.ls   文件: SyntaxServerTest.java
@Test
public void testDocumentSymbol() throws Exception {
	when(preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported()).thenReturn(Boolean.TRUE);

	URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileURI.toString());
	DocumentSymbolParams params = new DocumentSymbolParams(identifier);
	List<Either<SymbolInformation, DocumentSymbol>> result = server.documentSymbol(params).join();
	assertNotNull(result);
	assertEquals(2, result.size());
	Either<SymbolInformation, DocumentSymbol> symbol = result.get(0);
	assertTrue(symbol.isRight());
	assertEquals("java", symbol.getRight().getName());
	assertEquals(SymbolKind.Package, symbol.getRight().getKind());
	symbol = result.get(1);
	assertTrue(symbol.isRight());
	assertEquals("Foo", symbol.getRight().getName());
	assertEquals(SymbolKind.Class, symbol.getRight().getKind());
	List<DocumentSymbol> children = symbol.getRight().getChildren();
	assertNotNull(children);
	assertEquals(1, children.size());
	assertEquals("main(String[])", children.get(0).getName());
	assertEquals(SymbolKind.Method, children.get(0).getKind());
}
 
源代码13 项目: eclipse.jdt.ls   文件: CallHierarchyHandlerTest.java
/**
 * @param item
 *            to assert
 * @param name
 *            the expected name
 * @param kind
 *            the expected kind
 * @param detail
 *            the expected detail
 * @param deprecated
 *            expected deprecated state
 * @param selectionStartLine
 *            the start line of the selection range
 * @return the {@code item}
 */
static CallHierarchyItem assertItem(CallHierarchyItem item, String name, SymbolKind kind, String detail, boolean deprecated, int selectionStartLine) {
	assertNotNull(item);
	assertEquals(name, item.getName());
	assertEquals(kind, item.getKind());
	assertEquals(detail, item.getDetail());
	if (deprecated) {
		assertNotNull(item.getTags());
		assertTrue(item.getTags().stream().anyMatch(tag -> tag == SymbolTag.Deprecated));
	} else {
		assertTrue(item.getTags() == null || item.getTags().isEmpty() || !item.getTags().stream().anyMatch(tag -> tag == SymbolTag.Deprecated));
	}

	assertEquals(selectionStartLine, item.getSelectionRange().getStart().getLine());
	return item;
}
 
源代码14 项目: eclipse.jdt.ls   文件: DocumentSymbolHandlerTest.java
@Test
public void testTypes() throws Exception {
	String className = "org.sample.Bar";
	List<? extends SymbolInformation> symbols = getSymbols(className);
	assertHasSymbol("Bar", "Bar.java", SymbolKind.Class, symbols);
	assertHasSymbol("main(String[])", "Bar", SymbolKind.Method, symbols);
	assertHasSymbol("MyInterface", "Bar", SymbolKind.Interface, symbols);
	assertHasSymbol("foo()", "MyInterface", SymbolKind.Method, symbols);
	assertHasSymbol("MyClass", "Bar", SymbolKind.Class, symbols);
	assertHasSymbol("bar()", "MyClass", SymbolKind.Method, symbols);
	assertHasSymbol("Foo", "Bar", SymbolKind.Enum, symbols);
	assertHasSymbol("Bar", "Foo", SymbolKind.EnumMember, symbols);
	assertHasSymbol("Zoo", "Foo", SymbolKind.EnumMember, symbols);
	assertHasSymbol("EMPTY", "Bar", SymbolKind.Constant, symbols);

}
 
源代码15 项目: xtext-core   文件: DocumentSymbolService.java
protected SymbolInformation createSymbol(EObject object) {
	String name = getSymbolName(object);
	if (name == null) {
		return null;
	}
	SymbolKind kind = getSymbolKind(object);
	if (kind == null) {
		return null;
	}
	Location location = getSymbolLocation(object);
	if (location == null) {
		return null;
	}
	SymbolInformation symbol = new SymbolInformation();
	symbol.setName(name);
	symbol.setKind(kind);
	symbol.setLocation(location);
	return symbol;
}
 
源代码16 项目: xtext-core   文件: DocumentSymbolMapper.java
/**
 * 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;
}
 
源代码17 项目: lemminx   文件: XMLDocumentSymbolsTest.java
@Test
public void externalDTD() {
	String dtd = "<!ELEMENT br EMPTY>\n" + //
			"<!ATTLIST br\n" + //
			"	%all;>";
	XMLAssert.testDocumentSymbolsFor(dtd, "test.dtd", //
			ds("br", SymbolKind.Property, r(0, 0, 0, 19), r(0, 0, 0, 19), null, //
					Arrays.asList(ds("%all;", SymbolKind.Key, r(2, 1, 2, 6), r(2, 1, 2, 6), null, Arrays.asList()))));

}
 
源代码18 项目: lemminx   文件: XMLDocumentSymbolsTest.java
@Test
public void multipleAttlistValues() {
	String dtd = 
		"<!ELEMENT target EMPTY>\r\n" +
		" \r\n" +
		"<!ATTLIST target\r\n" +
		"          tid ID #IMPLIED\r\n" +
		"\r\n" +
		"<!ATTLIST target\r\n" +
		"          bee ID #IMPLIED>\r\n" +
		"        \r\n" +
		"         \r\n" +
		"<!ATTLIST extension-point\r\n" +
		"          ep CDATA #IMPLIED\r\n" +
		"          ep2 CDATA #IMPLIED>\r\n";

	XMLAssert.testDocumentSymbolsFor(dtd, "test.dtd", 
				ds("target", SymbolKind.Property, r(0, 0, 0, 23), r(0, 0, 0, 23), null,
								Arrays.asList(
									ds("tid", SymbolKind.Key, r(3, 10, 3, 13), r(3, 10, 3, 13), null, Arrays.asList()),
									ds("bee", SymbolKind.Key, r(6, 10, 6, 13), r(6, 10, 6, 13), null, Arrays.asList())
								)
				),
				ds("extension-point", SymbolKind.Key, r(9, 0, 11, 29), r(9, 0, 11, 29), null, 
								Arrays.asList(
									ds("ep", SymbolKind.Key, r(10, 10, 10, 12), r(10, 10, 10, 12), null, Arrays.asList()),
									ds("ep2", SymbolKind.Key, r(11, 10, 11, 13), r(11, 10, 11, 13), null, Arrays.asList())
								)));

}
 
源代码19 项目: lemminx   文件: XMLDocumentSymbolsTest.java
@Test
public void internalDTD() {
	String xml = "<?xml version = \"1.0\"?>\r\n" + //
			"<!DOCTYPE Folks [\r\n" + //
			"	<!ELEMENT Folks (Person*)>\r\n" + //
			"	<!ELEMENT Person (Name,Email?)>\r\n" + //
			"	<!ATTLIST Person Pin ID #REQUIRED>\r\n" + //
			"	<!ATTLIST Person Friend IDREF #IMPLIED>\r\n" + //
			"	<!ATTLIST Person Likes IDREFS #IMPLIED>\r\n" + //
			"	<!ELEMENT Name (#PCDATA)>\r\n" + //
			"	<!ELEMENT Email (#PCDATA)>\r\n" + //
			"	]>\r\n" + //
			"<Folks>\r\n" + //
			"	\r\n" + //
			"</Folks>";
	XMLAssert.testDocumentSymbolsFor(xml, "test.xml", //
			ds("xml", SymbolKind.Property, r(0, 0, 0, 23), r(0, 0, 0, 23), null, //
					Collections.emptyList()), //
			ds("DOCTYPE:Folks", SymbolKind.Struct, r(1, 0, 9, 3), r(1, 0, 9, 3), null,
					Arrays.asList(
							ds("Folks", SymbolKind.Property, r(2, 1, 2, 27), r(2, 1, 2, 27), null, Collections.emptyList()), //
							ds("Person", SymbolKind.Property, r(3, 1, 3, 32), r(3, 1, 3, 32), null, //
									Arrays.asList( //
											ds("Pin", SymbolKind.Key, r(4, 18, 4, 21), r(4, 18, 4, 21), null, Collections.emptyList()), //
											ds("Friend", SymbolKind.Key, r(5, 18, 5, 24), r(5, 18, 5, 24), null, Collections.emptyList()), //
											ds("Likes", SymbolKind.Key, r(6, 18, 6, 23), r(6, 18, 6, 23), null, Collections.emptyList()))), //
							ds("Name", SymbolKind.Property, r(7, 1, 7, 26), r(7, 1, 7, 26), null, Collections.emptyList()), //
							ds("Email", SymbolKind.Property, r(8, 1, 8, 27), r(8, 1, 8, 27), null, Collections.emptyList()) //
					)), //
			ds("Folks", SymbolKind.Field, r(10, 0, 12, 8), r(10, 0, 12, 8), null, Collections.emptyList()));
}
 
源代码20 项目: lemminx   文件: XMLDocumentSymbolsTest.java
@Test
public void exceedSymbolLimit() {
	String xml = "<?xml version = \"1.0\"?>\r\n" + //
			"<!DOCTYPE Folks [\r\n" + //
			"	<!ELEMENT Folks (Person*)>\r\n" + //
			"	<!ELEMENT Person (Name,Email?)>\r\n" + //
			"	<!ATTLIST Person Pin ID #REQUIRED>\r\n" + //
			"	<!ATTLIST Person Friend IDREF #IMPLIED>\r\n" + //
			"	<!ATTLIST Person Likes IDREFS #IMPLIED>\r\n" + //
			"	<!ELEMENT Name (#PCDATA)>\r\n" + //
			"	<!ELEMENT Email (#PCDATA)>\r\n" + //
			"	]>\r\n" + //
			"<Folks>\r\n" + //
			"	\r\n" + //
			"</Folks>";
	
	DocumentSymbol symbol1 = ds("xml", SymbolKind.Property, r(0, 0, 0, 23), r(0, 0, 0, 23), null, //
			Collections.emptyList());
	DocumentSymbol symbol2 = ds("DOCTYPE:Folks", SymbolKind.Struct, r(1, 0, 9, 3), r(1, 0, 9, 3), null,
			Arrays.asList(
					ds("Folks", SymbolKind.Property, r(2, 1, 2, 27), r(2, 1, 2, 27), null, Collections.emptyList()), //
					ds("Person", SymbolKind.Property, r(3, 1, 3, 32), r(3, 1, 3, 32), null, //
							Arrays.asList( //
									ds("Pin", SymbolKind.Key, r(4, 18, 4, 21), r(4, 18, 4, 21), null, Collections.emptyList()), //
									ds("Friend", SymbolKind.Key, r(5, 18, 5, 24), r(5, 18, 5, 24), null, Collections.emptyList()), //
									ds("Likes", SymbolKind.Key, r(6, 18, 6, 23), r(6, 18, 6, 23), null, Collections.emptyList()))), //
					ds("Name", SymbolKind.Property, r(7, 1, 7, 26), r(7, 1, 7, 26), null, Collections.emptyList()), //
					ds("Email", SymbolKind.Property, r(8, 1, 8, 27), r(8, 1, 8, 27), null, Collections.emptyList())));
	DocumentSymbol symbol3 = ds("Folks", SymbolKind.Field, r(10, 0, 12, 8), r(10, 0, 12, 8), null, Collections.emptyList());

	XMLSymbolSettings settings = new XMLSymbolSettings();
	settings.setMaxItemsComputed(10);
	XMLAssert.testDocumentSymbolsFor(xml, "test.xml", settings, symbol1, symbol2, symbol3);
	
	settings.setMaxItemsComputed(15);
	XMLAssert.testDocumentSymbolsFor(xml, "test.xml", settings, symbol1, symbol2, symbol3);

	settings.setMaxItemsComputed(9);
	XMLAssert.testDocumentSymbolsFor(xml, "test.xml", settings, symbol1, symbol2);
}
 
源代码21 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testSingleSymbol() {
	String xmlText = "<project></project>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 19, xmlDocument);
	currentSymbolInfo = createSymbolInformation("project", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码22 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testSelfClosingTag() {
	String xmlText = "<a/>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 4, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码23 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testUnclosedTag() {
	String xmlText = "<a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 3, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码24 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void singleEndTag() throws BadLocationException {
	String xmlText = "</meta>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 7, xmlDocument);
	currentSymbolInfo = createSymbolInformation("meta", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);

}
 
源代码25 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void internalDTD() {
	String xmlText = "<!DOCTYPE br [\n" + //
			"  	<!ELEMENT br EMPTY>\n" + //
			"	<!ATTLIST br\n" + //
			"		%all;>\n" + //
			"]>\n" + //
			"<br />";
	String testURI = "test.xml";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 63, xmlDocument);
	currentSymbolInfo = createSymbolInformation("DOCTYPE:br", SymbolKind.Struct, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 18, 37, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Property, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 54, 59, xmlDocument);
	currentSymbolInfo = createSymbolInformation("%all;", SymbolKind.Key, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 64, 70, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码26 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void exceedSymbolLimit() {
	String xmlText = "<!DOCTYPE br [\n" + //
			"  	<!ELEMENT br EMPTY>\n" + //
			"	<!ATTLIST br\n" + //
			"		%all;>\n" + //
			"]>\n" + //
			"<br />";
	String testURI = "test.xml";
	XMLSymbolSettings settings = new XMLSymbolSettings();
	settings.setMaxItemsComputed(4);
	initializeTestObjects(xmlText, testURI, settings);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 63, xmlDocument);
	currentSymbolInfo = createSymbolInformation("DOCTYPE:br", SymbolKind.Struct, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 18, 37, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Property, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 54, 59, xmlDocument);
	currentSymbolInfo = createSymbolInformation("%all;", SymbolKind.Key, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 64, 70, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);

	settings.setMaxItemsComputed(10);
	initializeTestObjects(xmlText, testURI, settings);
	assertSymbols(expectedSymbolInfos, actualSymbolInfos);

	settings.setMaxItemsComputed(3);
	initializeTestObjects(xmlText, testURI, settings);
	assertSymbols(expectedSymbolInfos.stream().limit(3).collect(Collectors.toList()), actualSymbolInfos);
}
 
private List<Either<SymbolInformation, DocumentSymbol>> convertToSymbolInformation(NodeList routeNodes) {
	List<Either<SymbolInformation, DocumentSymbol>> res = new ArrayList<>();
	for (int i = 0; i < routeNodes.getLength(); i++) {
		Node routeNode = routeNodes.item(i);
		Location location = parserFileHelper.retrieveLocation(routeNode, textDocumentItem);
		String displayNameOfSymbol = computeDisplayNameOfSymbol(routeNode);
		res.add(Either.forLeft(new SymbolInformation(displayNameOfSymbol, SymbolKind.Field, location)));
	}
	return res;
}
 
源代码28 项目: n4js   文件: JSONDocumentSymbolKindProvider.java
@Override
public SymbolKind getSymbolKind(EObject object) {
	if (object instanceof NameValuePair) {
		JSONValue value = ((NameValuePair) object).getValue();
		if (value != null && !(value instanceof JSONStringLiteral)) {
			return getSymbolKind(value);
		}
	}
	return super.getSymbolKind(object);
}
 
源代码29 项目: n4js   文件: JSONDocumentSymbolKindProvider.java
@Override
protected SymbolKind getSymbolKind(EClass clazz) {
	if (clazz.getEPackage() == JSONPackage.eINSTANCE) {
		switch (clazz.getClassifierID()) {
		case JSONPackage.JSON_DOCUMENT: {
			return SymbolKind.File;
		}
		case JSONPackage.JSON_OBJECT: {
			return SymbolKind.Object;
		}
		case JSONPackage.JSON_ARRAY: {
			return SymbolKind.Array;
		}
		case JSONPackage.NAME_VALUE_PAIR: {
			return SymbolKind.Field;
		}
		case JSONPackage.JSON_STRING_LITERAL: {
			// The outline does not look like something super exciting with this symbol
			// kind, but its likely the best choice here
			return SymbolKind.String;
		}
		case JSONPackage.JSON_NUMERIC_LITERAL: {
			return SymbolKind.Number;
		}
		case JSONPackage.JSON_BOOLEAN_LITERAL: {
			return SymbolKind.Boolean;
		}
		case JSONPackage.JSON_NULL_LITERAL: {
			return SymbolKind.Null;
		}
		}
	}
	throw new UnsupportedOperationException("Not supported for " + clazz.getName());
}
 
源代码30 项目: netbeans   文件: TextDocumentServiceImpl.java
private static SymbolKind elementKind2SymbolKind(ElementKind kind) {
    switch (kind) {
        case PACKAGE:
            return SymbolKind.Package;
        case ENUM:
            return SymbolKind.Enum;
        case CLASS:
            return SymbolKind.Class;
        case ANNOTATION_TYPE:
            return SymbolKind.Interface;
        case INTERFACE:
            return SymbolKind.Interface;
        case ENUM_CONSTANT:
            return SymbolKind.EnumMember;
        case FIELD:
            return SymbolKind.Field; //TODO: constant
        case PARAMETER:
            return SymbolKind.Variable;
        case LOCAL_VARIABLE:
            return SymbolKind.Variable;
        case EXCEPTION_PARAMETER:
            return SymbolKind.Variable;
        case METHOD:
            return SymbolKind.Method;
        case CONSTRUCTOR:
            return SymbolKind.Constructor;
        case TYPE_PARAMETER:
            return SymbolKind.TypeParameter;
        case RESOURCE_VARIABLE:
            return SymbolKind.Variable;
        case MODULE:
            return SymbolKind.Module;
        case STATIC_INIT:
        case INSTANCE_INIT:
        case OTHER:
        default:
            return SymbolKind.File; //XXX: what here?
    }
}
 
 类所在包
 同包方法