use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class OpenUtils method findLocalCall.
private IErlElement findLocalCall(final IErlModule module, final IErlProject erlProject, final OpenResult res, final IErlElement element, final IErlElementLocator.Scope scope) throws RpcException, CoreException {
if (isTypeDefOrRecordDef(element, res)) {
return modelFindService.findTypespec(module, res.getFun());
}
final IErlFunction foundElement = module.findFunction(res.getFunction());
if (foundElement != null) {
return foundElement;
}
// imported functions
OtpErlangObject res2 = null;
String moduleName = null;
final IErlImport ei = module.findImport(res.getFunction());
if (ei != null) {
final IErlModel model = ErlangEngine.getInstance().getModel();
moduleName = ei.getImportModule();
res2 = ErlangEngine.getInstance().getOpenService().getSourceFromModule(model.getPathVars(), moduleName, erlProject.getProperties().getExternalModules());
}
if (res2 instanceof OtpErlangString && moduleName != null) {
// imported from otp module
final OtpErlangString otpErlangString = (OtpErlangString) res2;
final String modulePath = otpErlangString.stringValue();
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
return modelFindService.findFunction(model, erlProject, module, moduleName, modulePath, res.getFunction(), scope);
}
// functions defined in include files
final Collection<IErlModule> allIncludedFiles = ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module);
for (final IErlModule includedModule : allIncludedFiles) {
final IErlFunction function = includedModule.findFunction(res.getFunction());
if (function != null) {
return function;
}
}
return null;
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class MarkerUtils method findResourceForFileName.
private static IResource findResourceForFileName(final IResource resource, final Entry<String, List<OtpErlangTuple>> entry, final String fileName) {
IResource res = resource;
if (!ResourceUtil.samePath(resource.getLocation().toString(), fileName)) {
final IProject project = resource.getProject();
res = ResourceUtil.findResourceByLocation(project, fileName);
if (res == null) {
try {
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlProject erlProject = model.findProject(project);
if (erlProject != null) {
final IErlModule includeFile = model.findIncludeFromProject(erlProject, fileName, fileName, IErlElementLocator.Scope.REFERENCED_PROJECTS);
if (includeFile == null) {
res = resource;
} else {
res = includeFile.getResource();
}
} else {
res = resource;
}
} catch (final Exception e) {
ErlLogger.warn(e);
}
}
}
return res;
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class StatsViewLabelProvider method getColumnImage.
@Override
public Image getColumnImage(final Object element, final int columnIndex) {
Image img = null;
final ICoverageObject statsEl = (ICoverageObject) element;
switch(columnIndex) {
case 0:
final ObjectType type = statsEl.getType();
switch(type) {
case FUNCTION:
img = Activator.getImageDescriptor(Images.FUNCTION).createImage();
break;
case MODULE:
IErlModule m;
try {
m = ErlangEngine.getInstance().getModel().findModule(statsEl.getLabel());
} catch (final ErlModelException e) {
ErlLogger.error(e);
return null;
}
img = ErlangElementImageProvider.getErlImageDescriptor(m, ErlangElementImageProvider.SMALL_ICONS).createImage();
break;
case FOLDER:
img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER).createImage();
break;
case PROJECT:
img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT).createImage();
break;
default:
break;
}
break;
case 3:
img = drawPercentage(statsEl.getPercentage());
break;
default:
}
return img;
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlNode method createErlNode.
public static ErlNode createErlNode(final ErlNode parent, final IErlElement element, final IDocument doc) {
int start = 0;
int length = 0;
String name = element.toString();
if (element instanceof IErlModule) {
final IErlModule m = (IErlModule) element;
length = doc.getLength();
name = m.getModuleName();
} else if (element instanceof ISourceReference) {
final ISourceReference sourceReference = (ISourceReference) element;
final ISourceRange sr = sourceReference.getSourceRange();
start = sr.getOffset();
length = sr.getLength();
}
return new ErlNode(parent, element.getKind(), name, ErlangCompareUtilities.getErlElementID(element), doc, start, length);
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlStructureCreator method createStructureComparator.
@Override
protected IStructureComparator createStructureComparator(final Object element, final IDocument document0, final ISharedDocumentAdapter sharedDocumentAdapter, final IProgressMonitor monitor) throws CoreException {
IErlModule module = null;
final IErlModel model = ErlangEngine.getInstance().getModel();
String s = "";
IDocument document = document0;
if (element instanceof ResourceNode) {
final ResourceNode rn = (ResourceNode) element;
final IResource r = rn.getResource();
if (r instanceof IFile) {
final IFile f = (IFile) r;
final IErlElement e = model.findElement(r);
if (e instanceof IErlModule) {
module = (IErlModule) e;
}
if (document == null) {
try {
s = ErlStructureCreator.readString(f.getContents());
document = new Document(s);
} catch (final CoreException e1) {
}
}
}
} else if (document == null && element instanceof IStreamContentAccessor) {
try {
try (final InputStream contents = ((IStreamContentAccessor) element).getContents()) {
s = ErlStructureCreator.readString(contents);
} catch (final IOException e) {
}
document = new Document(s);
} catch (final CoreException ex) {
}
} else if (document != null) {
s = document.get();
}
if (module == null) {
String name = "comptemp";
if (element instanceof ITypedElement) {
final ITypedElement typedElement = (ITypedElement) element;
name = typedElement.getName();
}
module = model.getModuleFromText(model, name, s, null);
}
ErlNode root = null;
if (element != null && document != null) {
try {
module.open(null);
root = new RootErlNode(document, element);
recursiveMakeErlNodes(module, root, document);
} catch (final ErlModelException e) {
ErlLogger.warn(e);
}
}
return root;
}
Aggregations