Java Code Examples for org.eclipse.xtext.naming.QualifiedName.getLastSegment()

The following are Jave code examples for showing how to use getLastSegment() of the org.eclipse.xtext.naming.QualifiedName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: n4js   File: ClassifierReference.java   Source Code and License Vote up 7 votes
/**
 * Creates a resolved classifier reference. This means a classifier with a valid uri of its declaration.
 *
 * @param qualifiedName
 *            QualifiedName of the classifier
 * @param uri
 *            Platform uri of the classifier declaration
 */
public ClassifierReference(QualifiedName qualifiedName, URI uri) {
	this.classifierName = qualifiedName.getLastSegment();
	List<String> frontSegments = qualifiedName.getSegments();
	if (frontSegments.size() > 0) {
		StringJoiner joiner = new StringJoiner(N4JSQualifiedNameConverter.DELIMITER);
		for (String segment : frontSegments.subList(0, frontSegments.size() - 1)) {
			joiner.add(segment);
		}
		this.classifierModuleSpecifier = joiner.toString();
	} else {
		this.classifierModuleSpecifier = "";
	}
	this.uri = uri;

}
 
Example 2
Project: n4js   File: ComposedMemberScope.java   Source Code and License Vote up 6 votes
/**
 * Returns description for given element, name is assumed to consist of a single segment containing the simple name
 * of the member. If no subScope contains a member with given name, null is returned. In other error cases (no or
 * wrong access, mixed types etc.), {@link IEObjectDescriptionWithError}, and in particular
 * {@link UnionMemberDescriptionWithError}, will be returned.
 */
@Override
protected IEObjectDescription getSingleLocalElementByName(QualifiedName qualifiedName) {
	String name = qualifiedName.getLastSegment();
	TMember member = getOrCreateComposedMember(name);
	if (member == null) { // no such member, no need for "merging" descriptions, there won't be any
		return null;
	}

	if (isErrorPlaceholder(member)) {
		return createComposedMemberDescriptionWithErrors(EObjectDescription.create(member.getName(), member));
	}

	IEObjectDescription description = getCheckedDescription(name, member);

	return description;
}
 
Example 3
Project: n4js   File: ImportRewriter.java   Source Code and License Vote up 5 votes
private AliasLocation addNewImportDeclaration(QualifiedName moduleName, QualifiedName qualifiedName,
		String optionalAlias,
		int insertionOffset, MultiTextEdit result) {

	final String spacer = lazySpacer.get();
	String syntacticModuleName = syntacticModuleName(moduleName);

	AliasLocation aliasLocation = null;
	String importSpec = (insertionOffset != 0 ? lineDelimiter : "") + "import ";

	if (!N4JSLanguageUtils.isDefaultExport(qualifiedName)) { // not an 'default' export
		importSpec = importSpec + "{" + spacer + qualifiedName.getLastSegment();
		if (optionalAlias != null) {
			importSpec = importSpec + " as ";
			aliasLocation = new AliasLocation(insertionOffset, importSpec.length(), optionalAlias);
			importSpec = importSpec + optionalAlias;
		}
		importSpec = importSpec + spacer + "}";
	} else { // import default exported element
		if (optionalAlias == null) {
			importSpec = importSpec + N4JSLanguageUtils.lastSegmentOrDefaultHost(qualifiedName);
		} else {
			aliasLocation = new AliasLocation(insertionOffset, importSpec.length(), optionalAlias);
			importSpec = importSpec + optionalAlias;
		}
	}

	result.addChild(new InsertEdit(insertionOffset, importSpec + " from "
			+ syntacticModuleName + ";"
			+ (insertionOffset != 0 ? "" : lineDelimiter)));

	return aliasLocation;
}
 
Example 4
Project: n4js   File: SpecTestInfo.java   Source Code and License Vote up 5 votes
/**
 * Matches names following the test name convention.
 *
 * @return method, title, and case.
 */
@VisibleForTesting
static String[] parseName(QualifiedName methodName) {
	Matcher matcher = TEST_NAME_PATTERN.matcher(methodName.getLastSegment());
	if (!matcher.matches()) {
		throw new IllegalArgumentException(
				"Test name does not match naming convention: " + methodName.getLastSegment());
	}
	return new String[] {
			matcher.group(1),
			matcher.group(2),
			matcher.group(3)
	};
}
 
Example 5
Project: n4js   File: PolyFilledProvision.java   Source Code and License Vote up 5 votes
/**
 * @param qualifiedName
 *            with {@code #POLY}-marker to be converted to a String without the polyfill-marker.
 * @return string representation without polyfill marker
 */
public static String withoutPolyfillAsString(QualifiedName qualifiedName) {
	// Assumption: 2nd-last segment is "!POLY"
	String last = qualifiedName.getLastSegment();
	String poly = qualifiedName.skipLast(1).getLastSegment();
	assert(N4TSQualifiedNameProvider.POLYFILL_SEGMENT.equals(poly));
	QualifiedName ret = qualifiedName.skipLast(2).append(last);
	return ret.toString();
}
 
Example 6
Project: n4js   File: InvalidStaticWriteAccessDescription.java   Source Code and License Vote up 5 votes
@Override
public String getMessage() {
	QualifiedName qualifiedName = getName();
	String memberName = qualifiedName.getLastSegment();
	return aliasOfMemberDefiningType == null
			? IssueCodes.getMessageForVIS_ILLEGAL_STATIC_MEMBER_WRITE_ACCESS(memberDefTypeName, memberName)
			: IssueCodes.getMessageForVIS_ILLEGAL_STATIC_MEMBER_WRITE_ACCESS_WITH_ALIAS(memberDefTypeName,
					memberName,
					aliasOfMemberDefiningType);
}