use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class XbaseHoverDocumentationProvider method getResolvedDeclarator.
protected JvmDeclaredType getResolvedDeclarator(String name) {
JvmDeclaredType jvmDeclaredType = null;
if (Strings.isEmpty(name) || name.trim().length() == 0) {
jvmDeclaredType = getDeclaringType(context);
} else {
HoverReference reference = new HoverReference(TypesPackage.Literals.JVM_TYPE);
IScope scope = scopeProvider.getScope(context, reference);
IEObjectDescription declarator = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(name));
if (declarator != null && EcoreUtil2.isAssignableFrom(TypesPackage.eINSTANCE.getJvmGenericType(), declarator.getEClass())) {
jvmDeclaredType = (JvmDeclaredType) context.eResource().getResourceSet().getEObject(declarator.getEObjectURI(), true);
}
}
return jvmDeclaredType;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class JavaTypeQuickfixes method addQuickfixes.
@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
String issueString = xtextDocument.get(issue.getOffset(), issue.getLength());
IScope scope = scopeProvider.getScope(referenceOwner, unresolvedReference);
boolean useJavaSearch = isUseJavaSearch(unresolvedReference, issue);
if (useJavaSearch) {
JvmDeclaredType jvmType = importsConfiguration.getContextJvmDeclaredType(referenceOwner);
IJavaSearchScope javaSearchScope = getJavaSearchScope(referenceOwner);
boolean proposeImports = true;
if (isConstructorReference(unresolvedReference))
proposeImports = !createConstructorProposals(jvmType, issue, issueString, javaSearchScope, issueResolutionAcceptor);
if (proposeImports)
createImportProposals(jvmType, issue, issueString, javaSearchScope, issueResolutionAcceptor);
scope = getImportedTypesScope(referenceOwner, issueString, scope, javaSearchScope);
}
List<IEObjectDescription> discardedDescriptions = Lists.newArrayList();
Set<String> proposedSolutions = Sets.newHashSet();
int addedDescriptions = 0;
int checkedDescriptions = 0;
for (IEObjectDescription referableElement : scope.getAllElements()) {
String solution = qualifiedNameConverter.toString(referableElement.getName());
if (!equal(issueString, solution) && proposedSolutions.add(solution)) {
if (useJavaSearch || similarityMatcher.isSimilar(issueString, solution)) {
addedDescriptions++;
createResolution(issue, issueResolutionAcceptor, issueString, referableElement);
proposedSolutions.add(solution);
} else {
discardedDescriptions.add(referableElement);
}
}
checkedDescriptions++;
if (checkedDescriptions > 100)
break;
}
if (discardedDescriptions.size() + addedDescriptions <= 5) {
for (IEObjectDescription referableElement : discardedDescriptions) {
createResolution(issue, issueResolutionAcceptor, issueString, referableElement);
}
}
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class AbstractHierarchyBuilderTest method toExpectation.
protected String toExpectation(final IHierarchyNode node, final IHierarchyBuilder builder) {
StringConcatenation _builder = new StringConcatenation();
IEObjectDescription _element = node.getElement();
_builder.append(_element);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
String _internalToExpectation = this.internalToExpectation(node, builder);
_builder.append(_internalToExpectation, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
return _builder.toString();
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class RefactoringCrossReferenceSerializer method getCrossRefText.
public String getCrossRefText(EObject owner, CrossReference crossref, EObject target, RefTextEvaluator refTextEvaluator, ITextRegion linkTextRegion, StatusWrapper status) {
try {
final EReference ref = GrammarUtil.getReference(crossref, owner.eClass());
final IScope scope = scopeProvider.getScope(owner, ref);
if (scope == null) {
throw new IllegalStateException("Could not create scope for the given cross reference.");
}
String ruleName = linkingHelper.getRuleNameFrom(crossref);
Iterable<IEObjectDescription> descriptionsForCrossRef = scope.getElements(target);
String bestRefText = null;
List<String> badNames = new ArrayList<String>();
for (IEObjectDescription desc : descriptionsForCrossRef) {
try {
String unconvertedRefText = qualifiedNameConverter.toString(desc.getName());
String convertedRefText = valueConverter.toString(unconvertedRefText, ruleName);
if (refTextEvaluator.isValid(desc) && (bestRefText == null || refTextEvaluator.isBetterThan(convertedRefText, bestRefText)))
bestRefText = convertedRefText;
} catch (ValueConverterException e) {
// this is a problem only if we don't find any matching value
badNames.add(desc.getName().toString());
}
}
if (bestRefText == null && !badNames.isEmpty()) {
status.add(WARNING, "Misconfigured language: New reference text has invalid syntax. Following names are in the scope: " + IterableExtensions.join(badNames, ", "), owner, linkTextRegion);
}
return bestRefText;
} catch (Exception exc) {
log.error(exc.getMessage(), exc);
status.add(ERROR, exc.getMessage(), owner, linkTextRegion);
return null;
}
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class OpenXtextElementHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell activeShell = HandlerUtil.getActiveShell(event);
ListDialog searchDialog = createSearchDialog(event, activeShell, searchEngine);
int result = searchDialog.open();
if (result == Window.OK) {
try {
Object[] selections = searchDialog.getResult();
if (selections != null && selections.length > 0) {
Object selection = selections[0];
if (selection instanceof IEObjectDescription) {
IEObjectDescription selectedObjectDescription = (IEObjectDescription) selection;
uriEditorOpener.open(selectedObjectDescription.getEObjectURI(), true);
}
}
} catch (Exception e) {
LOG.error("Error opening editor", e);
throw new ExecutionException("Error opening editor", e);
}
}
return null;
}
Aggregations