Package org.eclipse.dltk.compiler.problem

Examples of org.eclipse.dltk.compiler.problem.IProblem


        listOfClosedProjects.add(each);
      }
    }
   
    if(!listOfClosedProjects.isEmpty()) {
      IProblem problem = problemFactory.createClosedProjectsProblem(listOfClosedProjects);
      problemReporter.reportProblem(problem);
    }
   
  }
View Full Code Here


        String name = p.getName();
        name = expand(name);
        parentTypeInDeclaration = name;
        // TODO remember name for new types and their features!
        if (finalTypes.contains(name)) {
          IProblem problem = problemFactory.createInheritenceFinalProblem(p);
          pr.reportProblem(problem);
        }
      }
      return true;
    }
    if (s instanceof RutaTypeDeclaration) {
      RutaTypeDeclaration newType = (RutaTypeDeclaration) s;
      String shortName = newType.getName();
      String longName = getLongNameOfNewType(shortName);

      if (namespaces.values().contains(longName)) {
        IProblem problem = problemFactory.createIdConflictsWithTypeProblem(newType);
        pr.reportProblem(problem);
        return false;
      }

      if (reportWarningOnShortNames && namespaces.containsKey(shortName)) {
        IProblem problem = problemFactory
                .createDuplicateShortName(newType, ProblemSeverity.WARNING);
        pr.reportProblem(problem);
        return false;
      }
      if (knowsVariable(shortName)) {
        IProblem problem = problemFactory.createIdConflictsWithVariableProblem(newType);
        pr.reportProblem(problem);
        return false;
      }
      List<RutaFeatureDeclaration> features = newType.getFeatures();
      Set<FeatureDescription> feats = new HashSet<FeatureDescription>();
      if (parentTypeInDeclaration != null) {
        Set<FeatureDescription> set = featureDescriptionMap.get(parentTypeInDeclaration);
        if (set != null) {
          feats.addAll(set);
        }
      }
      if (features != null) {
        for (RutaFeatureDeclaration each : features) {
          // TODO create correct feature description! Works right now because the type is not
          // checked
          String type = each.getType();
          type = translate(type);
          type = expand(type);
          FeatureDescription f = new FeatureDescription_impl(each.getName(), "", type);
          feats.add(f);
          if (type.equals("INT") || type.equals("STRING") || type.equals("DOUBLE")
                  || type.equals("FLOAT") || type.equals("BOOLEAN")) {
            continue;
          }
          if (!namespaces.keySet().contains(type) && !namespaces.values().contains(type)) {
            IProblem problem = problemFactory.createUnknownFeatureTypeProblem(each);
            pr.reportProblem(problem);
          }

        }
        featureDescriptionMap.put(longName, feats);
      }
      addDeclaredType(shortName);
      return false;
    }
    if (s instanceof RutaVariableDeclaration) {
      RutaVariableDeclaration newVar = (RutaVariableDeclaration) s;
      if (knowsVariable(newVar.getName())) {
        IProblem problem = problemFactory.createIdConflictsWithVariableProblem(newVar);
        pr.reportProblem(problem);
        return false;
      }
      if (namespaces.containsKey(newVar.getName())) {
        IProblem problem = problemFactory.createIdConflictsWithTypeProblem(newVar);
        pr.reportProblem(problem);
        return false;
      }
      knownLocalVariables.peek().put(newVar.getName(), newVar.getKind());
      return false;
    }
    if (s instanceof RutaRegExpRule) {
      RutaRegExpRule rule = (RutaRegExpRule) s;
      Map<Expression, Map<Expression, Expression>> faMap = rule.getFeats();
      Set<Entry<Expression, Map<Expression, Expression>>> typeEntrySet = faMap.entrySet();
      for (Entry<Expression, Map<Expression, Expression>> entry : typeEntrySet) {
        Expression struct = entry.getKey();
        String structure = "";
        if (struct != null) {
          structure = sourceModule.getSource().substring(struct.sourceStart(), struct.sourceEnd());
          structure = expand(structure);
        }
        Map<Expression, Expression> fmap = entry.getValue();
        Set<Expression> keySet = fmap.keySet();
        for (Expression fkey : keySet) {
          if (fkey instanceof RutaExpression && fkey.getKind() == RutaTypeConstants.RUTA_TYPE_S) {
            String feat = fkey.toString();
            feat = getFeatureName(fkey, feat);
            boolean findFeature = findFeature(structure, feat, -1);
            if (!findFeature) {
              IProblem problem = problemFactory.createUnknownFeatureProblem(fkey, structure);
              pr.reportProblem(problem);
            }
          }
        }
      }
View Full Code Here

      String actionName = sourceModule.getSource().substring(tma.getNameStart(), tma.getNameEnd());
      String[] keywords = RutaKeywordsManager.getKeywords(IRutaKeywords.ACTION);
      List<String> asList = Arrays.asList(keywords);
      if (!StringUtils.isEmpty(actionName) && !"-".equals(actionName)
              && !asList.contains(actionName) && !implicitString.equals(tma.getName())) {
        IProblem problem = problemFactory.createUnknownActionProblem(tma);
        pr.reportProblem(problem);
      }

      IRutaExtension extension = actionExtensions.get(actionName);
      if (extension != null) {
        extension.checkSyntax(tma, problemFactory, pr);
      }

      if (tma.getName().equals("GETFEATURE") || tma.getName().equals("SETFEATURE")) {
        List<?> childs = tma.getChilds();
        RutaStringExpression stringExpr = (RutaStringExpression) childs.get(0);
        String feat = stringExpr.toString();
        feat = getFeatureName(stringExpr, feat);
        boolean featureFound = findFeature(matchedType, feat, -1);
        if (!featureFound) {
          IProblem problem = problemFactory.createUnknownFeatureProblem(stringExpr, matchedType);
          pr.reportProblem(problem);
        }
      }

      if (tma.getKind() == RutaActionConstants.A_ASSIGN) {
        List<?> childs = tma.getChilds();
        try {
          RutaVariableReference ref = (RutaVariableReference) childs.get(0);
          RutaExpression expr = (RutaExpression) childs.get(1);
          int type = expr.getKind();
          if (ref.getType() == RutaTypeConstants.RUTA_TYPE_G) {
            ref.setType(type);
          }
        } catch (IndexOutOfBoundsException e) {
          // exception should have been recognized and reported in
          // parser
          return false;
        } catch (ClassCastException e) {
          // exception should have been recognized and reported in
          // parser
          return false;
        }
      }

      if (s instanceof RutaStructureAction) {
        RutaStructureAction sa = (RutaStructureAction) s;
        Expression struct = sa.getStructure();
        String structure = null;
        if (struct != null) {
          structure = sourceModule.getSource().substring(struct.sourceStart(), struct.sourceEnd());
          structure = expand(structure);
        }
        Map<Expression, Expression> assignments = sa.getAssignments();
        // hotfix... correct name in ast
        String action = sourceModule.getSource().substring(sa.getNameStart(), sa.getNameEnd());
        if (assignments != null && !action.equals("TRIE")) {
          for (Expression each : assignments.keySet()) {
            // TODO refactor to visitor?
            String feat = each.toString();
            // List<?> childs = each.getChilds();
            feat = getFeatureName(each, feat);
            boolean featureFound = findFeature(structure, feat, -1);
            if (!featureFound) {
              IProblem problem = problemFactory.createUnknownFeatureProblem(each, structure);
              pr.reportProblem(problem);
            }
          }
        }
      }
    }
    if (s instanceof RutaCondition) {
      RutaCondition cond = (RutaCondition) s;
      String conditionName = sourceModule.getSource().substring(cond.getNameStart(),
              cond.getNameEnd());
      String[] keywords = RutaKeywordsManager.getKeywords(IRutaKeywords.CONDITION);
      List<String> asList = Arrays.asList(keywords);
      if (!StringUtils.isEmpty(conditionName) && !"-".equals(conditionName)
              && !asList.contains(conditionName) && !implicitString.equals(cond.getName())) {
        IProblem problem = problemFactory.createUnknownConditionProblem(cond);
        pr.reportProblem(problem);
      }

      IRutaExtension extension = conditionExtensions.get(conditionName);
      if (extension != null) {
        // boolean checkSyntax =
        extension.checkSyntax(cond, problemFactory, pr);
      }

      if (conditionName.equals("FEATURE")) {
        if (matchedType != null) {
          List<?> args = cond.getChilds();
          RutaStringExpression se = (RutaStringExpression) args.get(0);
          String feat = se.toString();
          feat = getFeatureName(se, feat);
          boolean featureFound = findFeature(matchedType, feat, -1);
          if (!featureFound) {
            String featureMatch = isFeatureMatch(matchedType);
            if (featureMatch != null) {
              featureFound = findFeature(featureMatch, feat, -1);
            }
          }
          if (!featureFound) {
            IProblem problem = problemFactory.createUnknownFeatureProblem(se, matchedType);
            pr.reportProblem(problem);
          }
        }
      }
    }
View Full Code Here

  }

  private boolean checkTypeOfVariable(RutaVariableReference ref) {
    Integer vt = getVariableType(ref.getName());
    if (vt == null) {
      IProblem problem = problemFactory.createUnknownVariableProblem(ref);
      pr.reportProblem(problem);
      return false;
    } else {
      int variableType = vt.intValue();
      int requiredType = ref.getType();
      // reject generic types
      if ((requiredType & RutaTypeConstants.RUTA_TYPE_G) != 0) {
        return true;
      }
      if ((variableType & requiredType) == 0) {
        String errMsg = "Variable \"" + ref.getName() + "\" has type "
                + RutaTypeConstants.typeStringOfInt.get(variableType) + ". But type "
                + RutaTypeConstants.typeStringOfInt.get(requiredType) + " is required.";
        IProblem problem = new RutaCheckerDefaultProblem(sourceModule.getElementName(), errMsg,
                ref, linetracker.getLineNumberOfOffset(ref.sourceStart()));
        pr.reportProblem(problem);
        return false;
      }
    }
View Full Code Here

    if (!knowsVariable(ref.getName())) {
      // declared as type?
      if (namespaces.keySet().contains(ref.getName())) {
        String errMsg = "\"" + ref.getName() + "\" declared as a Type. Variable of type "
                + RutaTypeConstants.typeStringOfInt.get(ref.getType()) + " required.";
        IProblem problem = new RutaCheckerDefaultProblem(sourceModule.getElementName(), errMsg,
                ref, linetracker.getLineNumberOfOffset(ref.sourceStart()));
        pr.reportProblem(problem);
        return false;
      }
      String errMsgHead = "Variable \"";
      String errMsgTailDefault = " defined in this script or block!";

      // not found
      String errMsg = errMsgHead + ref.getName() + "\" not" + errMsgTailDefault;
      IProblem problem = new RutaCheckerDefaultProblem(sourceModule.getElementName(), errMsg, ref,
              linetracker.getLineNumberOfOffset(ref.sourceStart()));
      pr.reportProblem(problem);
      return false;
    }
    return true;
View Full Code Here

      RutaFunction f = (RutaFunction) element;
      String name = f.getName();
      boolean ok = true;
      List<Expression> childs = f.getChilds();
      if (childs.size() < 1) {
        IProblem problem = problemFactory.createWrongNumberOfArgumentsProblem(name, element, 1);
        rep.reportProblem(problem);
        ok = false;
      }
      Expression expr = childs.get(0);
      if (expr.getKind() != RutaTypeConstants.RUTA_TYPE_S) {
        IProblem problem = problemFactory.createWrongArgumentTypeProblem(expr, "TypeExpression");
        rep.reportProblem(problem);
        ok = false;
      }
      return ok;
    }
View Full Code Here

    if (element instanceof RutaFunction) {
      RutaFunction f = (RutaFunction) element;
      String name = f.getName();
      // TODO
      if (!name.equals(strings[0])) {
        IProblem problem = problemFactory.createUnknownFunctionProblem(f);
        rep.reportProblem(problem);
        return false;
      }
      boolean ok = true;
      List<Expression> childs = f.getChilds();
      if (childs.size() != 1) {
        IProblem problem = problemFactory.createWrongNumberOfArgumentsProblem(name, element, 1);
        rep.reportProblem(problem);
        ok = false;
      }
      Expression expr = childs.get(0);
      if (expr.getKind() != RutaTypeConstants.RUTA_TYPE_AT) {
        IProblem problem = problemFactory.createWrongArgumentTypeProblem(expr, "TypeExpression");
        rep.reportProblem(problem);
        ok = false;
      }
      return ok;
    }
View Full Code Here

        return false;
      }
      if (s instanceof RutaVariableDeclaration) {
        RutaVariableDeclaration newVar = (RutaVariableDeclaration) s;
        if (knowsVariable(newVar.getName())) {
          IProblem problem = problemFactory.createIdConflictsWithVariableProblem(newVar);
          rep.reportProblem(problem);
          return false;
        }
        if (knownLocalTypeNames.contains(newVar.getName())) {
          IProblem problem = problemFactory.createIdConflictsWithTypeProblem(newVar);
          rep.reportProblem(problem);
          return false;
        }
        knownLocalVariables.peek().put(newVar.getName(), newVar.getKind());
        return false;
View Full Code Here

        String actionName = currentFile.getSource().substring(tma.getNameStart(), tma.getNameEnd());
        String[] keywords = RutaKeywordsManager.getKeywords(IRutaKeywords.ACTION);
        List<String> asList = Arrays.asList(keywords);
        if (!StringUtils.isEmpty(actionName) && !"-".equals(actionName)
                && !asList.contains(actionName)) {
          IProblem problem = problemFactory.createUnknownActionProblem(tma);
          rep.reportProblem(problem);
        }

        IRutaExtension extension = actionExtensions.get(actionName);
        if (extension != null) {
          // boolean checkSyntax =
          extension.checkSyntax(tma, problemFactory, rep);
        }

        if (tma.getName().equals("GETFEATURE") || tma.getName().equals("SETFEATURE")) {
          List<?> childs = tma.getChilds();
          RutaStringExpression stringExpr = (RutaStringExpression) childs.get(0);
          String feat = stringExpr.toString();
          feat = getFeatureName(stringExpr, feat);
          boolean featureFound = findFeature(matchedType, feat);
          if (!featureFound) {
            IProblem problem = problemFactory.createUnknownFeatureProblem(stringExpr, matchedType);
            rep.reportProblem(problem);
          }
        }

        if (tma.getKind() == RutaActionConstants.A_ASSIGN) {
          List<?> childs = tma.getChilds();
          try {
            RutaVariableReference ref = (RutaVariableReference) childs.get(0);
            RutaExpression expr = (RutaExpression) childs.get(1);
            int type = expr.getKind();
            if (ref.getType() == RutaTypeConstants.RUTA_TYPE_G) {
              ref.setType(type);
            }
          } catch (IndexOutOfBoundsException e) {
            // exception should have been recognized and reported in
            // parser
            return false;
          } catch (ClassCastException e) {
            // exception should have been recognized and reported in
            // parser
            return false;
          }
        }
        if (s instanceof RutaStructureAction) {
          RutaStructureAction sa = (RutaStructureAction) s;
          Expression struct = sa.getStructure();
          String structure = null;
          if (struct != null) {
            structure = currentFile.getSource().substring(struct.sourceStart(), struct.sourceEnd());
          }
          Map<Expression, Expression> assignments = sa.getAssignments();
          // hotfix... correct name in ast
          String action = currentFile.getSource().substring(sa.getNameStart(), sa.getNameEnd());
          if (assignments != null && !action.equals("TRIE")) {
            for (Expression each : assignments.keySet()) {
              // TODO refactor to visitor?
              String feat = each.toString();
              // List<?> childs = each.getChilds();
              feat = getFeatureName(each, feat);
              boolean featureFound = findFeature(structure, feat);
              if (!featureFound) {
                IProblem problem = problemFactory.createUnknownFeatureProblem(each, structure);
                rep.reportProblem(problem);
              }
            }
          }
        }
      }
      if (s instanceof RutaCondition) {
        RutaCondition cond = (RutaCondition) s;
        String conditionName = currentFile.getSource().substring(cond.getNameStart(),
                cond.getNameEnd());
        String[] keywords = RutaKeywordsManager.getKeywords(IRutaKeywords.CONDITION);
        List<String> asList = Arrays.asList(keywords);
        if (!StringUtils.isEmpty(conditionName) && !"-".equals(conditionName)
                && !asList.contains(conditionName)) {
          IProblem problem = problemFactory.createUnknownConditionProblem(cond);
          rep.reportProblem(problem);
        }

        IRutaExtension extension = conditionExtensions.get(conditionName);
        if (extension != null) {
          // boolean checkSyntax =
          extension.checkSyntax(cond, problemFactory, rep);
        }
       
       
        if (conditionName.equals("FEATURE")) {
          if (matchedType != null) {
            List<?> args = cond.getChilds();
            RutaStringExpression se = (RutaStringExpression) args.get(0);
            String feat = se.toString();
            feat = getFeatureName(se, feat);
            boolean featureFound = findFeature(matchedType, feat);
            if (!featureFound) {
              IProblem problem = problemFactory.createUnknownFeatureProblem(se, matchedType);
              rep.reportProblem(problem);
            }
          }
        }
      }
View Full Code Here

      }
      if ((variableType & requiredType) == 0) {
        String errMsg = errMsgHead + ref.getName() + "\" has type "
                + RutaTypeConstants.typeStringOfInt.get(variableType) + ". \nBut type "
                + RutaTypeConstants.typeStringOfInt.get(requiredType) + " required.";
        IProblem problem = new RutaCheckerDefaultProblem(currentFile.getElementName(),
                errMsg, ref, linetracker.getLineNumberOfOffset(ref.sourceStart()));
        rep.reportProblem(problem);
        return false;
      }
      return true;
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.compiler.problem.IProblem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.