blob: c7bd2d4f7403fa4a5ef9dbde8010993a678ec78e [file] [log] [blame]
package org.eclipse.osbp.xtext.oxtype.imports;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.common.types.JvmDeclaredType;
import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.common.types.TypesPackage;
import org.eclipse.xtext.xbase.imports.IImportsConfiguration;
import com.google.inject.Inject;
@SuppressWarnings("restriction")
public class DefaultShouldImportProvider implements IShouldImportProvider {
@Inject
private IImportsConfiguration importsConfiguration;
@Override
public boolean shouldImport(EObject toImport, EReference eRef, EObject context) {
// if ownerJvmType is null, there is no derived state JvmModel
// available. And we need to use "import ns org.foo.Bar"
JvmDeclaredType ownerJvmType = importsConfiguration.getContextJvmDeclaredType(toImport);
if (ownerJvmType != null && toImport.eClass().getEPackage() == TypesPackage.eINSTANCE) {
// in this case, let XbaseImportOrganizer do the job
return false;
}
boolean result = toImport.eResource() != context.eResource();
if (result == true) {
return doShouldImport(toImport, eRef, context);
} else {
return false;
}
}
/**
* To be overridden by sub classes. For {@link JvmType} never return true!
* See default impl in {@link #shouldImport(EObject, EReference, EObject)}.
*
* @param toImport
* @param eRef
* @param context
* @return
*/
protected boolean doShouldImport(EObject toImport, EReference eRef, EObject context) {
return true;
}
@Override
public boolean shouldProposeAllElements(EObject object, EReference reference) {
return doShouldProposeAllElements(object, reference);
}
@Override
public boolean shouldAutoImport(EObject context, EReference reference) {
return doShouldAutoImport(context, reference);
}
/**
* To be overridden by subclass.
*
* @param object
* @param reference
* @return
*/
protected boolean doShouldProposeAllElements(EObject object, EReference reference) {
return false;
}
/**
* To be overridden by subclass.
*
* @param object
* @param reference
* @return
*/
public boolean doShouldAutoImport(EObject context, EReference reference) {
return doShouldProposeAllElements(context, reference);
}
}