Search in sources :

Example 61 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project xtext-eclipse by eclipse.

the class XbaseUIValidator method checkRestrictedType.

protected void checkRestrictedType(final EObject context, final EStructuralFeature feature, final JvmDeclaredType typeToCheck) {
    @SuppressWarnings("unchecked") Map<JvmDeclaredType, Pair<RestrictionKind, String>> validationContext = (Map<JvmDeclaredType, Pair<RestrictionKind, String>>) getContext().get(RestrictionKind.class);
    if (validationContext == null) {
        validationContext = Maps.newHashMap();
        getContext().put(RestrictionKind.class, validationContext);
    }
    RestrictionKind restriction = null;
    String javaProjectName = null;
    Pair<RestrictionKind, String> cached = validationContext.get(typeToCheck);
    if (cached != null) {
        restriction = cached.getKey();
        javaProjectName = cached.getValue();
    }
    if (restriction == null) {
        final IJavaElement javaElement = javaElementFinder.findElementFor(typeToCheck);
        if (javaElement == null || !(javaElement instanceof IType)) {
            validationContext.put(typeToCheck, Pair.of(RestrictionKind.VALID, null));
            return;
        }
        IJavaProject javaProject = javaElement.getJavaProject();
        if (javaProject != null) {
            javaProjectName = javaProject.getElementName();
        }
        restriction = computeRestriction(projectProvider.getJavaProject(context.eResource().getResourceSet()), (IType) javaElement);
        validationContext.put(typeToCheck, Pair.of(restriction, javaProjectName));
    }
    if (restriction == RestrictionKind.FORBIDDEN) {
        if (javaProjectName == null) {
            IJavaProject javaProject = projectProvider.getJavaProject(context.eResource().getResourceSet());
            if (javaProject != null) {
                javaProjectName = javaProject.getElementName();
            }
        }
        addIssue("Access restriction: The type " + typeToCheck.getSimpleName() + " is not accessible due to restriction on required project " + javaProjectName, context, feature, IssueCodes.FORBIDDEN_REFERENCE);
    } else if (restriction == RestrictionKind.DISCOURAGED) {
        if (javaProjectName == null) {
            IJavaProject javaProject = projectProvider.getJavaProject(context.eResource().getResourceSet());
            if (javaProject != null) {
                javaProjectName = javaProject.getElementName();
            }
        }
        addIssue("Discouraged access: The type " + typeToCheck.getSimpleName() + " is not accessible due to restriction on required project " + javaProjectName, context, feature, IssueCodes.DISCOURAGED_REFERENCE);
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) Map(java.util.Map) Pair(org.eclipse.xtext.xbase.lib.Pair) IType(org.eclipse.jdt.core.IType)

Example 62 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project metalib by softlang.

the class Tests method testNegativeKeyword.

/**
 * Negative test for parser, s. figure D.37
 */
@Test
public void testNegativeKeyword() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("innnitial state locked {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("ticket/collect -> unlocked;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("pass/alarm -> exception;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("state unlocked {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("ticket/eject;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("pass -> locked;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("state exception {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("ticket/eject;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("pass;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("mute;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("release -> locked;");
    _builder.newLine();
    _builder.append("}");
    final Pair<FSM, Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>> annotatedFSM = this.annotatedParse(_builder);
    FSM _key = annotatedFSM.getKey();
    Assert.assertNull(_key);
    Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _value = annotatedFSM.getValue();
    EList<Resource.Diagnostic> _key_1 = _value.getKey();
    int _size = _key_1.size();
    Assert.assertEquals(_size, 0);
    Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _value_1 = annotatedFSM.getValue();
    EList<Resource.Diagnostic> _value_2 = _value_1.getValue();
    int _size_1 = _value_2.size();
    Assert.assertEquals(_size_1, 1);
    Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _value_3 = annotatedFSM.getValue();
    EList<Resource.Diagnostic> _value_4 = _value_3.getValue();
    final Resource.Diagnostic error = IterableExtensions.<Resource.Diagnostic>head(_value_4);
    int _line = error.getLine();
    Assert.assertEquals(_line, 1);
    String _message = error.getMessage();
    Assert.assertEquals(_message, "missing EOF at \'innnitial\'");
}
Also used : FSM(org.softlang.metalib.xtext.fsml.fsml.FSM) EList(org.eclipse.emf.common.util.EList) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) Pair(org.eclipse.xtext.xbase.lib.Pair) Test(org.junit.Test)

Example 63 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project erlide_eclipse by erlang.

the class CompilerOptions method store.

public void store() throws BackingStoreException {
    for (final CompilerOption option : ALL_OPTIONS) {
        final Object value = options.get(option);
        if (option instanceof BooleanOption) {
            final Boolean val = (Boolean) value;
            helper.putString(option.getName(), val.toString());
        } else if (option instanceof PathsOption) {
            if (value != null) {
                @SuppressWarnings("unchecked") final Iterable<String> avalue = (Iterable<String>) value;
                helper.putString(option.getName(), PathsOption.toString(avalue));
            } else {
                helper.remove(option.getName());
            }
        } else if (option instanceof ModuleOption || option instanceof RawOption) {
            if (value != null) {
                final String avalue = (String) value;
                helper.putString(option.getName(), avalue);
            } else {
                helper.remove(option.getName());
            }
        } else if (value != null) {
            @SuppressWarnings("unchecked") final Collection<Pair<String, String>> val = (Collection<Pair<String, String>>) value;
            helper.putString(option.getName(), val.toString());
        } else {
            helper.remove(option.getName());
        }
    }
    helper.flush();
}
Also used : ModuleOption(org.erlide.core.builder.CompilerOption.ModuleOption) PathsOption(org.erlide.core.builder.CompilerOption.PathsOption) Collection(java.util.Collection) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) BooleanOption(org.erlide.core.builder.CompilerOption.BooleanOption) RawOption(org.erlide.core.builder.CompilerOption.RawOption) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 64 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project erlide_eclipse by erlang.

the class BackendManager method addCodeBundle.

private void addCodeBundle(final IExtension extension) {
    final String pluginId = extension.getContributor().getName();
    final Bundle plugin = Platform.getBundle(pluginId);
    final Multimap<CodeContext, String> paths = HashMultimap.create();
    final List<Pair<String, String>> inits = Lists.newArrayList();
    RuntimeVersion ver = RuntimeVersion.NO_VERSION;
    for (final IConfigurationElement el : extension.getConfigurationElements()) {
        if ("beam_dir".equals(el.getName())) {
            final String dir = el.getAttribute("path");
            final String t = el.getAttribute("context").toUpperCase();
            final CodeContext type = Enum.valueOf(CodeContext.class, t);
            paths.put(type, dir);
        } else if ("init".equals(el.getName())) {
            final String module = el.getAttribute("module");
            final String function = el.getAttribute("function");
            inits.add(new Pair<>(module, function));
        } else if ("otp_version".equals(el.getName())) {
            final String attribute = el.getAttribute("value");
            if (attribute != null) {
                ver = RuntimeVersion.Serializer.parse(attribute);
            }
        } else {
            ErlLogger.error("Unknown code bundle element: %s", el.getName());
        }
    }
    addBundle(plugin, ver, paths, inits);
}
Also used : ICodeBundle(org.erlide.backend.api.ICodeBundle) Bundle(org.osgi.framework.Bundle) CodeContext(org.erlide.backend.api.ICodeBundle.CodeContext) RuntimeVersion(org.erlide.runtime.runtimeinfo.RuntimeVersion) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 65 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project erlide_eclipse by erlang.

the class CompilerOptionTest method testToTerm_5.

@Test
public void testToTerm_5() throws OtpParserException {
    final DefineOption option = CompilerOptions.DEFINE;
    @SuppressWarnings("unchecked") final List<Pair<String, String>> values = Lists.newArrayList(new Pair<>("Macro", "[hej,1]"));
    final OtpErlangObject actual = option.toTerm(values);
    final String expected = "[{d,'Macro',[hej,1]}]";
    Assert.assertEquals(expected, actual.toString());
}
Also used : DefineOption(org.erlide.core.builder.CompilerOption.DefineOption) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) Pair(org.eclipse.xtext.xbase.lib.Pair) Test(org.junit.Test)

Aggregations

Pair (org.eclipse.xtext.xbase.lib.Pair)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)22 Test (org.junit.Test)15 Collection (java.util.Collection)11 List (java.util.List)11 AbstractHierarchyBuilderTest (org.eclipse.xtext.junit4.ide.AbstractHierarchyBuilderTest)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 EObject (org.eclipse.emf.ecore.EObject)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 AbstractElement (org.eclipse.xtext.AbstractElement)6 HashMap (java.util.HashMap)5 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)5 Type (org.eclipse.n4js.ts.types.Type)5 EList (org.eclipse.emf.common.util.EList)4 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)4 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3