コード例 #1
0
 private void selectOnColonExpression(ModuleDeclaration parsedUnit, RubyColonExpression node) {
   BasicContext basicContext = new BasicContext(sourceModule, parsedUnit);
   ColonExpressionEvaluator evaluator =
       new ColonExpressionEvaluator(new ExpressionTypeGoal(basicContext, node));
   IGoal[] init = evaluator.init();
   if (init == null || init.length == 0) {
     // should never be here
     // System.err.println("Why did ColonExpressionEvaluator evaluated so
     // fast?");
   } else {
     IEvaluatedType leftType = inferencer.evaluateType((AbstractTypeGoal) init[0], -1);
     IGoal[] goals = evaluator.subGoalDone(init[0], leftType, GoalState.DONE);
     if (goals == null || goals.length == 0) { // good, we have
       // type-constant
       Object evaluatedType = evaluator.produceResult();
       if (evaluatedType instanceof RubyClassType) {
         RubyMixinClass mixinClass = mixinModel.createRubyClass((RubyClassType) evaluatedType);
         if (mixinClass != null)
           addArrayToCollection(mixinClass.getSourceTypes(), selectionElements);
       }
     } else {
       if (goals[0] instanceof NonTypeConstantTypeGoal) {
         processNonTypeConstant((NonTypeConstantTypeGoal) (goals[0]));
       }
     }
   }
 }
コード例 #2
0
 private IType[] getSourceTypesForClass(ModuleDeclaration parsedUnit, ASTNode statement) {
   ExpressionTypeGoal typeGoal =
       new ExpressionTypeGoal(new BasicContext(sourceModule, parsedUnit), statement);
   IEvaluatedType evaluatedType = this.inferencer.evaluateType(typeGoal, 5000);
   if (evaluatedType instanceof RubyClassType) {
     RubyMixinClass mixinClass = mixinModel.createRubyClass((RubyClassType) evaluatedType);
     if (mixinClass != null) return mixinClass.getSourceTypes();
   }
   return new IType[0];
 }
コード例 #3
0
 private void selectOnSuper(ModuleDeclaration parsedUnit, RubySuperExpression superExpr) {
   RubyClassType selfClass =
       RubyTypeInferencingUtils.determineSelfClass(
           mixinModel, sourceModule, parsedUnit, superExpr.sourceStart());
   MethodDeclaration enclosingMethod = ASTUtils.getEnclosingMethod(wayToNode, superExpr, false);
   if (enclosingMethod != null) {
     String name = enclosingMethod.getName();
     RubyMixinClass rubyClass = mixinModel.createRubyClass(selfClass);
     RubyMixinClass superclass = rubyClass.getSuperclass();
     RubyMixinMethod method = superclass.getMethod(name);
     if (method != null) {
       IMethod[] sourceMethods = method.getSourceMethods();
       addArrayToCollection(sourceMethods, selectionElements);
     }
   }
 }
コード例 #4
0
 private void selectOnConstant(ModuleDeclaration parsedUnit, ConstantReference node) {
   BasicContext basicContext = new BasicContext(sourceModule, parsedUnit);
   ConstantReferenceEvaluator evaluator =
       new ConstantReferenceEvaluator(new ExpressionTypeGoal(basicContext, node));
   IGoal[] init = evaluator.init();
   if (init == null || init.length == 0) {
     Object evaluatedType = evaluator.produceResult();
     if (evaluatedType instanceof RubyClassType) {
       RubyMixinClass mixinClass = mixinModel.createRubyClass((RubyClassType) evaluatedType);
       if (mixinClass != null)
         addArrayToCollection(mixinClass.getSourceTypes(), selectionElements);
     }
   } else if (init[0] instanceof NonTypeConstantTypeGoal) {
     // it'a non-type constant
     processNonTypeConstant((NonTypeConstantTypeGoal) init[0]);
   }
 }
コード例 #5
0
  @Override
  public IModelElement[] select(
      IModuleSource sourceUnit, int selectionSourceStart, int selectionSourceEnd) {
    sourceModule = (ISourceModule) sourceUnit.getModelElement();
    mixinModel = RubyMixinModel.getInstance(sourceModule.getScriptProject());
    String source = sourceUnit.getSourceContents();
    if (DEBUG) {
      System.out.print("SELECTION IN "); // $NON-NLS-1$
      System.out.print(sourceUnit.getFileName());
      System.out.print(" FROM "); // $NON-NLS-1$
      System.out.print(selectionSourceStart);
      System.out.print(" TO "); // $NON-NLS-1$
      System.out.println(selectionSourceEnd);
      System.out.println("SELECTION - Source :"); // $NON-NLS-1$
      System.out.println(source);
    }
    if (!checkSelection(source, selectionSourceStart, selectionSourceEnd)) {
      return new IModelElement[0];
    }
    actualSelectionEnd--; // inclusion fix
    if (DEBUG) {
      System.out.print("SELECTION - Checked : \""); // $NON-NLS-1$
      System.out.print(source.substring(actualSelectionStart, actualSelectionEnd + 1));
      System.out.println('"');
    }

    try {
      ModuleDeclaration parsedUnit = this.parser.parse(sourceUnit);

      if (parsedUnit != null) {
        if (DEBUG) {
          System.out.println("SELECTION - AST :"); // $NON-NLS-1$
          System.out.println(parsedUnit.toString());
        }

        ASTNode node =
            ASTUtils.findMinimalNode(parsedUnit, actualSelectionStart, actualSelectionEnd);

        if (node == null) return new IModelElement[0];

        this.wayToNode = ASTUtils.restoreWayToNode(parsedUnit, node);

        if (node instanceof TypeDeclaration) {
          selectionOnTypeDeclaration(parsedUnit, (TypeDeclaration) node);
        } else if (node instanceof MethodDeclaration) {
          selectionOnMethodDeclaration(parsedUnit, (MethodDeclaration) node);
        } else if (node instanceof ConstantReference || node instanceof RubyColonExpression) {
          selectTypes(parsedUnit, node);
        } else if (node instanceof VariableReference) {
          selectionOnVariable(parsedUnit, (VariableReference) node);
        } else if (node instanceof RubyMethodArgument) {
          selectOnMethodArgument(parsedUnit, (RubyMethodArgument) node);
        } else if (node instanceof RubySuperExpression) {
          selectOnSuper(parsedUnit, (RubySuperExpression) node);
        } else {
          CallExpression parentCall = this.getEnclosingCallNode(node);
          if (parentCall != null) {
            selectOnMethod(parsedUnit, parentCall);
          } else { // parentCall == null
          }
        }
      }
    } catch (IndexOutOfBoundsException e) { // work-around internal failure
      RubyPlugin.log(e);
    }

    return selectionElements.toArray(new IModelElement[selectionElements.size()]);
  }