| package org.eclipse.osbp.xtext.oxtype.imports; |
| |
| import org.eclipse.osbp.xtext.oxtype.linking.JvmTypeAwareLinkingHelper; |
| import org.eclipse.xtext.xbase.imports.TypeUsageCollector; |
| |
| import com.google.inject.Inject; |
| |
| /** |
| * This collector also imports JvmTypes which are stated in |
| */ |
| @SuppressWarnings("restriction") |
| public class JvmTypeEnhancingTypesCollector extends TypeUsageCollector { |
| |
| @Inject |
| private JvmTypeAwareLinkingHelper jvmTypeLinkingHelper; |
| |
| // protected void acceptType(JvmTypeReference ref) { |
| // if (jvmTypeLinkingHelper.isJvmLink(ref.eContainingFeature())) { |
| // acceptPreferredType(ref); |
| // } else if (ref instanceof XFunctionTypeRef |
| // || ref instanceof JvmWildcardTypeReference |
| // || ref instanceof JvmGenericArrayTypeReference |
| // || (ref.eContainer() instanceof XFunctionTypeRef && ref |
| // .eContainmentFeature() == JVM_SPECIALIZED_TYPE_REFERENCE__EQUIVALENT) |
| // || NodeModelUtils.findActualNodeFor(ref) == null) { |
| // return; |
| // } else { |
| // acceptPreferredType(ref); |
| // } |
| // } |
| // |
| // protected PreferredType findPreferredType(EObject owner, |
| // EReference reference, String text) { |
| // JvmIdentifiableElement referencedThing = getReferencedElement(owner, |
| // reference); |
| // JvmDeclaredType referencedType = null; |
| // if (referencedThing instanceof JvmDeclaredType) { |
| // referencedType = (JvmDeclaredType) referencedThing; |
| // } else if (referencedThing instanceof JvmMember) { |
| // referencedType = ((JvmMember) referencedThing).getDeclaringType(); |
| // } else if (referencedThing instanceof JvmType) { |
| // if (referencedThing.eIsProxy()) { |
| // String importedName = getFirstNameSegment(owner, reference); |
| // return jvmTypeLinkingHelper.isJvmLink(owner |
| // .eContainingFeature()) ? new CustomPreferredType( |
| // importedName, true) : new PreferredType(importedName); |
| // } |
| // return null; |
| // } |
| // return findPreferredType(referencedType, text); |
| // } |
| // |
| // private String getFirstNameSegment(EObject owner, EReference reference) { |
| // if (jvmTypeLinkingHelper.isJvmLink(owner.eContainingFeature())) { |
| // EReference semanticRef = jvmTypeLinkingHelper |
| // .getSemanticReference(owner.eContainingFeature()); |
| // List<INode> nodes = NodeModelUtils.findNodesForFeature( |
| // owner.eContainer(), semanticRef); |
| // if (nodes.size() == 1) { |
| // String text = NodeModelUtils.getTokenText(nodes.get(0)); |
| // IJvmLinkCrossRefStringEnhancer enhancer = jvmTypeLinkingHelper |
| // .getEnhancer(owner.eContainingFeature()); |
| // if (enhancer != null) { |
| // return enhancer.enhance(owner, reference, text); |
| // } |
| // } |
| // } else { |
| // List<INode> nodes = NodeModelUtils.findNodesForFeature(owner, |
| // reference); |
| // if (nodes.size() == 1) { |
| // String text = NodeModelUtils.getTokenText(nodes.get(0)); |
| // return getFirstNameSegment(text); |
| // } |
| // } |
| // throw new IllegalStateException("Cannot find node for feature"); |
| // } |
| // |
| // public class CustomPreferredType extends TypeUsageCollector.PreferredType |
| // { |
| // |
| // private final boolean jvmHelperLink; |
| // |
| // public CustomPreferredType(JvmType referencedType, JvmType usedType) { |
| // super(referencedType, usedType); |
| // jvmHelperLink = false; |
| // } |
| // |
| // public CustomPreferredType(String name) { |
| // this(name, false); |
| // } |
| // |
| // public CustomPreferredType(String name, boolean jvmHelperLink) { |
| // super(name); |
| // this.jvmHelperLink = jvmHelperLink; |
| // } |
| // |
| // public boolean isJvmHelperLink() { |
| // return jvmHelperLink; |
| // } |
| // |
| // } |
| } |