Search in sources :

Example 1 with IErlAttribute

use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.

the class ParserDB method handleModule.

public void handleModule(final IErlModule module) throws ErlModelException {
    module.open(null);
    final int numForms = module.getChildCount();
    final String path = module.getResource().getLocation().toPortableString();
    ParserDB.out.println(path + " " + numForms + " " + isTest(path));
    System.out.println(path + " " + numForms + " " + isTest(path));
    for (final IErlElement form : module.getChildren()) {
        ParserDB.out.print(" " + form.getKind() + " ");
        if (form instanceof IErlImportExport) {
            final IErlImportExport export = (IErlImportExport) form;
            ParserDB.out.println(export.getFunctions().size());
        } else if (form instanceof IErlPreprocessorDef) {
            final IErlPreprocessorDef def = (IErlPreprocessorDef) form;
            ParserDB.out.println(fix(def.getDefinedName()));
        } else if (form instanceof IErlTypespec) {
            final IErlTypespec attribute = (IErlTypespec) form;
            ParserDB.out.println("TYPESPEC " + fix(attribute.getName()));
        } else if (form instanceof IErlAttribute) {
            final IErlAttribute attribute = (IErlAttribute) form;
            ParserDB.out.println(fix(attribute.getName()));
        } else if (form instanceof IErlFunction) {
            final IErlFunction function = (IErlFunction) form;
            int numClauses = function.getChildCount();
            numClauses = numClauses == 0 ? 1 : numClauses;
            ParserDB.out.println(fix(function.getName()) + " " + function.getArity() + " " + numClauses);
        } else {
            ParserDB.out.println("?? " + form.getClass().getName());
        }
    }
    module.close();
    module.dispose();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlImportExport(org.erlide.engine.model.erlang.IErlImportExport) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute)

Example 2 with IErlAttribute

use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.

the class ErlParser method addModuleAttribute.

private IErlAttribute addModuleAttribute(final IErlModule module, final OtpErlangObject pos, final OtpErlangAtom value, final OtpErlangObject extra, final String nameS) {
    final String s = Util.stringValue(extra);
    final ErlAttribute r = new ErlAttribute(module, nameS, value, s);
    setPos(r, pos);
    return r;
}
Also used : IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) ErlAttribute(org.erlide.engine.internal.model.erlang.ErlAttribute) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 3 with IErlAttribute

use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.

the class SearchPatternFactory method getSearchPatternFromErlElementAndLimitTo.

public ErlangSearchPattern getSearchPatternFromErlElementAndLimitTo(final IErlElement element, final LimitTo limitTo) {
    if (element instanceof IErlFunction) {
        final IErlFunction function = (IErlFunction) element;
        final String withoutExtension = SystemConfiguration.withoutExtension(function.getModuleName());
        return new FunctionPattern(withoutExtension, function.getFunctionName(), function.getArity(), limitTo, true, modelUtilService.getModule(function), !function.isExported());
    } else if (element instanceof IErlMacroDef) {
        final IErlMacroDef m = (IErlMacroDef) element;
        final String unquoted = StringUtils.unquote(m.getDefinedName());
        return new MacroPattern(unquoted, limitTo);
    } else if (element instanceof IErlRecordDef) {
        final IErlRecordDef r = (IErlRecordDef) element;
        final String unquoted = StringUtils.unquote(r.getDefinedName());
        return new RecordPattern(unquoted, limitTo);
    } else if (element instanceof IErlFunctionClause) {
        final IErlFunctionClause clause = (IErlFunctionClause) element;
        return getSearchPatternFromErlElementAndLimitTo((IErlElement) clause.getParent(), limitTo);
    } else if (element instanceof IErlAttribute) {
        final IErlAttribute a = (IErlAttribute) element;
        if (a.getName().startsWith("include")) {
            final String s = Util.stringValue(a.getValue());
            return new IncludePattern(s, limitTo);
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) IErlMacroDef(org.erlide.engine.model.erlang.IErlMacroDef) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Example 4 with IErlAttribute

use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.

the class AddRefacHandler method checkType.

// check if the refactoring is elementary or composite
private RefacType checkType(final String callbackModule) {
    try {
        final IErlModule module = ErlangEngine.getInstance().getModel().findModule(callbackModule);
        final ScannerService scanner = module.getScanner();
        try {
            module.resetAndCacheScannerAndParser(null);
        } finally {
            scanner.dispose();
        }
        for (final IErlElement el : module.getChildrenOfKind(ErlElementKind.ATTRIBUTE)) {
            final IErlAttribute attr = (IErlAttribute) el;
            if ("behaviour".equals(attr.getName()) || "behavior".equals(attr.getName())) {
                if (attr.getValue().toString().contains("gen_refac")) {
                    return RefacType.ELEMENTARY;
                } else if (attr.getValue().toString().contains("gen_composite_refac")) {
                    return RefacType.COMPOSITE;
                }
            }
        }
        return null;
    } catch (final ErlModelException e) {
        return null;
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) ScannerService(org.erlide.engine.services.parsing.ScannerService)

Example 5 with IErlAttribute

use of org.erlide.engine.model.erlang.IErlAttribute in project erlide_eclipse by erlang.

the class ErlangCompareUtilities method getErlElementID.

/**
 * Returns a name for the given Erlang element
 */
static String getErlElementID(final IErlElement e) {
    final StringBuilder sb = new StringBuilder();
    final ErlElementKind kind = e.getKind();
    sb.append(kind);
    if (kind == ErlElementKind.FUNCTION) {
        final IErlFunction f = (IErlFunction) e;
        sb.append(f.getNameWithArity());
    } else if (kind == ErlElementKind.CLAUSE) {
        final IErlFunctionClause fc = (IErlFunctionClause) e;
        sb.append(fc.getHead());
    } else if (kind == ErlElementKind.ATTRIBUTE) {
        final IErlAttribute a = (IErlAttribute) e;
        sb.append(a.getName());
        if (a.getValue() != null) {
            sb.append(a.getValue().toString());
        }
    } else if (kind == ErlElementKind.RECORD_DEF || kind == ErlElementKind.MACRO_DEF) {
        final IErlPreprocessorDef pd = (IErlPreprocessorDef) e;
        sb.append(pd.getDefinedName());
    }
    return sb.toString();
}
Also used : ErlElementKind(org.erlide.engine.model.ErlElementKind) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)8 IErlElement (org.erlide.engine.model.IErlElement)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 ErlAttribute (org.erlide.engine.internal.model.erlang.ErlAttribute)2 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 TextSelection (org.eclipse.jface.text.TextSelection)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1 ErlElementKind (org.erlide.engine.model.ErlElementKind)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 ErlangIncludeFile (org.erlide.engine.model.erlang.ErlangIncludeFile)1 IErlImportExport (org.erlide.engine.model.erlang.IErlImportExport)1 IErlMacroDef (org.erlide.engine.model.erlang.IErlMacroDef)1