Search in sources :

Example 61 with LinkedHashMap

use of java.util.LinkedHashMap in project retrofit by square.

the class RequestBuilderTest method formEncodedWithEncodedNameFieldParamMap.

@Test
public void formEncodedWithEncodedNameFieldParamMap() {
    class Example {

        //
        @FormUrlEncoded
        //
        @POST("/foo")
        Call<ResponseBody> method(@FieldMap(encoded = true) Map<String, Object> fieldMap) {
            return null;
        }
    }
    Map<String, Object> fieldMap = new LinkedHashMap<>();
    fieldMap.put("k%20it", "k%20at");
    fieldMap.put("pin%20g", "po%20ng");
    Request request = buildRequest(Example.class, fieldMap);
    assertBody(request.body(), "k%20it=k%20at&pin%20g=po%20ng");
}
Also used : FieldMap(retrofit2.http.FieldMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 62 with LinkedHashMap

use of java.util.LinkedHashMap in project retrofit by square.

the class RequestBuilderTest method getWithHeaderMap.

@Test
public void getWithHeaderMap() {
    class Example {

        @GET("/search")
        Call<ResponseBody> method(@HeaderMap Map<String, Object> headers) {
            return null;
        }
    }
    Map<String, Object> headers = new LinkedHashMap<>();
    headers.put("Accept", "text/plain");
    headers.put("Accept-Charset", "utf-8");
    Request request = buildRequest(Example.class, headers);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.url().toString()).isEqualTo("http://example.com/search");
    assertThat(request.body()).isNull();
    assertThat(request.headers().size()).isEqualTo(2);
    assertThat(request.header("Accept")).isEqualTo("text/plain");
    assertThat(request.header("Accept-Charset")).isEqualTo("utf-8");
}
Also used : HeaderMap(retrofit2.http.HeaderMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 63 with LinkedHashMap

use of java.util.LinkedHashMap in project dagger by square.

the class GraphAnalysisProcessor method processCompleteModule.

private Map<String, Binding<?>> processCompleteModule(TypeElement rootModule, boolean ignoreCompletenessErrors) {
    Map<String, TypeElement> allModules = new LinkedHashMap<String, TypeElement>();
    collectIncludesRecursively(rootModule, allModules, new LinkedList<String>());
    ArrayList<GraphAnalysisStaticInjection> staticInjections = new ArrayList<GraphAnalysisStaticInjection>();
    Linker.ErrorHandler errorHandler = ignoreCompletenessErrors ? Linker.ErrorHandler.NULL : new GraphAnalysisErrorHandler(processingEnv, rootModule.getQualifiedName().toString());
    Linker linker = new Linker(null, new GraphAnalysisLoader(processingEnv), errorHandler);
    // to make the linker happy.
    synchronized (linker) {
        BindingsGroup baseBindings = new BindingsGroup() {

            @Override
            public Binding<?> contributeSetBinding(String key, SetBinding<?> value) {
                return super.put(key, value);
            }
        };
        BindingsGroup overrideBindings = new BindingsGroup() {

            @Override
            public Binding<?> contributeSetBinding(String key, SetBinding<?> value) {
                throw new IllegalStateException("Module overrides cannot contribute set bindings.");
            }
        };
        for (TypeElement module : allModules.values()) {
            Map<String, Object> annotation = getAnnotation(Module.class, module);
            boolean overrides = (Boolean) annotation.get("overrides");
            boolean library = (Boolean) annotation.get("library");
            BindingsGroup addTo = overrides ? overrideBindings : baseBindings;
            // Gather the injectable types from the annotation.
            Set<String> injectsProvisionKeys = new LinkedHashSet<String>();
            for (Object injectableTypeObject : (Object[]) annotation.get("injects")) {
                TypeMirror injectableType = (TypeMirror) injectableTypeObject;
                String providerKey = GeneratorKeys.get(injectableType);
                injectsProvisionKeys.add(providerKey);
                String key = isInterface(injectableType) ? providerKey : GeneratorKeys.rawMembersKey(injectableType);
                linker.requestBinding(key, module.getQualifiedName().toString(), getClass().getClassLoader(), false, true);
            }
            // Gather the static injections.
            for (Object staticInjection : (Object[]) annotation.get("staticInjections")) {
                TypeMirror staticInjectionTypeMirror = (TypeMirror) staticInjection;
                Element element = processingEnv.getTypeUtils().asElement(staticInjectionTypeMirror);
                staticInjections.add(new GraphAnalysisStaticInjection(element));
            }
            // Gather the enclosed @Provides methods.
            for (Element enclosed : module.getEnclosedElements()) {
                Provides provides = enclosed.getAnnotation(Provides.class);
                if (provides == null) {
                    continue;
                }
                ExecutableElement providerMethod = (ExecutableElement) enclosed;
                String key = GeneratorKeys.get(providerMethod);
                ProvidesBinding<?> binding = new ProviderMethodBinding(key, providerMethod, library);
                Binding<?> previous = addTo.get(key);
                if (previous != null) {
                    if ((provides.type() == SET || provides.type() == SET_VALUES) && previous instanceof SetBinding) {
                    // No duplicate bindings error if both bindings are set bindings.
                    } else {
                        String message = "Duplicate bindings for " + key;
                        if (overrides) {
                            message += " in override module(s) - cannot override an override";
                        }
                        message += ":\n    " + previous.requiredBy + "\n    " + binding.requiredBy;
                        error(message, providerMethod);
                    }
                }
                switch(provides.type()) {
                    case UNIQUE:
                        if (injectsProvisionKeys.contains(binding.provideKey)) {
                            binding.setDependedOn(true);
                        }
                        try {
                            addTo.contributeProvidesBinding(key, binding);
                        } catch (IllegalStateException ise) {
                            throw new ModuleValidationException(ise.getMessage(), providerMethod);
                        }
                        break;
                    case SET:
                        String setKey = GeneratorKeys.getSetKey(providerMethod);
                        SetBinding.add(addTo, setKey, binding);
                        break;
                    case SET_VALUES:
                        SetBinding.add(addTo, key, binding);
                        break;
                    default:
                        throw new AssertionError("Unknown @Provides type " + provides.type());
                }
            }
        }
        linker.installBindings(baseBindings);
        linker.installBindings(overrideBindings);
        for (GraphAnalysisStaticInjection staticInjection : staticInjections) {
            staticInjection.attach(linker);
        }
        // errors if any dependencies are missing.
        return linker.linkAll();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TypeMirror(javax.lang.model.type.TypeMirror) BindingsGroup(dagger.internal.BindingsGroup) TypeElement(javax.lang.model.element.TypeElement) Linker(dagger.internal.Linker) Provides(dagger.Provides) FileObject(javax.tools.FileObject) SetBinding(dagger.internal.SetBinding)

Example 64 with LinkedHashMap

use of java.util.LinkedHashMap in project dagger by square.

the class ValidationProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> types, RoundEnvironment env) {
    List<Element> allElements = new ArrayList<Element>();
    Map<Element, Element> parametersToTheirMethods = new LinkedHashMap<Element, Element>();
    getAllElements(env, allElements, parametersToTheirMethods);
    for (Element element : allElements) {
        try {
            validateProvides(element);
        } catch (CodeGenerationIncompleteException e) {
            // Upstream compiler issue in play. Ignore this element.
            continue;
        }
        validateScoping(element);
        validateQualifiers(element, parametersToTheirMethods);
    }
    return false;
}
Also used : CodeGenerationIncompleteException(dagger.internal.codegen.Util.CodeGenerationIncompleteException) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 65 with LinkedHashMap

use of java.util.LinkedHashMap in project leakcanary by square.

the class ShortestPathFinder method visitClassInstance.

private void visitClassInstance(LeakNode node) {
    ClassInstance classInstance = (ClassInstance) node.instance;
    Map<String, Exclusion> ignoredFields = new LinkedHashMap<>();
    ClassObj superClassObj = classInstance.getClassObj();
    Exclusion classExclusion = null;
    while (superClassObj != null) {
        Exclusion params = excludedRefs.classNames.get(superClassObj.getClassName());
        if (params != null) {
            // true overrides null or false.
            if (classExclusion == null || !classExclusion.alwaysExclude) {
                classExclusion = params;
            }
        }
        Map<String, Exclusion> classIgnoredFields = excludedRefs.fieldNameByClassName.get(superClassObj.getClassName());
        if (classIgnoredFields != null) {
            ignoredFields.putAll(classIgnoredFields);
        }
        superClassObj = superClassObj.getSuperClassObj();
    }
    if (classExclusion != null && classExclusion.alwaysExclude) {
        return;
    }
    for (ClassInstance.FieldValue fieldValue : classInstance.getValues()) {
        Exclusion fieldExclusion = classExclusion;
        Field field = fieldValue.getField();
        if (field.getType() != Type.OBJECT) {
            continue;
        }
        Instance child = (Instance) fieldValue.getValue();
        String fieldName = field.getName();
        Exclusion params = ignoredFields.get(fieldName);
        // If we found a field exclusion and it's stronger than a class exclusion
        if (params != null && (fieldExclusion == null || (params.alwaysExclude && !fieldExclusion.alwaysExclude))) {
            fieldExclusion = params;
        }
        enqueue(fieldExclusion, node, child, fieldName, INSTANCE_FIELD);
    }
}
Also used : ClassObj(com.squareup.haha.perflib.ClassObj) Field(com.squareup.haha.perflib.Field) Instance(com.squareup.haha.perflib.Instance) ClassInstance(com.squareup.haha.perflib.ClassInstance) ArrayInstance(com.squareup.haha.perflib.ArrayInstance) ClassInstance(com.squareup.haha.perflib.ClassInstance) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2398 Map (java.util.Map)691 ArrayList (java.util.ArrayList)675 HashMap (java.util.HashMap)439 Test (org.junit.Test)317 List (java.util.List)298 IOException (java.io.IOException)152 HashSet (java.util.HashSet)128 Set (java.util.Set)110 LinkedHashSet (java.util.LinkedHashSet)100 File (java.io.File)93 LinkedList (java.util.LinkedList)75 TreeMap (java.util.TreeMap)72 Node (org.apache.hadoop.hive.ql.lib.Node)70 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)68 Rule (org.apache.hadoop.hive.ql.lib.Rule)68 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)66 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)65 Iterator (java.util.Iterator)64 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)64