Esempio n. 1
0
  @Override
  public EolElement create(AST ast, EolElement container, Ast2EolContext context) {

    Import imp = context.getEolFactory().createImport(); // create an Import
    this.setAssets(ast, imp, container);

    AST importedStringAST = ast.getFirstChild(); // obtain the imported string AST
    if (importedStringAST != null) {
      String importedString = importedStringAST.getText();
      AST importedAst = null;

      try {
        importedAst = getAstForFile(importedString, context);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      if (importedAst != null) {
        imp.setImportedProgram(
            (Program)
                context.getEolElementCreatorFactory().createDomElement(importedAst, imp, context));
      }
      imp.setImported(
          (StringExpression)
              context
                  .getEolElementCreatorFactory()
                  .createDomElement(
                      importedStringAST,
                      imp,
                      context)); // create an StringExpression for the imported string
    }

    return imp;
  }
Esempio n. 2
0
  private void addStyleTypeSelector(String name, Rule rule, boolean local, int lineNumber) {
    StyleDef styleDef;

    if (local) {
      localStyleTypeNames.add(name);
    }

    if (selectors.containsKey(name)) {
      styleDef = (StyleDef) selectors.get(name);
    } else {
      styleDef =
          new StyleDef(
              name, true, mxmlDocument, compilationUnit.getSource(), lineNumber, perCompileData);
      selectors.put(name, styleDef);
    }

    styleDef.addRule(rule);

    if (mxmlDocument != null) {
      Iterator iterator = styleDef.getImports().iterator();

      while (iterator.hasNext()) {
        Import importObject = (Import) iterator.next();
        mxmlDocument.addImport(importObject.getValue(), importObject.getLineNumber());
      }
    }
  }
Esempio n. 3
0
 public Import getImport(String alias) {
   for (Import i : getImports()) {
     if (!i.isAmbiguous() && i.getAlias().equals(alias)) {
       return i;
     }
   }
   return null;
 }
Esempio n. 4
0
 public boolean hasImport(Declaration d) {
   for (Import i : getImports()) {
     if (!i.isAmbiguous() && i.getDeclaration().equals(d)) {
       return true;
     }
   }
   return false;
 }
Esempio n. 5
0
 public static TypeInfo formImport(Import typeName, boolean isArray) {
   TypeInfo typeInfo = new TypeInfo();
   typeInfo.type = TypeInfo.Type.form(typeName.getFullName());
   typeInfo.isArray = isArray;
   if (!typeInfo.type.isBaseType()) {
     typeInfo.packageName = typeName.getPackageName();
     typeInfo.name = typeName.getName();
     typeInfo.isInside = typeName.isInside();
   }
   return typeInfo;
 }
Esempio n. 6
0
 @NotNull
 private static List<Import> importsToImportList(@NotNull PsiImportStatementBase[] imports) {
   List<Import> result = new LinkedList<Import>();
   for (PsiImportStatementBase i : imports) {
     Import anImport = importToImport(i);
     String name = anImport.getName();
     if (!name.isEmpty() && !NOT_NULL_ANNOTATIONS.contains(name)) {
       result.add(anImport);
     }
   }
   return result;
 }
Esempio n. 7
0
  public String compileGrammar() {
    String f = header.getHeader();
    f = f.concat("grammar " + name + ";\n");

    for (Import i : imports) {
      f = f.concat(i.getString() + "\n");
    }
    for (Rule r : rules) {
      f = f.concat(r.getRuleString() + "\n");
    }
    return f;
  }
Esempio n. 8
0
 public Class<?> classNamed(String name) {
   try {
     return (name.startsWith(prefix))
         ? Import.forName(name)
         : (name.indexOf(".") == -1) ? Import.forName(prefix + name) : null;
   } catch (java.lang.SecurityException se) {
     // Can come back from Netscape. Assume the guessed name doesn't
     // exist.
     return null;
   } catch (Throwable t) {
     E.warn(this + " " + name + " " + t);
     return null;
   }
 }
Esempio n. 9
0
  public void addImport(String className) {
    List<Import> imports = getImports();

    if (imports.size() == 0) {
      TokenIterator iter = new TokenIterator();
      int offset = 0;
      boolean insertLF = false;
      while (iter.hasNext()) {
        Token token = iter.next();
        if (token.type != token.RESERVED_WORD) {
          insertLF = false;
          continue;
        }
        if (getText(token).equals("package")) {
          skipToEOL(iter, token);
          insertLF = true;
        } else {
          offset = token.offset;
          break;
        }
      }
      textArea.insert((insertLF ? "\n" : "") + "import " + className + ";\n\n", offset);
      return;
    }

    String string = "import " + className + ";\n";
    Import imp = new Import(0, 0, className);
    int insert = -1;

    for (int i = 0; i < imports.size(); i++) {
      int cmp = imports.get(i).compareTo(imp);
      if (cmp == 0) return;
      if (cmp < 0) insert = i;
    }

    // 'insert' is the index of the import _after_ which we
    // want to insert the current import.
    if (insert >= 0) string = "\n" + string;
    if (insert >= 0 && !imp.getPackage().equals(imports.get(insert).getPackage()))
      string = "\n" + string;
    if (insert + 1 < imports.size()
        && !imp.getPackage().equals(imports.get(insert + 1).getPackage())) string += "\n";
    int startOffset = insert < 0 ? imports.get(0).startOffset : imports.get(insert).endOffset;
    int endOffset =
        insert + 1 < imports.size()
            ? imports.get(insert + 1).startOffset
            : imports.get(insert).endOffset;
    textArea.replaceRange(string, startOffset, endOffset);
  }
Esempio n. 10
0
 public static Imports allOf(@Nonnull final Field field) {
   Check.notNull(field, "field");
   final List<Import> imports = Lists.newArrayList();
   imports.add(Import.of(field));
   imports.addAll(ofAnnotations(field.getAnnotations()).asList());
   return new Imports(imports);
 }
Esempio n. 11
0
 @Override
 public Void visit(Import i, Void _) {
     builder.append("imports ");
     builder.append(i.getName());
     builder.append('\n');
     return null;
 }
Esempio n. 12
0
 public static Imports allOf(@Nonnull final Method method) {
   Check.notNull(method, "method");
   final List<Import> imports = Lists.newArrayList();
   imports.add(Import.of(method.getReturnType().getType()));
   imports.addAll(ofAnnotations(method.getAnnotations()).asList());
   return new Imports(imports);
 }
Esempio n. 13
0
 private static Imports ofFields(@Nonnull final Iterable<Field> fields) {
   Check.notNull(fields, "fields");
   final List<Import> imports = Lists.newArrayList();
   for (final Field field : fields) {
     imports.add(Import.of(field));
   }
   return new Imports(imports);
 }
Esempio n. 14
0
 private static Imports ofInterfaces(@Nonnull final Iterable<Interface> interfaces) {
   Check.notNull(interfaces, "interfaces");
   final List<Import> imports = Lists.newArrayList();
   for (final Interface i : interfaces) {
     imports.add(Import.of(i));
   }
   return new Imports(imports);
 }
Esempio n. 15
0
 private static Imports ofAnnotations(@Nonnull final Iterable<Annotation> annotations) {
   Check.notNull(annotations, "annotations");
   final List<Import> imports = Lists.newArrayList();
   for (final Annotation annotation : annotations) {
     imports.add(Import.of(annotation));
   }
   return new Imports(imports);
 }
Esempio n. 16
0
 private static Imports ofAttributes(@Nonnull final Iterable<Attribute> attributes) {
   Check.notNull(attributes, "attributes");
   final List<Import> imports = Lists.newArrayList();
   for (final Attribute attribute : attributes) {
     imports.add(Import.of(attribute));
   }
   return new Imports(imports);
 }
Esempio n. 17
0
 /**
  * Searches the set of imports to find a matching import by type name.
  *
  * @param typeName name of type (qualified or simple name allowed)
  * @return found import or {@code null}
  */
 @Nullable
 public Import find(@Nonnull final String typeName) {
   Check.notEmpty(typeName, "typeName");
   Import ret = null;
   final Type type = new Type(typeName);
   for (final Import imp : imports) {
     if (imp.getType().getName().equals(type.getName())) {
       ret = imp;
       break;
     }
   }
   if (ret == null) {
     final Type javaLangType = Type.evaluateJavaLangType(typeName);
     if (javaLangType != null) {
       ret = Import.of(javaLangType);
     }
   }
   return ret;
 }
Esempio n. 18
0
  public void sortImports() {
    List<Import> imports = getImports();
    if (imports.size() == 0) return;
    int start = imports.get(0).startOffset;
    while (emptyLineAt(start - 2)) start--;
    int end = imports.get(imports.size() - 1).endOffset;
    while (eolAt(end)) end++;

    Collections.sort(
        imports,
        new Comparator<Import>() {
          public int compare(Import i1, Import i2) {
            return i1.classOrPackage.compareTo(i2.classOrPackage);
          }

          public boolean equals(Object o) {
            return false;
          }
        });

    StringBuffer buffer = new StringBuffer();
    String lastPrefix = null;
    String lastImport = null;
    for (Import imp : imports) {
      if (imp.classOrPackage.equals(lastImport)) continue;
      lastImport = imp.classOrPackage;

      String prefix = imp.getPackage();
      if (!prefix.equals(lastPrefix)) {
        buffer.append("\n");
        lastPrefix = prefix;
      }
      // TODO: honor comments
      buffer.append(getText(imp.startOffset, imp.endOffset));
      buffer.append("\n");
    }
    buffer.append("\n");

    textArea.replaceRange(buffer.toString(), start, end);
  }
Esempio n. 19
0
 private void addImports(PMML pmml, Package aPackage) {
   String importsFromDelimitedString =
       ScorecardPMMLUtils.getExtensionValue(
           pmml.getHeader().getExtensions(), PMMLExtensionNames.SCORECARD_IMPORTS);
   if (!(importsFromDelimitedString == null || importsFromDelimitedString.isEmpty())) {
     for (String importStatement : importsFromDelimitedString.split(",")) {
       Import imp = new Import();
       imp.setClassName(importStatement);
       aPackage.addImport(imp);
     }
   }
   Import defaultScorecardImport = new Import();
   defaultScorecardImport.setClassName("org.drools.scorecards.DroolsScorecard");
   aPackage.addImport(defaultScorecardImport);
   defaultScorecardImport = new Import();
   defaultScorecardImport.setClassName("org.drools.scorecards.PartialScore");
   aPackage.addImport(defaultScorecardImport);
   defaultScorecardImport = new Import();
   defaultScorecardImport.setClassName("org.drools.scorecards.InitialScore");
   aPackage.addImport(defaultScorecardImport);
   defaultScorecardImport = new Import();
   defaultScorecardImport.setClassName("org.drools.scorecards.BaselineScore");
   aPackage.addImport(defaultScorecardImport);
 }
Esempio n. 20
0
 protected void addImport(Import imp) {
   if (imp != NULL_IMPORT && imp.needsImport()) {
     imports.add(imp);
   }
 }
Esempio n. 21
0
 @Override
 public int compare(@Nonnull final Import left, @Nonnull final Import right) { // NOSONAR
   return left.getType().toString().compareTo(right.getType().toString());
 }
Esempio n. 22
0
 @Override
 public boolean apply(@Nonnull final Import imp) { // NOSONAR
   return !Package.UNDEFINED.equals(imp.getType().getPackage());
 }
Esempio n. 23
0
 protected void assertImport(Import anImport, String name, boolean isInside) {
   assertEquals(name, anImport.getFullName());
   assertEquals(isInside, anImport.isInside());
 }
 public DeclarationWithProximity(Import imp, int proximity) {
   this.declaration = imp.getDeclaration();
   this.proximity = proximity;
   this.name = imp.getAlias();
 }