Beispiel #1
0
 public int enter(DeclarationDescriptor descriptor, Type type) {
   int index = myMaxIndex;
   myVarIndex.put(descriptor, index);
   myMaxIndex += type.getSize();
   myVarSizes.put(descriptor, type.getSize());
   return index;
 }
  @SuppressWarnings({"HardCodedStringLiteral"})
  public void dumpStatistics() {
    System.out.println("Statistics:");
    final TObjectIntHashMap<Object> map = new TObjectIntHashMap<Object>();

    final PsiElementVisitor psiRecursiveElementVisitor =
        new XmlRecursiveElementVisitor() {
          @NonNls private static final String TOKENS_KEY = "Tokens";
          @NonNls private static final String ELEMENTS_KEY = "Elements";

          @Override
          public void visitXmlToken(XmlToken token) {
            inc(TOKENS_KEY);
          }

          @Override
          public void visitElement(PsiElement element) {
            inc(ELEMENTS_KEY);
            super.visitElement(element);
          }

          private void inc(final String key) {
            map.put(key, map.get(key) + 1);
          }
        };

    accept(psiRecursiveElementVisitor);

    final Object[] keys = map.keys();
    for (final Object key : keys) {
      System.out.println(key + ": " + map.get(key));
    }
  }
 private static <E extends ArrangementEntry> void sortByName(@NotNull List<E> entries) {
   if (entries.size() < 2) {
     return;
   }
   final TObjectIntHashMap<E> weights = new TObjectIntHashMap<E>();
   int i = 0;
   for (E e : entries) {
     weights.put(e, ++i);
   }
   ContainerUtil.sort(
       entries,
       new Comparator<E>() {
         @Override
         public int compare(E e1, E e2) {
           String name1 =
               e1 instanceof NameAwareArrangementEntry
                   ? ((NameAwareArrangementEntry) e1).getName()
                   : null;
           String name2 =
               e2 instanceof NameAwareArrangementEntry
                   ? ((NameAwareArrangementEntry) e2).getName()
                   : null;
           if (name1 != null && name2 != null) {
             return name1.compareTo(name2);
           } else if (name1 == null && name2 == null) {
             return weights.get(e1) - weights.get(e2);
           } else if (name2 == null) {
             return -1;
           } else {
             return 1;
           }
         }
       });
 }
 private TIntArrayList getParametersToRemove() {
   TIntArrayList list = new TIntArrayList();
   for (Object o : toRemoveCBs.keys()) {
     if (((JCheckBox) o).isSelected()) {
       list.add(toRemoveCBs.get((JCheckBox) o));
     }
   }
   return list;
 }
 @NotNull
 private static OrderMap fromList(@NotNull List<HighlightSeverity> orderList) {
   TObjectIntHashMap<HighlightSeverity> map = new TObjectIntHashMap<HighlightSeverity>();
   for (int i = 0; i < orderList.size(); i++) {
     HighlightSeverity severity = orderList.get(i);
     map.put(severity, i);
   }
   return new OrderMap(map);
 }
Beispiel #6
0
 public int leave(DeclarationDescriptor descriptor) {
   int size = myVarSizes.get(descriptor);
   myMaxIndex -= size;
   myVarSizes.remove(descriptor);
   int oldIndex = myVarIndex.remove(descriptor);
   if (oldIndex != myMaxIndex) {
     throw new IllegalStateException("Descriptor can be left only if it is last: " + descriptor);
   }
   return oldIndex;
 }
    private static int getAttributeId(String attId) throws IOException {
      if (myAttributeIds.containsKey(attId)) {
        return myAttributeIds.get(attId);
      }

      int id = myNames.enumerate(attId);
      myAttributeIds.put(attId, id);

      return id;
    }
 private OrderMap(@NotNull TObjectIntHashMap<HighlightSeverity> map) {
   super(map.size());
   map.forEachEntry(
       new TObjectIntProcedure<HighlightSeverity>() {
         @Override
         public boolean execute(HighlightSeverity key, int value) {
           OrderMap.super.put(key, value);
           return true;
         }
       });
   trimToSize();
 }
 private static TObjectIntHashMap<String> buildNamesIndex(Instruction[] flow) {
   TObjectIntHashMap<String> namesIndex = new TObjectIntHashMap<String>();
   int idx = 0;
   for (Instruction instruction : flow) {
     if (instruction instanceof ReadWriteVariableInstruction) {
       String name = ((ReadWriteVariableInstruction) instruction).getVariableName();
       if (!namesIndex.contains(name)) {
         namesIndex.put(name, idx++);
       }
     }
   }
   return namesIndex;
 }
 @Nullable
 private PsiElement findAnchor(String name) {
   final int myPriority = PRIORITY.get(name);
   final PsiElement[] modifiers = getModifiers();
   PsiElement anchor = null;
   for (int i = modifiers.length - 1; i >= 0; i--) {
     PsiElement modifier = modifiers[i];
     if (PRIORITY.get(modifier.getText()) <= myPriority) {
       anchor = modifier;
       break;
     }
   }
   return anchor;
 }
    @Override
    public void dispose() {
      synchronized (ourInstances) {
        ourInstances.remove(myParent);

        for (Object o : myCounts.keys()) {
          VirtualFilePointerImpl pointer = (VirtualFilePointerImpl) o;
          int disposeCount = myCounts.get(pointer);
          int after = pointer.myNode.incrementUsageCount(-disposeCount + 1);
          LOG.assertTrue(after > 0, after);
          pointer.dispose();
        }
      }
    }
 /**
  * Reads events from <tt>eventStream</tt> into a linked list. The predicates associated with each
  * event are counted and any which occur at least <tt>cutoff</tt> times are added to the
  * <tt>predicatesInOut</tt> map along with a unique integer index.
  *
  * @param eventStream an <code>EventStream</code> value
  * @param eventStore a writer to which the events are written to for later processing.
  * @param predicatesInOut a <code>TObjectIntHashMap</code> value
  * @param cutoff an <code>int</code> value
  */
 private int computeEventCounts(
     EventStream eventStream, Writer eventStore, TObjectIntHashMap predicatesInOut, int cutoff)
     throws IOException {
   TObjectIntHashMap counter = new TObjectIntHashMap();
   int predicateIndex = 0;
   int eventCount = 0;
   while (eventStream.hasNext()) {
     Event ev = eventStream.nextEvent();
     eventCount++;
     eventStore.write(FileEventStream.toLine(ev));
     String[] ec = ev.getContext();
     for (int j = 0; j < ec.length; j++) {
       if (!predicatesInOut.containsKey(ec[j])) {
         if (counter.increment(ec[j])) {
         } else {
           counter.put(ec[j], 1);
         }
         if (counter.get(ec[j]) >= cutoff) {
           predicatesInOut.put(ec[j], predicateIndex++);
           counter.remove(ec[j]);
         }
       }
     }
   }
   predicatesInOut.trimToSize();
   eventStore.close();
   return eventCount;
 }
  public int storeSafe(Object obj) {
    if (safeClone.isSafeToReuse(obj)) {
      int description = safeToReuse.get(obj);

      if (description == 0) {
        safeToReuse.put(obj, safeToReuse.size() + 1);
        description = safeToReuse.size();
        reuse.add(obj);
      }
      return description;
    } else {
      return 0;
    }
  }
  public static TObjectIntHashMap<GrParameter> findParametersToRemove(
      IntroduceParameterInfo helper) {
    final TObjectIntHashMap<GrParameter> result = new TObjectIntHashMap<GrParameter>();

    final TextRange range = ExtractUtil.getRangeOfRefactoring(helper);

    GrParameter[] parameters = helper.getToReplaceIn().getParameters();
    for (int i = 0; i < parameters.length; i++) {
      GrParameter parameter = parameters[i];
      if (shouldRemove(parameter, range.getStartOffset(), range.getEndOffset())) {
        result.put(parameter, i);
      }
    }
    return result;
  }
  public static boolean isNumericType(@Nullable PsiType type) {
    if (type instanceof PsiClassType) {
      return TYPE_TO_RANK.contains(type.getCanonicalText());
    }

    return type instanceof PsiPrimitiveType && TypeConversionUtil.isNumericType(type);
  }
 public int findIdInCacheWrite(final Object obj, boolean immutable) {
   if (immutable) {
     return findProperImmutableCache(obj.getClass()).get(obj);
   } else {
     return objectsCacheOnWrite.get(obj);
   }
 }
 public int putObjectInCacheWrite(final Object obj, boolean isImmutable) {
   objectsCacheOnWrite.put(obj, ++objectIdOnCache);
   if (isImmutable) {
     findProperImmutableCache(obj.getClass()).put(obj, objectIdOnCache);
   }
   return objectIdOnCache;
 }
 @Test
 public void testTermCodesPut() {
   TermCodes.reset();
   final int termsLength = terms.length;
   TObjectIntHashMap<String> check = new TObjectIntHashMap<String>();
   for (int i = 0; i < termsLength; i++) {
     TermCodes.setTermCode(terms[i], i);
     check.put(terms[i], i);
   }
   for (int j = 0; j < 1000000; j++) {
     for (int i = 0; i < termsLength; i++) {
       int code = TermCodes.getCode(terms[i]);
       assertEquals(check.get(terms[i]), code);
     }
   }
 }
  public boolean hasExplicitModifier(@NotNull @NonNls String name) {
    final GrModifierListStub stub = getStub();
    if (stub != null) {
      final int flag = NAME_TO_MODIFIER_FLAG_MAP.get(name);
      return (stub.getModifiersFlags() & flag) != 0;
    }

    if (name.equals(GrModifier.PUBLIC)) return findChildByType(GroovyElementTypes.kPUBLIC) != null;
    if (name.equals(GrModifier.ABSTRACT))
      return findChildByType(GroovyElementTypes.kABSTRACT) != null;
    if (name.equals(GrModifier.NATIVE)) return findChildByType(GroovyElementTypes.kNATIVE) != null;
    if (name.equals(GrModifier.PRIVATE))
      return findChildByType(GroovyElementTypes.kPRIVATE) != null;
    if (name.equals(GrModifier.PROTECTED))
      return findChildByType(GroovyElementTypes.kPROTECTED) != null;
    if (name.equals(GrModifier.SYNCHRONIZED))
      return findChildByType(GroovyElementTypes.kSYNCHRONIZED) != null;
    if (name.equals(GrModifier.STRICTFP))
      return findChildByType(GroovyElementTypes.kSTRICTFP) != null;
    if (name.equals(GrModifier.STATIC)) return findChildByType(GroovyElementTypes.kSTATIC) != null;
    if (name.equals(GrModifier.FINAL)) return findChildByType(GroovyElementTypes.kFINAL) != null;
    if (name.equals(GrModifier.TRANSIENT))
      return findChildByType(GroovyElementTypes.kTRANSIENT) != null;
    if (name.equals(GrModifier.NATIVE)) return findChildByType(GroovyElementTypes.kNATIVE) != null;
    if (name.equals(GrModifier.DEF)) return findChildByType(GroovyTokenTypes.kDEF) != null;
    return name.equals(GrModifier.VOLATILE)
        && findChildByType(GroovyElementTypes.kVOLATILE) != null;
  }
 public void reset() {
   if (safeToReuse != null) {
     safeToReuse.clear();
   }
   objectsCacheOnWrite.clear();
   objectsCacheOnRead.clear();
   immutableCache.clear();
   objectIdOnCache = 0;
 }
 @Override
 public int compare(Object o1, Object o2) {
   if (WEIGHTS.containsKey(o1) && WEIGHTS.containsKey(o2)) {
     return WEIGHTS.get(o1) - WEIGHTS.get(o2);
   } else if (WEIGHTS.containsKey(o1) && !WEIGHTS.containsKey(o2)) {
     return -1;
   } else if (!WEIGHTS.containsKey(o1) && WEIGHTS.containsKey(o2)) {
     return 1;
   } else {
     return o1.hashCode() - o2.hashCode();
   }
 }
  @Test
  public void testTermCodes() {
    TermCodes.reset();
    TObjectIntHashMap<String> check = new TObjectIntHashMap<String>();
    final int termsLength = terms.length;
    for (int i = 0; i < termsLength; i++) {
      int id = TermCodes.getCode(terms[i]);
      check.put(terms[i], id);
    }
    int code;
    for (int j = 0; j < 1000000; j++) {
      for (int i = 0; i < termsLength; i++) {
        code = TermCodes.getCode(terms[i]);
        assertEquals(check.get(terms[i]), code);
      }
    }
    // TODO: get a new term, then check that the new id is unique

  }
 static {
   TYPE_TO_RANK.put(JAVA_LANG_BYTE, 1);
   TYPE_TO_RANK.put(JAVA_LANG_SHORT, 2);
   TYPE_TO_RANK.put(JAVA_LANG_CHARACTER, 2);
   TYPE_TO_RANK.put(JAVA_LANG_INTEGER, 3);
   TYPE_TO_RANK.put(JAVA_LANG_LONG, 4);
   TYPE_TO_RANK.put(JAVA_MATH_BIG_INTEGER, 5);
   TYPE_TO_RANK.put(JAVA_MATH_BIG_DECIMAL, 6);
   TYPE_TO_RANK.put(JAVA_LANG_FLOAT, 7);
   TYPE_TO_RANK.put(JAVA_LANG_DOUBLE, 8);
   TYPE_TO_RANK.put(JAVA_LANG_NUMBER, 9);
 }
 private void writeVertices() throws IOException {
   /*
    * Start indexing with 1 since 0 is returned if no mapping is found.
    */
   vertexIdx = 1;
   for (Vertex v : graph.getVertices()) {
     vertexTmpIds.put(v, vertexIdx);
     writeStartTag(GraphML.NODE_TAG, getVertexAttributes(v), true);
     vertexIdx++;
   }
 }
Beispiel #25
0
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();

    if (myVarIndex.size() != myVarSizes.size()) {
      return "inconsistent";
    }

    List<Trinity<DeclarationDescriptor, Integer, Integer>> descriptors = Lists.newArrayList();

    for (Object descriptor0 : myVarIndex.keys()) {
      DeclarationDescriptor descriptor = (DeclarationDescriptor) descriptor0;
      int varIndex = myVarIndex.get(descriptor);
      int varSize = myVarSizes.get(descriptor);
      descriptors.add(Trinity.create(descriptor, varIndex, varSize));
    }

    Collections.sort(
        descriptors,
        new Comparator<Trinity<DeclarationDescriptor, Integer, Integer>>() {
          @Override
          public int compare(
              Trinity<DeclarationDescriptor, Integer, Integer> left,
              Trinity<DeclarationDescriptor, Integer, Integer> right) {
            return left.second - right.second;
          }
        });

    sb.append("size=").append(myMaxIndex);

    boolean first = true;
    for (Trinity<DeclarationDescriptor, Integer, Integer> t : descriptors) {
      if (!first) {
        sb.append(", ");
      }
      first = false;
      sb.append(t.first).append(",i=").append(t.second).append(",s=").append(t.third);
    }

    return sb.toString();
  }
  public StringEditFeatureVectorSequence(
      FeatureVector[] featureVectors, String s1, String s2, char delimiter, HashMap lexic) {
    super(featureVectors);
    this.delim = delimiter;

    this.lexicon = new TObjectIntHashMap();
    if (lexic != null) {
      Set keys = lexic.keySet();
      Iterator iter = keys.iterator();
      while (iter.hasNext()) this.lexicon.put((String) iter.next(), 1);
    }

    this.string1 = s1;
    this.string2 = s2;
    this.string1Length = s1.length() + 2;
    this.string2Length = s2.length() + 2;
    string1Blocks = string1.split("" + delim);
    string2Blocks = string2.split("" + delim);
    string1Present = new TObjectIntHashMap();
    string2Present = new TObjectIntHashMap();
    block1Indices = new int[string1Length];
    if (string1Blocks.length > 0) {
      int whichBlock = 0;
      block1Indices[0] = whichBlock++;
      for (int i = 0; i < string1Blocks.length; i++) string1Present.put(string1Blocks[i], 1);
      for (int i = 1; i < string1Length - 1; i++)
        block1Indices[i] = ((string1.charAt(i - 1) == delim) ? whichBlock++ : -1);
      block1Indices[string1Length - 1] = -1;
    }
    block2Indices = new int[string2Length];
    if (string2Blocks.length > 0) {
      int whichBlock = 0;
      block2Indices[0] = whichBlock++;
      for (int i = 0; i < string2Blocks.length; i++) string2Present.put(string2Blocks[i], 1);
      for (int i = 1; i < string2Length - 1; i++)
        block2Indices[i] = ((string2.charAt(i - 1) == delim) ? whichBlock++ : -1);
      block2Indices[string2Length - 1] = -1;
    }
  }
 /**
  * Returns a list of edge attributes stored in String-String-tuples. The returned list contains
  * two entries:
  *
  * <ul>
  *   <li>{@link GraphML#SOURCE_ATTR} - <tt>vertexIdx</tt>
  *   <li>{@link GraphML#TARGET_ATTR} - <tt>vertexIdx</tt>
  * </ul>
  *
  * @param e the edge the attributes are to be returned.
  * @return a list of edge attributes.
  */
 protected List<Tuple<String, String>> getEdgeAttributes(Edge e) {
   List<Tuple<String, String>> attrs = new LinkedList<Tuple<String, String>>();
   Vertex v1 = e.getVertices().getFirst();
   Vertex v2 = e.getVertices().getSecond();
   int idx1 = vertexTmpIds.get(v1);
   int idx2 = vertexTmpIds.get(v2);
   if (idx1 > 0 && idx2 > 0) {
     attrs.add(createTuple(GraphML.SOURCE_ATTR, idx1));
     attrs.add(createTuple(GraphML.TARGET_ATTR, idx2));
   } else {
     throw new IllegalArgumentException("Orphaned edges are not allowed!");
   }
   return attrs;
 }
  public GrIntroduceParameterDialog(IntroduceParameterInfo info) {
    super(info.getProject(), true);
    myInfo = info;
    myProject = info.getProject();
    myCanIntroduceSimpleParameter =
        GroovyIntroduceParameterUtil.findExpr(myInfo) != null
            || GroovyIntroduceParameterUtil.findVar(myInfo) != null
            || findStringPart() != null;

    TObjectIntHashMap<GrParameter> parametersToRemove =
        GroovyIntroduceParameterUtil.findParametersToRemove(info);
    toRemoveCBs = new TObjectIntHashMap<JCheckBox>(parametersToRemove.size());
    for (Object p : parametersToRemove.keys()) {
      JCheckBox cb =
          new JCheckBox(
              GroovyRefactoringBundle.message(
                  "remove.parameter.0.no.longer.used", ((GrParameter) p).getName()));
      toRemoveCBs.put(cb, parametersToRemove.get((GrParameter) p));
      cb.setSelected(true);
    }

    init();
  }
  private void createCheckBoxes(JPanel panel) {
    myDeclareFinalCheckBox = new JCheckBox(UIUtil.replaceMnemonicAmpersand("Declare &final"));
    myDeclareFinalCheckBox.setFocusable(false);
    panel.add(myDeclareFinalCheckBox);

    myDelegateViaOverloadingMethodCheckBox =
        new JCheckBox(UIUtil.replaceMnemonicAmpersand("De&legate via overloading method"));
    myDelegateViaOverloadingMethodCheckBox.setFocusable(false);
    panel.add(myDelegateViaOverloadingMethodCheckBox);

    for (Object o : toRemoveCBs.keys()) {
      final JCheckBox cb = (JCheckBox) o;
      cb.setFocusable(false);
      panel.add(cb);
    }
  }
 @Override
 public void dispose() {
   ourInstances.remove(myParent);
   synchronized (this) {
     myCounts.forEachEntry(
         new TObjectIntProcedure<VirtualFilePointerImpl>() {
           @Override
           public boolean execute(VirtualFilePointerImpl pointer, int disposeCount) {
             int after = pointer.myNode.incrementUsageCount(-disposeCount + 1);
             LOG.assertTrue(after > 0, after);
             pointer.dispose();
             return true;
           }
         });
   }
 }