예제 #1
0
  private void removeValue(int inputId, Value value) {
    final Object input = getInput(value);
    if (input == null) {
      return;
    }

    if (input instanceof ChangeBufferingList) {
      final ChangeBufferingList changesList = (ChangeBufferingList) input;
      changesList.remove(inputId);
      if (!changesList.isEmpty()) return;
    } else if (input instanceof Integer) {
      if (((Integer) input).intValue() != inputId) {
        return;
      }
    }

    if (!(myInputIdMapping instanceof THashMap)) {
      myInputIdMapping = null;
      myInputIdMappingValue = null;
    } else {
      THashMap<Value, Object> mapping = (THashMap<Value, Object>) myInputIdMapping;
      mapping.remove(value);
      if (mapping.size() == 1) {
        myInputIdMapping = mapping.keySet().iterator().next();
        myInputIdMappingValue = mapping.get((Value) myInputIdMapping);
      }
    }
  }
예제 #2
0
  @NotNull
  public ValueContainerImpl<Value> copy() {
    ValueContainerImpl<Value> container = new ValueContainerImpl<Value>();

    if (myInputIdMapping instanceof THashMap) {
      final THashMap<Value, Object> mapping = (THashMap<Value, Object>) myInputIdMapping;
      final THashMap<Value, Object> newMapping = new THashMap<Value, Object>(mapping.size());
      container.myInputIdMapping = newMapping;

      mapping.forEachEntry(
          new TObjectObjectProcedure<Value, Object>() {
            @Override
            public boolean execute(Value key, Object val) {
              if (val instanceof ChangeBufferingList) {
                newMapping.put(key, ((ChangeBufferingList) val).clone());
              } else {
                newMapping.put(key, val);
              }
              return true;
            }
          });
    } else {
      container.myInputIdMapping = myInputIdMapping;
      container.myInputIdMappingValue =
          myInputIdMappingValue instanceof ChangeBufferingList
              ? ((ChangeBufferingList) myInputIdMappingValue).clone()
              : myInputIdMappingValue;
    }
    return container;
  }
예제 #3
0
  @Nullable
  public JsPropertyInitializer translate(
      @NotNull JetClassOrObject declaration, TranslationContext context) {
    ClassDescriptor descriptor = getClassDescriptor(context().bindingContext(), declaration);
    JsExpression value;
    if (descriptor.getModality() == Modality.FINAL) {
      value =
          new ClassTranslator(declaration, classDescriptorToQualifiedLabel, context).translate();
    } else {
      String label = createNameForClass(descriptor);
      JsName name = dummyFunction.getScope().declareName(label);
      JsNameRef qualifiedLabel = openClassDescriptorToQualifiedLabel.get(descriptor);
      if (qualifiedLabel == null) {
        qualifiedLabel = new JsNameRef(name);
        openClassDescriptorToQualifiedLabel.put(descriptor, qualifiedLabel);
      } else {
        qualifiedLabel.resolve(name);
      }
      qualifiedLabel.setQualifier(declarationsObjectRef);

      OpenClassInfo item = new OpenClassInfo((JetClass) declaration, descriptor, name.makeRef());

      openList.add(item);
      openClassDescriptorToItem.put(descriptor, item);

      value = qualifiedLabel;

      // not public api classes referenced to internal var _c
      if (!descriptor.getVisibility().isPublicAPI()) {
        return null;
      }
    }

    return InitializerUtils.createPropertyInitializer(descriptor, value, context());
  }
예제 #4
0
 public void loadState(final Element element) {
   myInjections.clear();
   final THashMap<String, LanguageInjectionSupport> supports =
       new THashMap<String, LanguageInjectionSupport>();
   for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
     supports.put(support.getId(), support);
   }
   loadStateOld(
       element,
       supports.get(LanguageInjectionSupport.XML_SUPPORT_ID),
       supports.get(LanguageInjectionSupport.JAVA_SUPPORT_ID));
   for (Element child : (List<Element>) element.getChildren("injection")) {
     final String key = child.getAttributeValue("injector-id");
     final LanguageInjectionSupport support = supports.get(key);
     final BaseInjection injection =
         support == null ? new BaseInjection(key) : support.createInjection(child);
     injection.loadState(child);
     InjectionPlace[] places = dropKnownInvalidPlaces(injection.getInjectionPlaces());
     if (places != null) { // not all places were removed
       injection.setInjectionPlaces(places);
       myInjections.get(key).add(injection);
     }
   }
   importPlaces(getDefaultInjections());
 }
 public void reset(@Nullable List<T> newOriginalItems) {
   if (newOriginalItems != null) {
     originalItems.clear();
     originalItems.addAll(newOriginalItems);
   }
   modifiedToOriginal.clear();
   originalToModified.clear();
 }
 public SNode remove(SNodeId key) {
   if (key instanceof Regular) {
     return myRegularMap.remove(((Regular) key).getId());
   } else if (key instanceof Foreign) {
     return myForeignMap.remove(((Foreign) key).getId());
   } else {
     return myOtherMap.remove(key);
   }
 }
 public boolean containsKey(SNodeId key) {
   if (key instanceof Regular) {
     return myRegularMap.containsKey(((Regular) key).getId());
   } else if (key instanceof Foreign) {
     return myForeignMap.containsKey(((Foreign) key).getId());
   } else {
     return myOtherMap.containsKey(key);
   }
 }
 public SNode put(SNodeId key, SNode value) {
   if (key instanceof Regular) {
     return myRegularMap.put(((Regular) key).getId(), value);
   } else if (key instanceof Foreign) {
     return myForeignMap.put(((Foreign) key).getId(), value);
   } else {
     return myOtherMap.put(key, value);
   }
 }
 /** Insert a term into this document, occurs at given block id */
 public void insert(String t, int blockId) {
   insert(t);
   TIntHashSet blockids = null;
   if ((blockids = term_blocks.get(t)) == null) {
     term_blocks.put(t, blockids = new TIntHashSet(/*TODO */ ));
   }
   blockids.add(blockId);
   blockCount++;
 }
예제 #10
0
  public SortResult sort(
      List<Library> libraries,
      File outFile,
      Condition<String> isExternal,
      boolean returnDefinitionMap)
      throws IOException {
    final THashMap<CharSequence, Definition> definitionMap =
        new THashMap<>(libraries.size() * 128, AbcTranscoder.HASHING_STRATEGY);
    final List<LibrarySetItem> unsortedItems = collectItems(libraries, definitionMap, isExternal);
    final AbcMerger abcMerger = new AbcMerger(definitionMap, outFile, definitionProcessor);
    try {
      final ArrayList<Library> resourceOrStyleHolders = new ArrayList<>(unsortedItems.size());
      for (LibrarySetItem item : unsortedItems) {
        if (!item.hasDefinitions()) {
          if (item.library.hasResourceBundles()) {
            resourceOrStyleHolders.add(item.library);
          }
          continue;
        }

        if (item.library.hasResourceBundles() || item.library.isStyleOwner()) {
          resourceOrStyleHolders.add(item.library);
        }

        abcMerger.process(item.library);
      }

      if (definitionMapProcessor != null) {
        definitionMapProcessor.process(definitionMap, abcMerger);
      }

      final List<Decoder> decoders = new ArrayList<>(definitionMap.size());
      final String[] singleStringArray = new String[1];
      definitionMap.forEachValue(
          new TObjectProcedure<Definition>() {
            @Override
            public boolean execute(Definition definition) {
              if (definition.doAbcData != null
                  && (definition.resolved == ResolvedState.YES
                      || (definition.resolved == ResolvedState.UNKNOWN
                          && processDependencies(
                              decoders, definition, definitionMap, singleStringArray)))) {
                decoders.add(createDecoder(definition));
              }

              return true;
            }
          });

      abcMerger.end(decoders, new Encoder());
      return new SortResult(returnDefinitionMap ? definitionMap : null, resourceOrStyleHolders);
    } finally {
      abcMerger.close();
    }
  }
 protected void readExternalImpl(Element e) {
   if (e.getAttribute("injector-id") == null) {
     setClassName(JDOMExternalizer.readString(e, "CLASS"));
     // setApplyInHierarchy(JDOMExternalizer.readBoolean(e, "APPLY_IN_HIERARCHY"));
     readOldFormat(e);
     final THashMap<String, String> map = new THashMap<>();
     JDOMExternalizer.readMap(e, map, null, "SIGNATURES");
     for (String s : map.keySet()) {
       final String fixedSignature = fixSignature(s, false);
       myParameterMap.put(fixedSignature, new MethodInfo(fixedSignature, map.get(s)));
     }
   }
 }
예제 #12
0
        @NotNull
        @Override
        public JsNameRef get(ClassDescriptor descriptor, ClassDescriptor referencedDescriptor) {
          JsNameRef ref = openClassDescriptorToQualifiedLabel.get(descriptor);
          if (ref != null) {
            return ref;
          }

          // will be resolved later
          ref = new JsNameRef("<unresolved class>");
          openClassDescriptorToQualifiedLabel.put(descriptor, ref);
          return ref;
        }
 @NotNull
 public T getMutable(@NotNull T item, int index) {
   if (isMutable(item) || !isEditable(item)) {
     return item;
   } else {
     T mutable = originalToModified.get(item);
     if (mutable == null) {
       mutable = itemEditor.clone(item, false);
       modifiedToOriginal.put(mutable, item);
       originalToModified.put(item, mutable);
       silentlyReplaceItem(item, mutable, index);
     }
     return mutable;
   }
 }
    @Override
    public void add(int hash, int cost, @Nullable PsiFragment frag) {
      if (!isIndexedFragment(frag, cost, myProfile, myDuplocatorState)) {
        return;
      }

      if (myTracingData != null) myTracingData.record(hash, cost, frag);

      TIntArrayList list = myMap.get(hash);
      if (list == null) {
        myMap.put(hash, list = new TIntArrayList());
      }
      list.add(frag.getStartOffset());
      list.add(0);
    }
예제 #15
0
  private THashMap<Value, Object> mapCopy(final THashMap<Value, Object> map) {
    if (map == null) {
      return null;
    }
    final THashMap<Value, Object> cloned = map.clone();
    cloned.forEachEntry(
        new TObjectObjectProcedure<Value, Object>() {
          @Override
          public boolean execute(Value key, Object val) {
            if (val instanceof ChangeBufferingList) {
              cloned.put(key, ((ChangeBufferingList) val).clone());
            }
            return true;
          }
        });

    return cloned;
  }
  private void setupEnvironment(final Map<String, String> environment) {
    environment.clear();

    if (myPassParentEnvironment) {
      environment.putAll(EnvironmentUtil.getEnvironmentMap());
    }

    if (!myEnvParams.isEmpty()) {
      if (SystemInfo.isWindows) {
        THashMap<String, String> envVars =
            new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
        envVars.putAll(environment);
        envVars.putAll(myEnvParams);
        environment.clear();
        environment.putAll(envVars);
      } else {
        environment.putAll(myEnvParams);
      }
    }
  }
예제 #17
0
  @SuppressWarnings({"UnusedDeclaration"})
  @TestOnly
  private static Map<CharSequence, Definition> getDefinitions(
      LibrarySetItem library, THashMap<CharSequence, Definition> definitionMap) {
    Map<CharSequence, Definition> definitions = new HashMap<>();
    for (Entry<CharSequence, Definition> entry : definitionMap.entrySet()) {
      if (entry.getValue().getLibrary() == library) {
        definitions.put(entry.getKey(), entry.getValue());
      }
    }

    return definitions;
  }
예제 #18
0
  public void loadState(final Element element, final boolean mergeWithOriginalAndCompile) {
    final THashMap<String, LanguageInjectionSupport> supports =
        new THashMap<String, LanguageInjectionSupport>();
    for (LanguageInjectionSupport support :
        Extensions.getExtensions(LanguageInjectionSupport.EP_NAME)) {
      supports.put(support.getId(), support);
    }
    loadStateOld(
        element,
        supports.get(LanguageInjectionSupport.XML_SUPPORT_ID),
        supports.get(LanguageInjectionSupport.JAVA_SUPPORT_ID));
    for (Element child : (List<Element>) element.getChildren("injection")) {
      final String key = child.getAttributeValue("injector-id");
      final LanguageInjectionSupport support = supports.get(key);
      final BaseInjection injection =
          support == null ? new BaseInjection(key) : support.createInjection(child);
      injection.loadState(child);
      myInjections.get(key).add(injection);
    }
    setInstrumentationType(JDOMExternalizerUtil.readField(element, INSTRUMENTATION_TYPE_NAME));
    setLanguageAnnotation(JDOMExternalizerUtil.readField(element, LANGUAGE_ANNOTATION_NAME));
    setPatternAnnotation(JDOMExternalizerUtil.readField(element, PATTERN_ANNOTATION_NAME));
    setSubstAnnotation(JDOMExternalizerUtil.readField(element, SUBST_ANNOTATION_NAME));
    setResolveReferences(readBoolean(element, RESOLVE_REFERENCES, true));
    setUseDfaIfAvailable(readBoolean(element, USE_DFA_IF_AVAILABLE, false));
    setIncludeUncomputablesAsLiterals(
        readBoolean(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, false));

    if (mergeWithOriginalAndCompile) {
      mergeWithDefaultConfiguration();

      for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
        for (BaseInjection injection : getInjections(supportId)) {
          injection.initializePlaces(true);
        }
      }
    }
  }
  protected void setupEnvironment(@NotNull Map<String, String> environment) {
    environment.clear();

    if (myPassParentEnvironment) {
      environment.putAll(
          PlatformUtils.isAppCode()
              ? System.getenv() // Temporarily fix for OC-8606
              : EnvironmentUtil.getEnvironmentMap());
    }

    if (!myEnvParams.isEmpty()) {
      if (SystemInfo.isWindows) {
        THashMap<String, String> envVars =
            new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
        envVars.putAll(environment);
        envVars.putAll(myEnvParams);
        environment.clear();
        environment.putAll(envVars);
      } else {
        environment.putAll(myEnvParams);
      }
    }
  }
예제 #20
0
 private void fixUnresolvedClassReferences() {
   openClassDescriptorToQualifiedLabel.forEachEntry(
       new TObjectObjectProcedure<ClassDescriptor, JsNameRef>() {
         @Override
         public boolean execute(ClassDescriptor descriptor, JsNameRef ref) {
           if (ref.getName() == null) {
             // from library
             ref.resolve(context().getNameForDescriptor(descriptor));
             ref.setQualifier(context().getQualifierForDescriptor(descriptor));
           }
           return true;
         }
       });
 }
예제 #21
0
 @Override
 public void readFields(DataInput in) throws IOException {
   clear();
   final int termCount = WritableUtils.readVInt(in);
   for (int i = 0; i < termCount; i++) {
     final String term = Text.readString(in);
     final int freq = WritableUtils.readVInt(in);
     final int bf = WritableUtils.readVInt(in);
     insert(freq, term);
     if (bf == 0) continue;
     final int[] blocks = new int[bf];
     blocks[0] = WritableUtils.readVInt(in) - 1;
     for (int j = 1; j < bf; j++) blocks[j] = WritableUtils.readVInt(in) - blocks[j - 1];
     term_blocks.put(term, new TIntHashSet(blocks));
   }
 }
  private static boolean parseDefault(PerlBuilder b, int l) {
    PerlBuilder.Marker m = b.mark();

    IElementType tokenType = b.getTokenType();
    if (MOOSE_TOKEN_SET.contains(tokenType)) {
      b.advanceLexer();
      if (PerlParserImpl.expr(b, l, -1)) {
        PerlParserUtil.parseStatementModifier(b, l);
        m.done(RESERVED_TO_STATEMENT_MAP.get(tokenType));
        return true;
      }
    }

    m.rollbackTo();
    return false;
  }
 private void mergeVisibility(
     final THashMap<AbstractBuildingStruct, LayerVisibility> transformed,
     final TShortObjectHashMap<short[]> layerByGroups) {
   final ArrayList<AbstractBuildingStruct> buildings = new ArrayList<AbstractBuildingStruct>();
   this.m_havenWorld.foreachBuildings(
       new TObjectProcedure<AbstractBuildingStruct>() {
         @Override
         public boolean execute(final AbstractBuildingStruct building) {
           buildings.add(building);
           return true;
         }
       });
   for (final AbstractBuildingStruct b1 : buildings) {
     for (final AbstractBuildingStruct b2 : buildings) {
       if (b1 == b2) {
         continue;
       }
       final LayerVisibility visibility1 = transformed.get(b1);
       final LayerVisibility visibility2 = transformed.get(b2);
       LayerVisibility.merge(visibility1, visibility2, layerByGroups);
     }
   }
 }
 @Override
 public void putAll(Map<? extends String, ? extends String> map) {
   if (map != null) {
     super.putAll(map);
   }
 }
예제 #25
0
 /**
  * return blocks
  *
  * @param term
  * @return int[]
  */
 public int[] getBlocks(String term) {
   int[] rtr = term_blocks.get(term).toArray();
   if (rtr == null) return new int[0];
   Arrays.sort(rtr);
   return rtr;
 }
예제 #26
0
 @Override
 public void clear() {
   super.clear();
   blockCount = 0;
   term_blocks.clear();
 }
 public void process(@NotNull TObjectObjectProcedure<T, T> procedure) {
   modifiedToOriginal.forEachEntry(procedure);
 }
 public boolean hasModifiedItems() {
   return !modifiedToOriginal.isEmpty();
 }
 public boolean isMutable(@NotNull T item) {
   return modifiedToOriginal.containsKey(item) || !originalItems.contains(item);
 }
 public void remove(@NotNull T item) {
   T original = modifiedToOriginal.remove(item);
   if (original != null) {
     originalToModified.remove(original);
   }
 }