Java Code Examples for org.eclipse.lsp4j.Location#getUri()

The following examples show how to use org.eclipse.lsp4j.Location#getUri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallHierarchyHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private CallHierarchyItem toCallHierarchyItem(IMember member) throws JavaModelException {
	Location fullLocation = getLocation(member, LocationType.FULL_RANGE);
	Range range = fullLocation.getRange();
	String uri = fullLocation.getUri();
	CallHierarchyItem item = new CallHierarchyItem();
	item.setName(JDTUtils.getName(member));
	item.setKind(DocumentSymbolHandler.mapKind(member));
	item.setRange(range);
	item.setSelectionRange(getLocation(member, LocationType.NAME_RANGE).getRange());
	item.setUri(uri);
	IType declaringType = member.getDeclaringType();
	item.setDetail(declaringType == null ? null : declaringType.getFullyQualifiedName());
	if (JDTUtils.isDeprecated(member)) {
		item.setTags(Arrays.asList(SymbolTag.Deprecated));
	}

	return item;
}
 
Example 2
Source File: StringLSP4J.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return string for given element */
public String toString(Location location) {
	if (location == null) {
		return "";
	}
	String uri = location.getUri().startsWith(N4Scheme.SCHEME)
			? location.getUri()
			: relativize(location.getUri());

	String str = Strings.join(", ",
			uri,
			toString(location.getRange()));

	return "(" + str + ")";
}
 
Example 3
Source File: ClassFileUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
	try {
		if (match.getType().isBinary()) {
			Location location = JDTUtils.toLocation(match.getType().getClassFile());
			if (location != null) {
				uri = location.getUri();
			}
		}  else {
			uri = match.getType().getResource().getLocationURI().toString();
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 4
Source File: JavaElementLinks.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates an {@link URI} with the given scheme based on the given element. The
 * additional arguments specify a member referenced from the given element.
 *
 * @param scheme
 *            a scheme
 * @param element
 *            the declaring element
 * @param refTypeName
 *            a (possibly qualified) type or package name, can be
 *            <code>null</code>
 * @param refMemberName
 *            a member name, can be <code>null</code>
 * @param refParameterTypes
 *            a (possibly empty) array of (possibly qualified) parameter type
 *            names, can be <code>null</code>
 * @return an {@link URI}, encoded as {@link URI#toASCIIString() ASCII} string,
 *         ready to be used as <code>href</code> attribute in an
 *         <code>&lt;a&gt;</code> tag
 * @throws URISyntaxException
 *             if the arguments were invalid
 */
public static String createURI(String scheme, IJavaElement element, String refTypeName, String refMemberName, String[] refParameterTypes, int startPosition) throws URISyntaxException {
	/*
	 * We use an opaque URI, not ssp and fragments (to work around Safari bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=212527 (wrongly encodes #)).
	 */

	StringBuffer ssp = new StringBuffer(60);
	ssp.append(LINK_SEPARATOR); // make sure first character is not a / (would be hierarchical URI)

	// replace '[' manually, since URI confuses it for an IPv6 address as per RFC 2732:
	ssp.append(element.getHandleIdentifier().toString().replace('[', LINK_BRACKET_REPLACEMENT)); // segments[1]

	if (refTypeName != null) {
		ssp.append(LINK_SEPARATOR);
		ssp.append(refTypeName); // segments[2]

		if (refMemberName != null) {
			ssp.append(LINK_SEPARATOR);
			ssp.append(refMemberName); // segments[3]

			if (refParameterTypes != null) {
				ssp.append(LINK_SEPARATOR);
				for (int i = 0; i < refParameterTypes.length; i++) {
					ssp.append(refParameterTypes[i]); // segments[4|5|..]
					if (i != refParameterTypes.length - 1) {
						ssp.append(LINK_SEPARATOR);
					}
				}
			}
		}
	}

	URI javadocURI = new URI("eclipse-javadoc", ssp.toString(), null);

	IJavaElement linkTarget = parseURI(javadocURI);
	if (linkTarget == null) {
		return "";
	}

	try {
		Location locationToElement = JDTUtils.toLocation(linkTarget);
		if (locationToElement != null) {
			return locationToElement.getUri() + "#" + (locationToElement.getRange().getStart().getLine() + 1);
		}
	} catch (JavaModelException e) {

	}

	return "";
}
 
Example 5
Source File: FindLinksHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public LinkLocation(String displayName, String kind, Location location) {
	super(location.getUri(), location.getRange());
	this.displayName = displayName;
	this.kind = kind;
}