use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method specifyTypeExplicitly.
@Fix(IssueCodes.API_TYPE_INFERENCE)
public void specifyTypeExplicitly(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Infer type", "Infer type", null, new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
EStructuralFeature featureAfterType = null;
JvmIdentifiableElement jvmElement = null;
if (element instanceof XtendFunction) {
XtendFunction function = (XtendFunction) element;
if (function.getCreateExtensionInfo() == null) {
featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__NAME;
} else {
featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__CREATE_EXTENSION_INFO;
}
jvmElement = associations.getDirectlyInferredOperation((XtendFunction) element);
} else if (element instanceof XtendField) {
featureAfterType = XtendPackage.Literals.XTEND_FIELD__NAME;
jvmElement = associations.getJvmField((XtendField) element);
}
if (jvmElement != null) {
LightweightTypeReference type = batchTypeResolver.resolveTypes(element).getActualType(jvmElement);
INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(element, featureAfterType), null);
if (node == null) {
throw new IllegalStateException("Could not determine node for " + element);
}
if (type == null) {
throw new IllegalStateException("Could not determine type for " + element);
}
ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) element.eResource(), node.getOffset(), 0);
appendable.append(type);
appendable.append(" ");
appendable.commitChanges();
}
}
});
}
use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class XtendReferenceFinder method addReferenceToTypeFromStaticImport.
protected void addReferenceToTypeFromStaticImport(final XAbstractFeatureCall sourceCandidate, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) {
final JvmIdentifiableElement feature = sourceCandidate.getFeature();
if ((feature instanceof JvmMember)) {
final JvmDeclaredType type = ((JvmMember) feature).getDeclaringType();
this.addReferenceIfTarget(type, targetURISet, sourceCandidate, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor);
}
}
use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class SyntheticNameClashResolver method resolveNameClashes.
public void resolveNameClashes(JvmGenericType type) {
Multimap<String, JvmIdentifiableElement> classScope = HashMultimap.create();
List<JvmMember> renameableMembers = newArrayList();
int i = 1;
for (JvmMember member : type.getMembers()) {
String simpleName = member.getSimpleName();
if (simpleName != null) {
if (!isRenameable(member))
classScope.put(simpleName, member);
else
renameableMembers.add(member);
}
if (member instanceof JvmFeature) {
for (JvmGenericType localType : ((JvmFeature) member).getLocalClasses()) {
localType.setSimpleName(localType.getSimpleName() + '_' + (i++));
}
}
}
for (JvmMember renameable : renameableMembers) {
String simpleName = renameable.getSimpleName();
if (collides(renameable, simpleName, classScope)) {
int count = 0;
String currentName;
do {
if (count == Integer.MAX_VALUE)
throw new IllegalStateException("Cannot find a collision-free name for " + renameable.getIdentifier());
currentName = simpleName + "_" + ++count;
} while (collides(renameable, currentName, classScope));
renameable.setSimpleName(currentName);
classScope.put(currentName, renameable);
} else {
classScope.put(simpleName, renameable);
}
}
}
use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class XtendHoverSerializer method computeUnsugaredExpression.
public String computeUnsugaredExpression(EObject object) {
if (object instanceof XAbstractFeatureCall) {
StringBuilder stringBuilder = new StringBuilder();
XAbstractFeatureCall featureCall = (XAbstractFeatureCall) object;
JvmIdentifiableElement feature = featureCall.getFeature();
if (feature != null && !feature.eIsProxy()) {
// Static extensions which are no expliciteOperationCalls
if (featureCall instanceof XMemberFeatureCall && feature instanceof JvmOperation && !((XMemberFeatureCall) featureCall).isExplicitOperationCall()) {
JvmOperation jvmOperation = (JvmOperation) feature;
if (jvmOperation.isStatic()) {
return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, jvmOperation)).toString();
}
}
// Static calls with implicit receiver or implicit first argument
if (featureCall.getImplicitReceiver() != null || featureCall.getImplicitFirstArgument() != null) {
if (featureCall.isStatic()) {
return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, (JvmMember) feature)).toString();
}
XExpression receiver = featureCall.getActualReceiver();
if (receiver instanceof XMemberFeatureCall) {
stringBuilder.append(THIS).append(DELIMITER);
stringBuilder.append(((XMemberFeatureCall) receiver).getFeature().getSimpleName()).append(DELIMITER);
} else if (receiver instanceof XAbstractFeatureCall) {
JvmIdentifiableElement receiverFeature = ((XAbstractFeatureCall) receiver).getFeature();
if (receiverFeature == feature.eContainer()) {
stringBuilder.append(THIS).append(DELIMITER);
} else {
stringBuilder.append(receiverFeature.getSimpleName()).append(DELIMITER);
}
}
stringBuilder.append(feature.getSimpleName());
if (feature instanceof JvmExecutable)
stringBuilder.append(computeArguments(featureCall));
return stringBuilder.toString();
}
}
}
return "";
}
use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class XtendHyperlinkHelper method createHyperlinksByOffset.
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
super.createHyperlinksByOffset(resource, offset, acceptor);
if (canShowMany(acceptor)) {
final EObject element = getEObjectAtOffsetHelper().resolveElementAt(resource, offset);
if (element instanceof XtendField) {
XtendField member = (XtendField) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(member, XtendPackage.Literals.XTEND_FIELD__NAME, node) && member.getType() == null) {
EObject jvmElement = associations.getPrimaryJvmElement(member);
if (jvmElement instanceof JvmIdentifiableElement) {
addOpenInferredTypeHyperlink(resource, (JvmIdentifiableElement) jvmElement, node, acceptor);
}
}
}
if (element instanceof XtendFunction) {
XtendFunction member = (XtendFunction) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(member, XtendPackage.Literals.XTEND_FUNCTION__NAME, node)) {
EObject jvmElement = associations.getPrimaryJvmElement(member);
if (jvmElement instanceof JvmIdentifiableElement) {
JvmIdentifiableElement identifiableElement = (JvmIdentifiableElement) jvmElement;
if (member.getReturnType() == null) {
addOpenInferredTypeHyperlink(resource, identifiableElement, node, acceptor);
}
IJavaElement javaElement = javaElementFinder.findExactElementFor(identifiableElement);
if (sourceViewer != null && javaElement != null && (javaElement.getElementType() == IJavaElement.METHOD && canBeOverridden((IMethod) javaElement))) {
Region region = new Region(node.getOffset(), node.getLength());
acceptor.accept(new XbaseImplementatorsHyperlink(javaElement, region, sourceViewer, implOpener));
}
}
}
}
}
}
Aggregations