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

The following examples show how to use org.eclipse.xtext.naming.QualifiedName#getLastSegment() . 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: ClassifierReference.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
Source File: ComposedMemberScope.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
Source File: ImportRewriter.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
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
Source File: SpecTestInfo.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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
Source File: PolyFilledProvision.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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
Source File: InvalidStaticWriteAccessDescription.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: EObjectDescriptionBasedStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected QualifiedName getOwnerClassName(QualifiedName nestedClassName) {
	String lastSegment = nestedClassName.getLastSegment();
	int trimIndex = lastSegment.lastIndexOf('$');
	if(trimIndex == -1)
		return nestedClassName.skipLast(1);
	else
		return nestedClassName.skipLast(1).append(lastSegment.substring(0, trimIndex));
}
 
Example 8
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected StyledString getStyledDisplayString(IEObjectDescription description) {
	if (EcorePackage.Literals.EPACKAGE == description.getEClass()) {
		if ("true".equals(description.getUserData("nsURI"))) {
			String name = description.getUserData("name");
			if (name == null) {
				return new StyledString(description.getName().toString());
			}
			String string = name + " - " + description.getName();
			return new StyledString(string);
		}
	} else if(XtextPackage.Literals.GRAMMAR == description.getEClass()){
		QualifiedName qualifiedName = description.getQualifiedName();
		if(qualifiedName.getSegmentCount() >1) {
			return new StyledString(qualifiedName.getLastSegment() + " - " + qualifiedName.toString());
		}
		return new StyledString(qualifiedName.toString());
	} else if (XtextPackage.Literals.ABSTRACT_RULE.isSuperTypeOf(description.getEClass())) {
		EObject object = description.getEObjectOrProxy();
		if (!object.eIsProxy()) {
			AbstractRule rule = (AbstractRule) object;
			Grammar grammar = GrammarUtil.getGrammar(rule);
			if (description instanceof EnclosingGrammarAwareDescription) {
				if (grammar == ((EnclosingGrammarAwareDescription) description).getGrammar()) {
					return getStyledDisplayString(rule, null, rule.getName());
				}
			}
			return getStyledDisplayString(rule,
					grammar.getName() + "." + rule.getName(),
					description.getName().toString().replace(".", "::"));	
		}
		
	}
	return super.getStyledDisplayString(description);
}
 
Example 9
Source File: AbstractContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String getDisplayString(EObject element, String qualifiedNameAsString, String shortName) {
	if (qualifiedNameAsString == null)
		qualifiedNameAsString = shortName;
	if (qualifiedNameAsString == null) {
		if (element != null)
			qualifiedNameAsString = labelProvider.getText(element);
		else
			return null;
	}
	QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(qualifiedNameAsString);		
	if(qualifiedName.getSegmentCount() >1) {
		return qualifiedName.getLastSegment() + " - " + qualifiedNameAsString;
	}
	return qualifiedNameAsString;
}
 
Example 10
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** This functions checks of the given name is disallowed.
 * The {@link SARLFeatureNameValidator} provides the basic conditions.
 * It is not detecting the implicit lambda's parameter names. This specific
 * function does.
 *
 * @param name the name to test.
 * @return {@code true} if the name is really disallowed.
 */
private boolean isReallyDisallowedName(QualifiedName name) {
	if (this.featureNames_.isDisallowedName(name)) {
		return true;
	}
	final String base = name.getLastSegment();
	if (Utils.isHiddenMember(base) && Utils.isImplicitLambdaParameterName(base)) {
		return true;
	}
	return false;
}
 
Example 11
Source File: PyGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected void generateImportStatement(QualifiedName qualifiedName, ExtraLanguageAppendable appendable,
		IExtraLanguageGeneratorContext context) {
	final String typeName = qualifiedName.getLastSegment();
	final QualifiedName packageName = qualifiedName.skipLast(1);
	appendable.append("from "); //$NON-NLS-1$
	appendable.append(packageName.toString());
	appendable.append(" import "); //$NON-NLS-1$
	appendable.append(typeName);
	appendable.newLine();
}
 
Example 12
Source File: SuppressWarningsAddModification.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Create the quick fix if needed.
 *
 * @param provider the quick fix provider.
 * @param issue the issue to fix.
 * @param acceptor the quick fix acceptor.
 */
public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor) {
	final IFile file = provider.getProjectUtil().findFileStorage(issue.getUriToProblem(), false);
	final ResourceSet resourceSet = provider.getResourceSetProvider().get(file.getProject());
	final EObject failingObject;
	try {
		failingObject = resourceSet.getEObject(issue.getUriToProblem(), true);
	} catch (Exception exception) {
		// Something is going really wrong. Must of the time the cause is a major syntax error.
		return;
	}
	XtendAnnotationTarget eObject = EcoreUtil2.getContainerOfType(failingObject, XtendAnnotationTarget.class);
	boolean first = true;
	int relevance = IProposalRelevance.ADD_SUPPRESSWARNINGS;
	while (eObject != null) {
		final URI uri = EcoreUtil2.getNormalizedURI(eObject);
		final SuppressWarningsAddModification modification = new SuppressWarningsAddModification(uri, issue.getCode());
		modification.setIssue(issue);
		modification.setTools(provider);
		final String elementName;
		final QualifiedName name = provider.getQualifiedNameProvider().getFullyQualifiedName(eObject);
		if (name != null) {
			elementName = name.getLastSegment();
		} else if (first) {
			elementName = Messages.AddSuppressWarnings_0;
		} else {
			elementName = null;
		}
		if (elementName != null) {
			acceptor.accept(issue,
					MessageFormat.format(Messages.AddSuppressWarnings_1, elementName),
					MessageFormat.format(Messages.AddSuppressWarnings_2, elementName),
					JavaPluginImages.IMG_OBJS_ANNOTATION_ALT,
					modification,
					relevance);
			--relevance;
		}
		first = false;
		eObject = EcoreUtil2.getContainerOfType(eObject.eContainer(), XtendAnnotationTarget.class);
	}
}
 
Example 13
Source File: SARLFeatureNameValidator.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isDisallowedName(QualifiedName name) {
	final String id = name.getLastSegment();
	return super.isDisallowedName(name) || (Utils.isHiddenMember(id) && !Utils.isImplicitLambdaParameterName(id));
}