blob: bc11837efce7b1e6de92eca0fbc9005b750ac00c [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*
*/
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);
}
}