private static boolean checkDependants(
      final IdeaPluginDescriptor pluginDescriptor,
      final Function<PluginId, IdeaPluginDescriptor> pluginId2Descriptor,
      final Condition<PluginId> check,
      final Set<PluginId> processed) {
    processed.add(pluginDescriptor.getPluginId());
    final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds();
    final Set<PluginId> optionalDependencies =
        new HashSet<PluginId>(Arrays.asList(pluginDescriptor.getOptionalDependentPluginIds()));
    for (final PluginId dependentPluginId : dependentPluginIds) {
      if (processed.contains(dependentPluginId)) continue;

      // TODO[yole] should this condition be a parameter?
      if (isModuleDependency(dependentPluginId)
          && (ourAvailableModules.isEmpty()
              || ourAvailableModules.contains(dependentPluginId.getIdString()))) {
        continue;
      }
      if (!optionalDependencies.contains(dependentPluginId)) {
        if (!check.value(dependentPluginId)) {
          return false;
        }
        final IdeaPluginDescriptor dependantPluginDescriptor =
            pluginId2Descriptor.fun(dependentPluginId);
        if (dependantPluginDescriptor != null
            && !checkDependants(dependantPluginDescriptor, pluginId2Descriptor, check, processed)) {
          return false;
        }
      }
    }
    return true;
  }
Esempio n. 2
0
  /**
   * type check this rule
   *
   * @throws TypeException if the ruele contains type errors
   */
  public void typeCheck() throws TypeException {
    String helperName = ruleScript.getTargetHelper();

    // ensure that we have a valid helper class
    if (helperName != null) {
      try {
        helperClass = loader.loadClass(helperName);
      } catch (ClassNotFoundException e) {
        throw new TypeException(
            "Rule.typecheck : unknown helper class " + helperName + " for rule " + getName());
      }
    } else {
      helperClass = Helper.class;
    }
    if (triggerExceptions != null) {
      // ensure that the type group includes the exception types
      typeGroup.addExceptionTypes(triggerExceptions);
    }

    // try to resolve all types in the type group to classes

    typeGroup.resolveTypes();

    // use the descriptor to derive the method argument types and type any bindings for them
    // that are located in the bindings list

    installParameters((triggerAccess & Opcodes.ACC_STATIC) != 0, triggerClass);

    event.typeCheck(Type.VOID);
    condition.typeCheck(Type.Z);
    action.typeCheck(Type.VOID);
  }
Esempio n. 3
0
  private Rule(RuleScript ruleScript, ClassLoader loader, HelperManager helperManager)
      throws ParseException, TypeException, CompileException {
    ParseNode ruleTree;

    this.ruleScript = ruleScript;
    this.helperClass = null;
    this.loader = loader;

    typeGroup = new TypeGroup(loader);
    bindings = new Bindings();
    checked = false;
    triggerClass = null;
    triggerMethod = null;
    triggerDescriptor = null;
    triggerAccess = 0;
    returnType = null;
    accessibleFields = null;
    accessibleMethods = null;
    // this is only set when the rule is created via a real installed transformer
    this.helperManager = helperManager;
    ECAGrammarParser parser = null;
    try {
      String file = getFile();
      ECATokenLexer lexer = new ECATokenLexer(new StringReader(ruleScript.getRuleText()));
      lexer.setStartLine(getLine());
      lexer.setFile(file);
      parser = new ECAGrammarParser(lexer);
      parser.setFile(file);
      Symbol parse = (debugParse ? parser.debug_parse() : parser.parse());
      if (parser.getErrorCount() != 0) {
        String message = "rule " + ruleScript.getName();
        message += parser.getErrors();
        throw new ParseException(message);
      }
      ruleTree = (ParseNode) parse.value;
    } catch (ParseException pe) {
      throw pe;
    } catch (Throwable th) {
      String message = "rule " + ruleScript.getName();
      if (parser != null && parser.getErrorCount() != 0) {
        message += parser.getErrors();
      }
      message += "\n" + th.getMessage();
      throw new ParseException(message);
    }

    ParseNode eventTree = (ParseNode) ruleTree.getChild(0);
    ParseNode conditionTree = (ParseNode) ruleTree.getChild(1);
    ParseNode actionTree = (ParseNode) ruleTree.getChild(2);

    event = Event.create(this, eventTree);
    condition = Condition.create(this, conditionTree);
    action = Action.create(this, actionTree);
    key = null;
  }
Esempio n. 4
0
  /**
   * generate a string representation of the rule
   *
   * @return a string representation of the rule
   */
  public String toString() {
    StringWriter stringWriter = new StringWriter();
    stringWriter.write("RULE ");
    stringWriter.write(getName());
    stringWriter.write("\n");
    if (isInterface()) {
      stringWriter.write("INTERFACE ");
    } else {
      stringWriter.write("CLASS ");
    }
    if (isOverride()) {
      stringWriter.write("^");
    }
    stringWriter.write(getTargetClass());
    stringWriter.write('\n');
    stringWriter.write("METHOD ");
    stringWriter.write(getTargetMethod());
    stringWriter.write('\n');
    stringWriter.write(getTargetLocation().toString());
    stringWriter.write('\n');
    if (event != null) {
      event.writeTo(stringWriter);
    } else {
      stringWriter.write("BIND NOTHING\n");
    }
    if (condition != null) {
      condition.writeTo(stringWriter);
    } else {
      stringWriter.write("COND   TRUE\n");
    }
    if (action != null) {
      action.writeTo(stringWriter);
    } else {
      stringWriter.write("DO   NOTHING\n");
    }

    return stringWriter.toString();
  }
Esempio n. 5
0
 public void setCondition(String conditionSpec) throws ParseException, TypeException {
   if (event != null & condition == null) {
     condition = Condition.create(this, conditionSpec);
   }
 }
Esempio n. 6
0
 private void parseMobFile(String strStore, RandomAccessFile rafFile) {
   try {
     if (strStore.equalsIgnoreCase("skill")) {
       strStore = rafFile.readLine();
       int value = Byte.parseByte(rafFile.readLine());
       addToSkill(strStore, value);
       engGame.log.printMessage(Log.DEBUG, strStore + "=" + value);
       return;
     }
     if (strStore.equalsIgnoreCase("condition")) {
       Condition cndStore = engGame.getCondition(rafFile.readLine());
       cndStore.intTicksPast = Integer.parseInt(rafFile.readLine());
       cndStore.intDuration = Integer.parseInt(rafFile.readLine());
       addCondition(cndStore);
       engGame.log.printMessage(Log.DEBUG, "condition \"" + cndStore.strName + "\"");
       return;
     }
     if (strStore.equalsIgnoreCase("giveitem")) {
       String strItem = rafFile.readLine();
       double dblChance = Double.valueOf(rafFile.readLine()).doubleValue();
       vctGiveItems.addElement(new GiveItem(strItem, dblChance));
       engGame.log.printMessage(
           Log.DEBUG,
           strName + " gives a \"" + strItem + "\" " + (100 * dblChance) + "% of the time.");
       return;
     }
     if (strStore.equalsIgnoreCase("item")) {
       Item itmStore = engGame.getItem(rafFile.readLine());
       if (itmStore != null) {
         itmStore.lngDurability = Long.parseLong(rafFile.readLine());
         itmStore.intUses = Integer.parseInt(rafFile.readLine());
         vctItems.addElement(itmStore);
       }
       return;
     }
     if (strStore.equalsIgnoreCase("clan")) {
       strClan = rafFile.readLine();
       return;
     }
     if (strStore.equalsIgnoreCase("race")) {
       strRace = rafFile.readLine();
       return;
     }
     if (strStore.equalsIgnoreCase("title")) {
       strTitle = rafFile.readLine();
       return;
     }
     if (strStore.equalsIgnoreCase("description")) {
       strDescription = rafFile.readLine();
       return;
     }
     if (strStore.equalsIgnoreCase("x")) {
       intLocX = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("y")) {
       intLocY = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("maxhp")) {
       maxhp = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("maxmp")) {
       maxmp = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("stre")) {
       stre = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("inte")) {
       inte = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("dext")) {
       dext = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equals("cons")) {
       cons = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("wisd")) {
       wisd = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("image")) {
       intImage = Integer.parseInt(rafFile.readLine());
       return;
     }
     if (strStore.equalsIgnoreCase("bravery")) {
       dblBravery = Double.valueOf(rafFile.readLine()).doubleValue();
       return;
     }
     if (strStore.equalsIgnoreCase("grouprelation")) {
       dblGroupRelation = Double.valueOf(rafFile.readLine()).doubleValue();
       return;
     }
     if (strStore.equalsIgnoreCase("wield")) {
       equWorn.wield = engGame.getItem(rafFile.readLine());
       if (equWorn.wield != null) {
         equWorn.wield.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.wield.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.wield);
       return;
     }
     if (strStore.equalsIgnoreCase("arms")) {
       equWorn.arms = engGame.getItem(rafFile.readLine());
       if (equWorn.arms != null) {
         equWorn.arms.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.arms.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.arms);
       return;
     }
     if (strStore.equalsIgnoreCase("legs")) {
       equWorn.legs = engGame.getItem(rafFile.readLine());
       if (equWorn.legs != null) {
         equWorn.legs.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.legs.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.legs);
       return;
     }
     if (strStore.equalsIgnoreCase("torso")) {
       equWorn.torso = engGame.getItem(rafFile.readLine());
       if (equWorn.torso != null) {
         equWorn.torso.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.torso.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.torso);
       return;
     }
     if (strStore.equalsIgnoreCase("waist")) {
       equWorn.waist = engGame.getItem(rafFile.readLine());
       if (equWorn.waist != null) {
         equWorn.waist.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.waist.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.waist);
       return;
     }
     if (strStore.equalsIgnoreCase("neck")) {
       equWorn.neck = engGame.getItem(rafFile.readLine());
       if (equWorn.neck != null) {
         equWorn.neck.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.neck.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.neck);
       return;
     }
     if (strStore.equalsIgnoreCase("skull")) {
       equWorn.skull = engGame.getItem(rafFile.readLine());
       if (equWorn.skull != null) {
         equWorn.skull.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.skull.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.skull);
       return;
     }
     if (strStore.equalsIgnoreCase("eyes")) {
       equWorn.eyes = engGame.getItem(rafFile.readLine());
       if (equWorn.eyes != null) {
         equWorn.eyes.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.eyes.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.eyes);
       return;
     }
     if (strStore.equalsIgnoreCase("hands")) {
       equWorn.hands = engGame.getItem(rafFile.readLine());
       if (equWorn.hands != null) {
         equWorn.hands.lngDurability = Long.parseLong(rafFile.readLine());
         equWorn.hands.intUses = Integer.parseInt(rafFile.readLine());
       }
       runWearScript(equWorn.hands);
       return;
     }
     if (strStore.equalsIgnoreCase("faction")) {
       String strFaction = rafFile.readLine();
       fctFaction = engGame.getFaction(strFaction);
       if (fctFaction != null) {
         engGame.log.printMessage(Log.DEBUG, "faction=\"" + fctFaction.strName + "\"");
       } else {
         engGame.log.printMessage(Log.DEBUG, "no faction found for \"" + strFaction + "\"");
       }
       return;
     }
     if (strStore.equalsIgnoreCase("onBattle")) {
       strOnBattle = rafFile.readLine();
       return;
     }
     if (strStore.equalsIgnoreCase("nofollow")) {
       noFollow = true;
       return;
     }
   } catch (Exception e) {
     engGame.log.printError(
         "parseMobFile():Parsing \"" + strStore + "\" from " + strName + "'s file", e);
   }
 }
  /**
   * Asynchronous sequence update operation. Will add given amount to the sequence value.
   *
   * @param l Increment amount.
   * @param updateCall Cache call that will update sequence reservation count in accordance with l.
   * @param updated If {@code true}, will return sequence value after update, otherwise will return
   *     sequence value prior to update.
   * @return Future indicating sequence value.
   * @throws GridException If update failed.
   */
  private GridFuture<Long> internalUpdateAsync(
      long l, @Nullable Callable<Long> updateCall, boolean updated) throws GridException {
    checkRemoved();

    A.ensure(l > 0, " Parameter mustn't be less then 1: " + l);

    lock.lock();

    try {
      // If reserved range isn't exhausted.
      if (locVal + l <= upBound) {
        long curVal = locVal;

        locVal += l;

        return new GridFinishedFuture<Long>(ctx.kernalContext(), updated ? locVal : curVal);
      }
    } finally {
      lock.unlock();
    }

    if (updateCall == null) updateCall = internalUpdate(l, updated);

    while (true) {
      if (updateGuard.compareAndSet(false, true)) {
        try {
          // This call must be outside lock.
          return ctx.closures().callLocalSafe(updateCall, true);
        } finally {
          lock.lock();

          try {
            updateGuard.set(false);

            cond.signalAll();
          } finally {
            lock.unlock();
          }
        }
      } else {
        lock.lock();

        try {
          while (locVal >= upBound && updateGuard.get()) {
            try {
              cond.await(500, MILLISECONDS);
            } catch (InterruptedException e) {
              throw new GridInterruptedException(e);
            }
          }

          checkRemoved();

          // If reserved range isn't exhausted.
          if (locVal + l <= upBound) {
            long curVal = locVal;

            locVal += l;

            return new GridFinishedFuture<Long>(ctx.kernalContext(), updated ? locVal : curVal);
          }
        } finally {
          lock.unlock();
        }
      }
    }
  }
  /**
   * Synchronous sequence update operation. Will add given amount to the sequence value.
   *
   * @param l Increment amount.
   * @param updateCall Cache call that will update sequence reservation count in accordance with l.
   * @param updated If {@code true}, will return sequence value after update, otherwise will return
   *     sequence value prior to update.
   * @return Sequence value.
   * @throws GridException If update failed.
   */
  private long internalUpdate(long l, @Nullable Callable<Long> updateCall, boolean updated)
      throws GridException {
    checkRemoved();

    assert l > 0;

    lock.lock();

    try {
      // If reserved range isn't exhausted.
      if (locVal + l <= upBound) {
        long curVal = locVal;

        locVal += l;

        return updated ? locVal : curVal;
      }
    } finally {
      lock.unlock();
    }

    if (updateCall == null) updateCall = internalUpdate(l, updated);

    while (true) {
      if (updateGuard.compareAndSet(false, true)) {
        try {
          // This call must be outside lock.
          return CU.outTx(updateCall, ctx);
        } finally {
          lock.lock();

          try {
            updateGuard.set(false);

            cond.signalAll();
          } finally {
            lock.unlock();
          }
        }
      } else {
        lock.lock();

        try {
          while (locVal >= upBound && updateGuard.get()) {
            try {
              cond.await(500, MILLISECONDS);
            } catch (InterruptedException e) {
              throw new GridInterruptedException(e);
            }
          }

          checkRemoved();

          // If reserved range isn't exhausted.
          if (locVal + l <= upBound) {
            long curVal = locVal;

            locVal += l;

            return updated ? locVal : curVal;
          }
        } finally {
          lock.unlock();
        }
      }
    }
  }