Java Code Examples for org.eclipse.xtext.resource.IEObjectDescription#getQualifiedName()

The following examples show how to use org.eclipse.xtext.resource.IEObjectDescription#getQualifiedName() . 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: ImportsAwareReferenceProposalCreator.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** In case of main module, adjust the qualified name, e.g. index.Element -> react.Element */
private QualifiedName getCandidateName(IEObjectDescription candidate, String tmodule) {
	QualifiedName candidateName;
	IN4JSProject project = n4jsCore.findProject(candidate.getEObjectURI()).orNull();
	if (project != null && tmodule != null && tmodule.equals(project.getMainModule())) {
		N4JSProjectName projectName = project.getProjectName();
		N4JSProjectName definesPackage = project.getDefinesPackageName();
		if (definesPackage != null) {
			projectName = definesPackage;
		}
		String lastSegmentOfQFN = candidate.getQualifiedName().getLastSegment().toString();
		candidateName = QualifiedName.create(projectName.getRawName(), lastSegmentOfQFN);
	} else {
		candidateName = candidate.getQualifiedName();
	}
	return candidateName;
}
 
Example 2
Source File: EObjectDescriptionBasedStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public String getJavaStubSource(IEObjectDescription description, IResourceDescription resourceDescription) {
	if(isNestedType(description) || !isJvmDeclaredType(description)) {
		return null;
	}
	Multimap<QualifiedName, IEObjectDescription> owner2nested = LinkedHashMultimap.create();
	for(IEObjectDescription other: resourceDescription.getExportedObjects()) {
		if(isJvmDeclaredType(other) && isNestedType(other))
			owner2nested.put(getOwnerClassName(other.getQualifiedName()), other);
	}
	StringBuilder classSignatureBuilder = new StringBuilder();
	QualifiedName qualifiedName = description.getQualifiedName();
	if (qualifiedName.getSegments().size() > 1) {
		String string = qualifiedName.toString();
		classSignatureBuilder.append("package " + string.substring(0, string.lastIndexOf('.')) + ";");
	}
	appendType(description, owner2nested, classSignatureBuilder);
	return classSignatureBuilder.toString();
}
 
Example 3
Source File: IteratorJob.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
	long startTime = System.currentTimeMillis();
	while (iterator.hasNext()) {
		IEObjectDescription next = iterator.next();
		if (next.getQualifiedName() != null && next.getEObjectURI() != null && next.getEClass() != null) {
			matches.add(next);
			long endTime = System.currentTimeMillis();
			if (matches.size() == dialog.getHeightInChars() || endTime - startTime > TIME_THRESHOLD) {
				if (monitor.isCanceled()) {
					return Status.CANCEL_STATUS;
				}
				dialog.updateMatches(sortedCopy(matches), false);
				startTime = System.currentTimeMillis();
			}
		}
	}
	dialog.updateMatches(sortedCopy(matches), true);
	return Status.OK_STATUS;
}
 
Example 4
Source File: NewFeatureNameUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public String getDefaultName(XExpression expression) {
	String baseName = getBaseName(expression);
	final List<String> candidates = newArrayList();
	Set<String> excludedNames = new HashSet<String>(allKeywords); 
	for(IEObjectDescription featureDescription: featureCallScope.getAllElements()) {
		QualifiedName featureQName = featureDescription.getQualifiedName();
		if(featureQName.getSegmentCount() == 1)
			excludedNames.add(featureQName.getLastSegment());
	}
	jdtVariableCompletions.getVariableProposals(baseName, expression, VariableType.LOCAL_VAR, excludedNames, new CompletionDataAcceptor() {
		@Override
		public void accept(String replaceText, StyledString label, Image img) {
			candidates.add(replaceText);
		}
	});
	return candidates.isEmpty() ? "dingenskirchen" : candidates.get(0);
}
 
Example 5
Source File: EObjectDescriptionProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public SimpleNameDescription(QualifiedName qName, EObject resolvedObject, IEObjectDescription source) {
	this.simpleName = qName;
	this.object = resolvedObject;
	this.qualifiedName = source.getQualifiedName();
	Preconditions.checkArgument(!this.object.eIsProxy());
	Preconditions.checkNotNull(this.simpleName);
	Preconditions.checkNotNull(this.qualifiedName);
	Map<String, String> userData = null;
	for (final String key : source.getUserDataKeys()) {
		if (userData == null) {
			userData = Maps.newHashMapWithExpectedSize(2);
		}
		userData.put(key, source.getUserData(key));
	}
	this.userData = userData;
}
 
Example 6
Source File: EObjectDescriptionProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected QualifiedName computeSimpleName(Multimap<EObject, IEObjectDescription> descs, IEObjectDescription desc) {
	QualifiedName name = desc.getQualifiedName();
	int segmentCount = name.getSegmentCount();
	if (segmentCount < 2) {
		return name;
	}
	EObject container = desc.getEObjectOrProxy().eContainer();
	while (container != null) {
		Collection<IEObjectDescription> candidates = descs.get(container);
		for (IEObjectDescription cand : candidates) {
			QualifiedName candName = cand.getQualifiedName();
			int candCount = candName.getSegmentCount();
			if (candCount < segmentCount && name.startsWith(candName)) {
				return name.skipFirst(candCount);
			}
		}
		container = container.eContainer();
	}
	return name;
}
 
Example 7
Source File: ReferenceUpdater.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean containsReferenceText(Delta delta, QualifiedName exp) {
	DESC: for (IEObjectDescription desc : delta.getDescriptions()) {
		QualifiedName cand = desc.getQualifiedName();
		if (cand.getSegmentCount() >= exp.getSegmentCount()) {
			for (int i = 1; i <= exp.getSegmentCount(); i++) {
				String expSeg = exp.getSegment(exp.getSegmentCount() - i);
				String candSeg = cand.getSegment(cand.getSegmentCount() - i);
				if (!expSeg.equals(candSeg)) {
					continue DESC;
				}
			}
		}
		return true;
	}
	return false;
}
 
Example 8
Source File: N4JSCandidateFilter.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean apply(IEObjectDescription candidate) {
	QualifiedName qualifiedName = candidate.getQualifiedName();
	final IEObjectDescription eObjectDescription = candidate;
	// Don't propose any erroneous descriptions.
	return !IEObjectDescriptionWithError.isErrorDescription(eObjectDescription)
			&& !N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT.equals(qualifiedName.getFirstSegment())
			&& !N4TSQualifiedNameProvider.isModulePolyfill(qualifiedName)
			&& !N4TSQualifiedNameProvider.isPolyfill(qualifiedName);
}
 
Example 9
Source File: N4JSIdeContentProposalProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean apply(IEObjectDescription candidate) {
	QualifiedName qualifiedName = candidate.getQualifiedName();
	final IEObjectDescription eObjectDescription = candidate;
	// Don't propose any erroneous descriptions.
	boolean valid = true;
	valid &= !(IEObjectDescriptionWithError.isErrorDescription(eObjectDescription));
	valid &= !N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT.equals(qualifiedName.getFirstSegment());
	valid &= !N4TSQualifiedNameProvider.isModulePolyfill(qualifiedName);
	valid &= !N4TSQualifiedNameProvider.isPolyfill(qualifiedName);
	return valid;
}
 
Example 10
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 11
Source File: PortableURIs.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected PortableURIs.PortableFragmentDescription createPortableFragmentDescription(IEObjectDescription desc,
		EObject target) {
	EObject possibleContainer = EcoreUtil.resolve(desc.getEObjectOrProxy(), target);
	String fragmentToTarget = getFragment(target, possibleContainer);
	return new PortableURIs.PortableFragmentDescription(desc.getEClass(), desc.getQualifiedName(),
			fragmentToTarget);
}
 
Example 12
Source File: SerializableResourceDescription.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private static SerializableEObjectDescription createCopy(IEObjectDescription desc) {
	if (desc instanceof SerializableEObjectDescriptionProvider)
		return ((SerializableEObjectDescriptionProvider) desc).toSerializableEObjectDescription();
	SerializableEObjectDescription result = new SerializableEObjectDescription();
	result.setEClass(desc.getEClass());
	result.setEObjectURI(desc.getEObjectURI());
	result.qualifiedName = desc.getQualifiedName();
	result.userData = new HashMap<String, String>(desc.getUserDataKeys().length);
	for (String key : desc.getUserDataKeys())
		result.userData.put(key, desc.getUserData(key));
	return result;
}
 
Example 13
Source File: ImportsAwareReferenceProposalCreator.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This
 * list is further filtered here. This is a general pattern: Do not change or modify scoping for special content
 * assist requirements, instead filter here.
 *
 * @param proposalFactory
 *            usually this will be an instance of
 *            {@link AbstractJavaBasedContentProposalProvider.DefaultProposalCreator DefaultProposalCreator}.
 * @param filter
 *            by default an instance of {@link N4JSCandidateFilter} will be provided here.
 */
@SuppressWarnings("javadoc")
public void lookupCrossReference(
		EObject model,
		EReference reference,
		ContentAssistContext context,
		ICompletionProposalAcceptor acceptor,
		Predicate<IEObjectDescription> filter,
		Function<IEObjectDescription, ICompletionProposal> proposalFactory) {

	if (model != null) {
		final IScope scope = getScopeForContentAssist(model, reference);

		final Iterable<IEObjectDescription> candidates = getAllElements(scope);
		try (Measurement m = contentAssistDataCollectors.dcIterateAllElements().getMeasurement()) {
			for (IEObjectDescription candidate : candidates) {
				if (!acceptor.canAcceptMoreProposals())
					return;

				if (filter.apply(candidate)) {
					final QualifiedName qfn = candidate.getQualifiedName();
					final int qfnSegmentCount = qfn.getSegmentCount();
					final String tmodule = (qfnSegmentCount >= 2) ? qfn.getSegment(qfnSegmentCount - 2) : null;

					final ICompletionProposal proposal = getProposal(candidate,
							model,
							scope,
							reference,
							context,
							filter,
							proposalFactory);

					if (proposal instanceof ConfigurableCompletionProposal
							&& candidate.getName().getSegmentCount() > 1) {

						QualifiedName candidateName = getCandidateName(candidate, tmodule);
						ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
						castedProposal.setAdditionalData(N4JSReplacementTextApplier.KEY_QUALIFIED_NAME,
								candidateName);

						// Original qualified name is the qualified name before adjustment
						castedProposal.setAdditionalData(N4JSReplacementTextApplier.KEY_ORIGINAL_QUALIFIED_NAME,
								qfn);
					}
					acceptor.accept(proposal);
				}
			}
		}
	}
}
 
Example 14
Source File: StaticPolyfillHelper.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * For a given N4JSResource annotated with {@code @@StaticPolyfillAware} lookup the filling Module. returns
 * {@code true} if the filling Module exists in the project.
 */
public boolean hasStaticPolyfill(Resource resource) {
	// ensure right resource
	if (resource instanceof N4JSResource) {
		final N4JSResource res = (N4JSResource) resource;
		if (isContainedInStaticPolyfillAware(res.getScript())) {

			// TODO GHOLD-196 resolve inconsistency in logic between this method and #findStaticPolyfiller(Resource)
			// (i.e. if possible, delete strategy #1 and only use strategy #2; but make sure this isn't a
			// performance issue, esp. with respect to the call "srcConti.findArtifact(fqn, fileExtension)" in
			// #findStaticPolyfiller(Resource))
			boolean strategyIndex = true;

			if (strategyIndex) {
				// 1. query index
				final QualifiedName qnFilled = qualifiedNameConverter
						.toQualifiedName(res.getModule().getQualifiedName());
				final IResourceDescriptions index = indexAccess.getResourceDescriptions(res.getResourceSet());
				final java.util.Optional<QualifiedName> optQnFilling = N4TSQualifiedNameProvider
						.toStaticPolyfillFQN(qnFilled);
				if (optQnFilling.isPresent()) {
					final QualifiedName qnFilling = optQnFilling.get();

					final Iterable<IEObjectDescription> modules = index
							.getExportedObjectsByType(TypesPackage.Literals.TMODULE);
					for (IEObjectDescription module : modules) {
						if (module.getQualifiedName() == qnFilling) {
							return true;
						}
					}
				}
			} else {
				// 2. query all source-containers for file with same QN
				final SafeURI<?> fillingURI = findStaticPolyfiller(res);
				if (null != fillingURI)
					return true;
			}
		}
	}
	return false;
}
 
Example 15
Source File: DefaultDescriptionLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Object text(IEObjectDescription element) {
	return element.getQualifiedName() + " - " + element.getEClass().getName();
}
 
Example 16
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isLocalVarOrFormalParameter(IEObjectDescription desc) {
	QualifiedName name = desc.getQualifiedName();
	return !name.equals(IFeatureNames.THIS) && !name.equals(IFeatureNames.SUPER);
}