Example #1
0
 /** @since 2.7 */
 protected void addMarkerAndLogError(URI uri, Throwable e) {
   for (Pair<IStorage, IProject> storage : getStorage2UriMapper().getStorages(uri)) {
     IResource resource = null;
     if (storage.getFirst() instanceof IResource) {
       resource = (IResource) storage.getFirst();
     } else {
       resource = storage.getSecond();
     }
     if (resource != null) {
       try {
         IMarker marker = resource.createMarker(MarkerTypes.NORMAL_VALIDATION);
         marker.setAttribute(IMarker.MESSAGE, e.getMessage() + " - See error log for details");
         marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
         marker.setAttribute(IMarker.LINE_NUMBER, 1);
       } catch (CoreException ce) {
         logger.error("Could not create marker", ce);
       }
     }
   }
   Throwable cause = e;
   if (cause instanceof CoreException) {
     cause = cause.getCause();
   }
   if (uri == null) {
     logger.error("Error during compilation.", e);
   } else {
     logger.error("Error during compilation of '" + uri + "'.", e);
   }
 }
 protected void appendSyntheticDispatchMethods(XtendClass source, JvmGenericType target) {
   Multimap<Pair<String, Integer>, JvmOperation> methods =
       dispatchingSupport.getDispatchMethods(target);
   for (Pair<String, Integer> key : methods.keySet()) {
     Collection<JvmOperation> operations = methods.get(key);
     JvmOperation operation =
         deriveGenericDispatchOperationSignature(dispatchingSupport.sort(operations), target);
     operation.setSimpleName(key.getFirst());
   }
 }
Example #3
0
 public <S, P, D extends Pda<S, P>> Map<S, S> mapPopAndPush(Pda<S, P> pda) {
   Map<P, Pair<S, S>> popsAndPushs = collectPopsAndPushs(pda);
   Map<S, S> result = Maps.newLinkedHashMap();
   for (Pair<S, S> p : popsAndPushs.values()) {
     S push = p.getFirst();
     S pop = p.getSecond();
     if (push != null && pop != null) {
       result.put(push, pop);
       result.put(pop, push);
     }
   }
   return result;
 }
Example #4
0
 protected boolean shouldGenerate(Resource resource, IBuildContext context) {
   try {
     Iterable<Pair<IStorage, IProject>> storages =
         storage2UriMapper.getStorages(resource.getURI());
     for (Pair<IStorage, IProject> pair : storages) {
       if (pair.getFirst() instanceof IFile
           && pair.getSecond().equals(context.getBuiltProject())) {
         IFile file = (IFile) pair.getFirst();
         return file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE)
             != IMarker.SEVERITY_ERROR;
       }
     }
     return false;
   } catch (CoreException exc) {
     throw new WrappedException(exc);
   }
 }
Example #5
0
 /** @since 2.7 */
 protected String getCurrentSourceFolder(IBuildContext context, Delta delta) {
   Iterable<org.eclipse.xtext.util.Pair<IStorage, IProject>> storages =
       storage2UriMapper.getStorages(delta.getUri());
   for (org.eclipse.xtext.util.Pair<IStorage, IProject> pair : storages) {
     final IResource resource = (IResource) pair.getFirst();
     IProject project = pair.getSecond();
     for (OutputConfiguration output : getOutputConfigurations(context).values()) {
       for (SourceMapping sourceMapping : output.getSourceMappings()) {
         IContainer folder = ResourceUtil.getContainer(project, sourceMapping.getSourceFolder());
         if (folder.contains(resource)) {
           return sourceMapping.getSourceFolder();
         }
       }
     }
   }
   return null;
 }
Example #6
0
 public <S, P, D extends Pda<S, P>> Map<P, Pair<S, S>> collectPopsAndPushs(Pda<S, P> pda) {
   Map<P, Pair<S, S>> result = Maps.newLinkedHashMap();
   for (S s : nfaUtil.collect(pda)) {
     P push = pda.getPush(s);
     if (push != null) {
       Pair<S, S> o = result.get(push);
       Pair<S, S> n = Tuples.create(s, o == null ? null : o.getSecond());
       result.put(push, n);
     }
     P pop = pda.getPop(s);
     if (pop != null) {
       Pair<S, S> o = result.get(pop);
       Pair<S, S> n = Tuples.create(o == null ? null : o.getFirst(), s);
       result.put(pop, n);
     }
   }
   return result;
 }
 public ToBeBuilt removeProject(IProject project, IProgressMonitor monitor) {
   SubMonitor progress =
       SubMonitor.convert(monitor, Iterables.size(builderState.getAllResourceDescriptions()));
   ToBeBuilt result = new ToBeBuilt();
   Iterable<IResourceDescription> allResourceDescriptions =
       builderState.getAllResourceDescriptions();
   for (IResourceDescription description : allResourceDescriptions) {
     Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(description.getURI());
     boolean onlyOnThisProject = true;
     Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
     while (iterator.hasNext() && onlyOnThisProject) {
       Pair<IStorage, IProject> storage2Project = iterator.next();
       onlyOnThisProject = project.equals(storage2Project.getSecond());
     }
     if (onlyOnThisProject) result.getToBeDeleted().add(description.getURI());
     progress.worked(1);
   }
   return result;
 }
Example #8
0
  @Override
  protected void configureFormatting(FormattingConfig c) {
    org.eclectic.frontend.services.MappingsGrammarAccess f =
        (org.eclectic.frontend.services.MappingsGrammarAccess) getGrammarAccess();
    for (Pair<Keyword, Keyword> pair : f.findKeywordPairs("{", "}")) {
      c.setIndentation(pair.getFirst(), pair.getSecond());
      c.setLinewrap(1).after(pair.getFirst());
      c.setLinewrap(1).before(pair.getSecond());
      c.setLinewrap(1).after(pair.getSecond());
    }
    for (Keyword comma : f.findKeywords(",")) {
      c.setNoLinewrap().before(comma);
      c.setNoSpace().before(comma);
      c.setLinewrap().after(comma);
    }
    c.setLinewrap(0, 1, 2).before(f.getSL_COMMENTRule());
    c.setLinewrap(0, 1, 2).before(f.getML_COMMENTRule());
    c.setLinewrap(0, 1, 1).after(f.getML_COMMENTRule());

    // Manually added
    for (Keyword end : f.findKeywords("end")) {
      c.setLinewrap().before(end);
      c.setLinewrap().after(end);
    }

    for (Keyword end : f.findKeywords("from")) {
      c.setLinewrap().before(end);
      // c.setLinewrap().after(end);
    }

    c.setLinewrap().before(f.getAttributeMappingRule());
    c.setLinewrap().before(f.getReference2ReferenceRule());
  }
 // copy/pasted from PreferenceStoreWhitespaceInformationProvider, just call to
 // senseLineDelimiter() commented out
 protected String getLineSeparatorPreference(URI uri) {
   //		if (uri.isPlatformResource()) {
   //			IFile file = workspace.getRoot().getFile(new Path(uri.toPlatformString(true)));
   //			String delimiter = senseLineDelimiter(file);
   //			if (delimiter != null) return delimiter;
   //		}
   IProject project = null;
   if (uri.isPlatformResource()) {
     project = workspace.getRoot().getProject(uri.segment(1));
   } else {
     for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(uri)) {
       project = storage.getSecond();
       break;
     }
   }
   if (project != null) {
     String result = getLineSeparatorPreference(new ProjectScope(project));
     if (result != null) return result;
   }
   @SuppressWarnings("all")
   String result = getLineSeparatorPreference(new InstanceScope());
   if (result != null) return result;
   return System.getProperty("line.separator");
 }
  @Override
  protected void configureFormatting(FormattingConfig cfg) {
    OrcsScriptDslGrammarAccess grmr = (OrcsScriptDslGrammarAccess) getGrammarAccess();

    cfg.setAutoLinewrap(120);

    // Comments
    cfg.setLinewrap(0, 1, 2).before(grmr.getSL_COMMENTRule());

    cfg.setLinewrap(2, 2, 2).before(grmr.getML_COMMENTRule());
    cfg.setLinewrap(0, 1, 1).after(grmr.getML_COMMENTRule());

    // General Keywords
    for (Keyword keyword : grmr.findKeywords(";")) {
      cfg.setNoSpace().before(keyword);
    }
    for (Keyword keyword : grmr.findKeywords(".")) {
      cfg.setNoSpace().before(keyword);
      cfg.setNoSpace().after(keyword);
    }
    for (Keyword keyword : grmr.findKeywords("..")) {
      cfg.setNoSpace().before(keyword);
      cfg.setNoSpace().after(keyword);
    }
    for (Keyword keyword : grmr.findKeywords(",")) {
      cfg.setNoSpace().before(keyword);
      cfg.setSpace(" ").after(keyword);
    }
    for (Pair<Keyword, Keyword> pair : grmr.findKeywordPairs("(", ")")) {
      cfg.setNoSpace().after(pair.getFirst());
      cfg.setNoSpace().before(pair.getSecond());
    }
    for (Pair<Keyword, Keyword> pair : grmr.findKeywordPairs("[", "]")) {
      cfg.setNoSpace().after(pair.getFirst());
      cfg.setNoSpace().before(pair.getSecond());
    }

    // >>>>>>>>>>>>>>>>> Grammar
    // Script Version
    ScriptVersionElements version = grmr.getScriptVersionAccess();
    cfg.setLinewrap(0, 1, 2).before(version.getGroup());
    cfg.setLinewrap(1).after(version.getGroup());

    // templates
    OsTemplateLiteralElements template = grmr.getOsTemplateLiteralAccess();
    cfg.setNoSpace().after(template.getLeftCurlyBracketLeftCurlyBracketKeyword_1());
    cfg.setNoSpace().before(template.getRightCurlyBracketRightCurlyBracketKeyword_3());

    // variables
    OsVariableDeclarationElements variable = grmr.getOsVariableDeclarationAccess();
    cfg.setLinewrap(0, 1, 2).before(variable.getVarKeyword_1());
    cfg.setLinewrap(1, 1, 2).after(variable.getSemicolonKeyword_4());

    // start from ....;
    OsQueryExpressionElements query = grmr.getOsQueryExpressionAccess();
    cfg.setLinewrap(1).before(query.getNameStartKeyword_1_0());

    OsQueryStatementElements stmt = grmr.getOsQueryStatementAccess();
    cfg.setLinewrap(2).after(stmt.getSemicolonKeyword_1());

    // find
    OsFindClauseElements find = grmr.getOsFindClauseAccess();
    cfg.setLinewrap(1).before(find.getGroup());
    cfg.setLinewrap(1).after(find.getGroup());

    // follow
    OsFollowClauseElements follow = grmr.getOsFollowClauseAccess();
    cfg.setLinewrap(1).before(follow.getGroup());
    cfg.setLinewrap(1).after(follow.getGroup());

    // collect
    OsCollectClauseElements collect = grmr.getOsCollectClauseAccess();
    cfg.setLinewrap(1).before(collect.getNameCollectKeyword_0_0());
    cfg.setLinewrap(1).after(collect.getGroup());

    OsCollectObjectExpressionElements collectObj = grmr.getOsCollectObjectExpressionAccess();
    cfg.setLinewrap().after(collectObj.getLeftCurlyBracketKeyword_3());
    cfg.setIndentationIncrement().before(collectObj.getGroup_4_1());
    cfg.setIndentationDecrement().after(collectObj.getGroup_4_1());
    cfg.setLinewrap().before(collectObj.getRightCurlyBracketKeyword_5());

    OsCollectAllFieldsExpressionElements allFields = grmr.getOsCollectAllFieldsExpressionAccess();
    cfg.setNoLinewrap().before(allFields.getNameAsteriskKeyword_1_0());
    cfg.setNoLinewrap().after(allFields.getNameAsteriskKeyword_1_0());
  }