Beispiel #1
0
 protected String getTabName() {
   String _xifexpression = null;
   boolean _needsSave = this.root.getNeedsSave();
   if (_needsSave) {
     _xifexpression = "*";
   } else {
     _xifexpression = "";
   }
   final String prefix = _xifexpression;
   String _fileName = this.root.getFileName();
   String[] _split = null;
   if (_fileName != null) {
     String _quote = Pattern.quote(File.separator);
     _split = _fileName.split(_quote);
   }
   String _last = null;
   if (((Iterable<String>) Conversions.doWrapArray(_split)) != null) {
     _last = IterableExtensions.<String>last(((Iterable<String>) Conversions.doWrapArray(_split)));
   }
   final String fileName = _last;
   boolean _equals = Objects.equal(fileName, null);
   if (_equals) {
     return (prefix + "Untitled");
   }
   final int dotPos = fileName.lastIndexOf(".");
   if ((dotPos >= 0)) {
     String _substring = fileName.substring(0, dotPos);
     return (prefix + _substring);
   } else {
     return (prefix + fileName);
   }
 }
 @Override
 public WorkspaceConfig get() {
   SimpleWorkspaceConfig _xblockexpression = null;
   {
     ProjectManager _instance = ProjectManager.getInstance();
     Project[] _openProjects = _instance.getOpenProjects();
     final Project project =
         IterableExtensions.<Project>head(
             ((Iterable<Project>) Conversions.doWrapArray(_openProjects)));
     String _basePath = project.getBasePath();
     final SimpleWorkspaceConfig result = new SimpleWorkspaceConfig(_basePath);
     ModuleManager _instance_1 = ModuleManager.getInstance(project);
     Module[] _modules = _instance_1.getModules();
     final Procedure1<Module> _function =
         new Procedure1<Module>() {
           @Override
           public void apply(final Module m) {
             IdeaModuleConfig _ideaModuleConfig =
                 new IdeaModuleConfig(m, IdeaWorkspaceConfigProvider.this.outputConfigurations);
             result.addProjectConfig(_ideaModuleConfig);
           }
         };
     IterableExtensions.<Module>forEach(
         ((Iterable<Module>) Conversions.doWrapArray(_modules)), _function);
     _xblockexpression = result;
   }
   return _xblockexpression;
 }
Beispiel #3
0
 private static String getPackageName(final String qualifiedName, final boolean strict) {
   Splitter _on = Splitter.on(".");
   Iterable<String> _split = _on.split(qualifiedName);
   final List<String> segments = IterableExtensions.<String>toList(_split);
   int _size = segments.size();
   boolean _equals = (_size == 1);
   if (_equals) {
     return "";
   }
   if (strict) {
     int _length = ((Object[]) Conversions.unwrapArray(segments, Object.class)).length;
     int _minus = (_length - 1);
     final List<String> packageSegments = segments.subList(0, _minus);
     final Function1<String, Boolean> _function =
         (String it) -> {
           char _charAt = it.charAt(0);
           return Boolean.valueOf(Character.isUpperCase(_charAt));
         };
     Iterable<String> _filter = IterableExtensions.<String>filter(packageSegments, _function);
     boolean _isEmpty = IterableExtensions.isEmpty(_filter);
     boolean _not = (!_isEmpty);
     if (_not) {
       throw new IllegalArgumentException(
           (("Cannot determine the package name of \'" + qualifiedName)
               + "\'. Please use the TypeReference(packageName, className) constructor"));
     }
     return IterableExtensions.join(packageSegments, ".");
   } else {
     int _length_1 = ((Object[]) Conversions.unwrapArray(segments, Object.class)).length;
     int _minus_1 = (_length_1 - 1);
     List<String> packageSegments_1 = segments.subList(0, _minus_1);
     while ((!packageSegments_1.isEmpty())) {
       String _last = IterableExtensions.<String>last(packageSegments_1);
       char _charAt = _last.charAt(0);
       boolean _isUpperCase = Character.isUpperCase(_charAt);
       if (_isUpperCase) {
         final List<String> _converted_packageSegments_1 = (List<String>) packageSegments_1;
         int _length_2 =
             ((Object[]) Conversions.unwrapArray(_converted_packageSegments_1, Object.class))
                 .length;
         int _minus_2 = (_length_2 - 1);
         List<String> _subList = packageSegments_1.subList(0, _minus_2);
         packageSegments_1 = _subList;
       } else {
         return IterableExtensions.join(packageSegments_1, ".");
       }
     }
     return "";
   }
 }
 public String simpleName(final ModuleAST module) {
   String _name = module.getName();
   String[] _split = _name.split("\\.");
   String _last =
       IterableExtensions.<String>last(((Iterable<String>) Conversions.doWrapArray(_split)));
   return StringExtensions.toFirstLower(_last);
 }
 private IJavaProject xtendProject(final String name, final IJavaProject... upstreamProjects) {
   try {
     final IJavaProject result = JavaProjectSetupUtil.createJavaProject(name);
     IProject _project = result.getProject();
     IResourcesSetupUtil.addNature(_project, XtextProjectHelper.NATURE_ID);
     this.xtendLibs.addLibsToClasspath(result, null);
     final Procedure1<IJavaProject> _function =
         new Procedure1<IJavaProject>() {
           @Override
           public void apply(final IJavaProject it) {
             try {
               IPath _path = it.getPath();
               IClasspathEntry _newProjectEntry = JavaCore.newProjectEntry(_path, true);
               JavaProjectSetupUtil.addToClasspath(result, _newProjectEntry);
             } catch (Throwable _e) {
               throw Exceptions.sneakyThrow(_e);
             }
           }
         };
     IterableExtensions.<IJavaProject>forEach(
         ((Iterable<IJavaProject>) Conversions.doWrapArray(upstreamProjects)), _function);
     return result;
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
Beispiel #6
0
 public String getLanguageNameAbbreviation() {
   String[] packageNames = this.languageName.split("\\.");
   final String[] _converted_packageNames = (String[]) packageNames;
   String _last =
       IterableExtensions.<String>last(
           ((Iterable<String>) Conversions.doWrapArray(_converted_packageNames)));
   return Strings.toFirstUpper(_last);
 }
 protected Object _execute(final ExitState exitState) {
   Object _xblockexpression = null;
   {
     ExecutionState[] _stateConfiguration = this.executionContext.getStateConfiguration();
     ExecutionState _state = exitState.getState();
     StateVector _stateVector = _state.getStateVector();
     int _offset = _stateVector.getOffset();
     ((List<ExecutionState>) Conversions.doWrapArray(_stateConfiguration)).set(_offset, null);
     _xblockexpression = (null);
   }
   return _xblockexpression;
 }
 public void checkEntityProgram(final String contents, final int expectedErrors) {
   try {
     String _plus = (this.TEST_PROJECT + "/src/test.entities");
     final IFile file = IResourcesSetupUtil.createFile(_plus, contents);
     IResourcesSetupUtil.waitForAutoBuild();
     IMarker[] _findMarkers = file.findMarkers(EValidator.MARKER, true, IResource.DEPTH_INFINITE);
     int _size = ((List<IMarker>) Conversions.doWrapArray(_findMarkers)).size();
     Assert.assertEquals(expectedErrors, _size);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 public void runCycle() throws ExecutionException {
   {
     this.externalExecutionContext.flush();
     this.nextSVIdx = 0;
     this.execute(this.brc);
     ExecutionState[] _stateConfiguration = this.executionContext.getStateConfiguration();
     int _size = ((List<ExecutionState>) Conversions.doWrapArray(_stateConfiguration)).size();
     boolean _operator_lessThan =
         ComparableExtensions.<Integer>operator_lessThan(
             ((Integer) this.nextSVIdx), ((Integer) _size));
     Boolean _xwhileexpression = _operator_lessThan;
     while (_xwhileexpression) {
       {
         ExecutionState[] _stateConfiguration_1 = this.executionContext.getStateConfiguration();
         ExecutionState _get =
             ((List<ExecutionState>) Conversions.doWrapArray(_stateConfiguration_1))
                 .get(this.nextSVIdx);
         ExecutionState state = _get;
         boolean _operator_notEquals = ObjectExtensions.operator_notEquals(state, null);
         if (_operator_notEquals) {
           Sequence _reactSequence = state.getReactSequence();
           this.execute(_reactSequence);
         }
         int _operator_plus =
             IntegerExtensions.operator_plus(((Integer) this.nextSVIdx), ((Integer) 1));
         this.nextSVIdx = _operator_plus;
       }
       ExecutionState[] _stateConfiguration_2 = this.executionContext.getStateConfiguration();
       int _size_1 =
           ((List<ExecutionState>) Conversions.doWrapArray(_stateConfiguration_2)).size();
       boolean _operator_lessThan_1 =
           ComparableExtensions.<Integer>operator_lessThan(
               ((Integer) this.nextSVIdx), ((Integer) _size_1));
       _xwhileexpression = _operator_lessThan_1;
     }
     this.executionContext.resetRaisedEvents();
     this.execute(this.erc);
   }
 }
 @Override
 public Object[] getVariants() {
   ArrayList<LookupElementBuilder> _xblockexpression = null;
   {
     ProgressIndicatorProvider.checkCanceled();
     ICrossReferenceDescription crossReferenceDescription = this.getCrossReferenceDescription();
     boolean _equals = Objects.equal(crossReferenceDescription, null);
     if (_equals) {
       return ((Object[])
           Conversions.unwrapArray(CollectionLiterals.<Object>emptyList(), Object.class));
     }
     ArrayList<LookupElementBuilder> variants =
         CollectionLiterals.<LookupElementBuilder>newArrayList();
     Iterable<IEObjectDescription> _variants = crossReferenceDescription.getVariants();
     for (final IEObjectDescription objectDescription : _variants) {
       {
         ProgressIndicatorProvider.checkCanceled();
         QualifiedName _name = objectDescription.getName();
         String name = this.qualifiedNameConverter.toString(_name);
         BaseXtextFile _xtextFile = this.myElement.getXtextFile();
         XtextResource _resource = _xtextFile.getResource();
         PsiElement element =
             this.psiModelAssociations.getPsiElement(objectDescription, _resource);
         boolean _notEquals = (!Objects.equal(element, null));
         if (_notEquals) {
           LookupElementBuilder _create = LookupElementBuilder.create(name);
           PsiElement _navigationElement = element.getNavigationElement();
           PsiFile _containingFile = _navigationElement.getContainingFile();
           String _name_1 = _containingFile.getName();
           LookupElementBuilder _withTypeText = _create.withTypeText(_name_1);
           variants.add(_withTypeText);
         }
       }
     }
     _xblockexpression = variants;
   }
   return ((Object[]) Conversions.unwrapArray(_xblockexpression, Object.class));
 }
 public void addExportedPackage(
     final IJavaProject pluginProject, final String... exportedPackages) {
   try {
     IProject _project = pluginProject.getProject();
     final IFile manifestFile = _project.getFile("META-INF/MANIFEST.MF");
     final InputStream manifestContent = manifestFile.getContents();
     Manifest _xtrycatchfinallyexpression = null;
     try {
       _xtrycatchfinallyexpression = new Manifest(manifestContent);
     } finally {
       manifestContent.close();
     }
     final Manifest manifest = _xtrycatchfinallyexpression;
     final Attributes attrs = manifest.getMainAttributes();
     boolean _containsKey = attrs.containsKey("Export-Package");
     if (_containsKey) {
       Object _get = attrs.get("Export-Package");
       String _plus = (_get + ",");
       String _join =
           IterableExtensions.join(((Iterable<?>) Conversions.doWrapArray(exportedPackages)), ",");
       String _plus_1 = (_plus + _join);
       attrs.putValue("Export-Package", _plus_1);
     } else {
       String _join_1 =
           IterableExtensions.join(((Iterable<?>) Conversions.doWrapArray(exportedPackages)), ",");
       attrs.putValue("Export-Package", _join_1);
     }
     final ByteArrayOutputStream out = new ByteArrayOutputStream();
     manifest.write(out);
     byte[] _byteArray = out.toByteArray();
     final ByteArrayInputStream in = new ByteArrayInputStream(_byteArray);
     BufferedInputStream _bufferedInputStream = new BufferedInputStream(in);
     manifestFile.setContents(_bufferedInputStream, true, true, null);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
Beispiel #12
0
 protected String addIconDivs(final IImageDescription it, final String nameHtml) {
   String _switchResult = null;
   boolean _matched = false;
   if (it instanceof SimpleImageDescription) {
     _matched = true;
     String _imageID = ((SimpleImageDescription) it).getImageID();
     String _plus = (_imageID + "-icon");
     _switchResult = this.surroundWithDiv(nameHtml, _plus);
   }
   if (!_matched) {
     if (it instanceof AlternativeImageDescription) {
       _matched = true;
       List<String> _imageIDs = ((AlternativeImageDescription) it).getImageIDs();
       final Function1<String, String> _function =
           new Function1<String, String>() {
             @Override
             public String apply(final String it) {
               return (it + "-icon");
             }
           };
       List<String> _map = ListExtensions.<String, String>map(_imageIDs, _function);
       _switchResult =
           this.surroundWithDiv(
               nameHtml, ((String[]) Conversions.unwrapArray(_map, String.class)));
     }
   }
   if (!_matched) {
     if (it instanceof DecoratedImageDescription) {
       _matched = true;
       List<IImageDescription> _decorators = ((DecoratedImageDescription) it).getDecorators();
       IImageDescription _baseImage = ((DecoratedImageDescription) it).getBaseImage();
       Iterable<IImageDescription> _plus =
           Iterables.<IImageDescription>concat(
               _decorators,
               Collections.<IImageDescription>unmodifiableList(
                   CollectionLiterals.<IImageDescription>newArrayList(_baseImage)));
       final Function2<String, IImageDescription, String> _function =
           new Function2<String, IImageDescription, String>() {
             @Override
             public String apply(final String $0, final IImageDescription $1) {
               return HoverService.this.addIconDivs($1, $0);
             }
           };
       _switchResult =
           IterableExtensions.<IImageDescription, String>fold(_plus, nameHtml, _function);
     }
   }
   return _switchResult;
 }
 @Test
 public void testCompileTestData() {
   this.batchCompiler.compile();
   File _file = new File((FeatureBatchCompilerTest.OUTPUT_DIRECTORY + "/test"));
   final FilenameFilter _function =
       new FilenameFilter() {
         public boolean accept(final File dir, final String name) {
           boolean _endsWith = name.endsWith(".java");
           return _endsWith;
         }
       };
   String[] _list = _file.list(_function);
   int _size = ((List<String>) Conversions.doWrapArray(_list)).size();
   Assert.assertEquals(3, _size);
 }
 @Test
 public void testEnumeration() {
   try {
     final XExpression expression = this.expression("null", false);
     final Procedure1<JvmEnumerationType> _function =
         new Procedure1<JvmEnumerationType>() {
           public void apply(final JvmEnumerationType it) {
             EList<JvmMember> _members = it.getMembers();
             JvmEnumerationLiteral _enumerationLiteral =
                 JvmModelGeneratorTest.this.builder.toEnumerationLiteral(expression, "BAR");
             JvmModelGeneratorTest.this.builder.<JvmEnumerationLiteral>operator_add(
                 _members, _enumerationLiteral);
             EList<JvmMember> _members_1 = it.getMembers();
             JvmEnumerationLiteral _enumerationLiteral_1 =
                 JvmModelGeneratorTest.this.builder.toEnumerationLiteral(expression, "BAZ");
             JvmModelGeneratorTest.this.builder.<JvmEnumerationLiteral>operator_add(
                 _members_1, _enumerationLiteral_1);
           }
         };
     final JvmEnumerationType enumeration =
         this.builder.toEnumerationType(expression, "my.test.Foo", _function);
     Resource _eResource = expression.eResource();
     final Class<? extends Object> compiled = this.compile(_eResource, enumeration);
     final Method valuesMethod = compiled.getMethod("values");
     Object _invoke = valuesMethod.invoke(null);
     final Object[] values = ((Object[]) _invoke);
     Object _get = ((List<Object>) Conversions.doWrapArray(values)).get(0);
     String _string = _get.toString();
     Assert.assertEquals("BAR", _string);
     Object _get_1 = ((List<Object>) Conversions.doWrapArray(values)).get(1);
     String _string_1 = _get_1.toString();
     Assert.assertEquals("BAZ", _string_1);
   } catch (Exception _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 protected String root(final EObject xtendClass) {
   final XtendFile specFile =
       EcoreUtil2.<XtendFile>getContainerOfType(xtendClass, XtendFile.class);
   final String packageName = specFile.getPackage();
   boolean _equals = Objects.equal(packageName, null);
   if (_equals) {
     return "";
   }
   final String[] fragments = packageName.split("\\.");
   final Function1<String, String> _function =
       new Function1<String, String>() {
         public String apply(final String s) {
           return "../";
         }
       };
   final List<String> path =
       ListExtensions.<String, String>map(
           ((List<String>) Conversions.doWrapArray(fragments)), _function);
   return IterableExtensions.join(path, "");
 }
Beispiel #16
0
 public TypeReference(
     final String packageName, final String className, final List<TypeReference> arguments) {
   if ((packageName == null)) {
     throw new IllegalArgumentException(("Invalid package name: " + packageName));
   }
   if ((className == null)) {
     throw new IllegalArgumentException(("Invalid class name: " + className));
   }
   this.packageName = packageName;
   String[] _split = className.split("\\.");
   this.simpleNames = ((List<String>) Conversions.doWrapArray(_split));
   List<TypeReference> _elvis = null;
   if (arguments != null) {
     _elvis = arguments;
   } else {
     List<TypeReference> _emptyList = Collections.<TypeReference>emptyList();
     _elvis = _emptyList;
   }
   this.typeArguments = _elvis;
 }
Beispiel #17
0
 @Override
 public IResource getResource() {
   boolean _equals = Objects.equal(this.file, null);
   if (_equals) {
     IWorkspace _workspace = ResourcesPlugin.getWorkspace();
     IWorkspaceRoot _root = _workspace.getRoot();
     IPath _path = this.getPath();
     final List<IFile> possibleFiles =
         (List<IFile>) Conversions.doWrapArray(_root.findFilesForLocation(_path));
     int _size = possibleFiles.size();
     boolean _equals_1 = (_size == 1);
     if (_equals_1) {
       IFile _head = IterableExtensions.<IFile>head(possibleFiles);
       this.file = _head;
     }
     ErlLogger _instance = ErlLogger.getInstance();
     IPath _path_1 = this.getPath();
     _instance.warn("not able to find file %s", _path_1);
   }
   return this.file;
 }
 protected void createParserBasedProposals(
     final CompletionParameters parameters, final CompletionResultSet result) {
   Editor _editor = parameters.getEditor();
   int _offset = parameters.getOffset();
   final TokenSet tokenSet = this._tokenSetProvider.getTokenSet(((EditorEx) _editor), _offset);
   boolean _supportParserBasedProposals = this.supportParserBasedProposals(tokenSet);
   boolean _not = (!_supportParserBasedProposals);
   if (_not) {
     return;
   }
   final ContentAssistContextFactory delegate = this.getParserBasedDelegate();
   boolean _equals = Objects.equal(delegate, null);
   if (_equals) {
     return;
   }
   String _text = this.getText(parameters);
   TextRegion _selection = this.getSelection(parameters);
   int _offset_1 = parameters.getOffset();
   XtextResource _resource = this.getResource(parameters);
   final ContentAssistContext[] contexts =
       delegate.create(_text, _selection, _offset_1, _resource);
   final Procedure1<ContentAssistContext> _function =
       new Procedure1<ContentAssistContext>() {
         @Override
         public void apply(final ContentAssistContext c) {
           ImmutableList<AbstractElement> _firstSetGrammarElements =
               c.getFirstSetGrammarElements();
           final Procedure1<AbstractElement> _function =
               new Procedure1<AbstractElement>() {
                 @Override
                 public void apply(final AbstractElement e) {
                   AbstractCompletionContributor.this.createProposal(e, c, parameters, result);
                 }
               };
           IterableExtensions.<AbstractElement>forEach(_firstSetGrammarElements, _function);
         }
       };
   IterableExtensions.<ContentAssistContext>forEach(
       ((Iterable<ContentAssistContext>) Conversions.doWrapArray(contexts)), _function);
 }
 @Test
 public void testAnnotation_1() {
   try {
     final XExpression expression = this.expression("42", false);
     final Procedure1<JvmAnnotationType> _function =
         new Procedure1<JvmAnnotationType>() {
           public void apply(final JvmAnnotationType it) {
             EList<JvmMember> _members = it.getMembers();
             JvmTypeReference _typeForName =
                 JvmModelGeneratorTest.this.references.getTypeForName(int.class, expression);
             final Procedure1<JvmOperation> _function =
                 new Procedure1<JvmOperation>() {
                   public void apply(final JvmOperation it) {
                     JvmModelGeneratorTest.this.builder.setBody(it, expression);
                   }
                 };
             JvmOperation _method =
                 JvmModelGeneratorTest.this.builder.toMethod(
                     expression, "theTruth", _typeForName, _function);
             JvmModelGeneratorTest.this.builder.<JvmOperation>operator_add(_members, _method);
           }
         };
     final JvmAnnotationType clazz =
         this.builder.toAnnotationType(expression, "my.test.Foo", _function);
     Resource _eResource = expression.eResource();
     final Class<? extends Object> compiledClass = this.compile(_eResource, clazz);
     boolean _isAnnotation = compiledClass.isAnnotation();
     Assert.assertTrue(_isAnnotation);
     Method[] _methods = compiledClass.getMethods();
     final Method method =
         IterableExtensions.<Method>head(((Iterable<Method>) Conversions.doWrapArray(_methods)));
     String _name = method.getName();
     Assert.assertEquals("theTruth", _name);
     Object _defaultValue = method.getDefaultValue();
     Assert.assertEquals(Integer.valueOf(42), _defaultValue);
   } catch (Exception _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 protected Object _execute(final StateSwitch stateSwitch) throws ExecutionException {
   Object _xblockexpression = null;
   {
     ExecutionRegion _historyRegion = stateSwitch.getHistoryRegion();
     final ExecutionRegion historyRegion = _historyRegion;
     boolean _operator_notEquals = ObjectExtensions.operator_notEquals(historyRegion, null);
     if (_operator_notEquals) {
       {
         ExecutionState _historyStateConfiguration =
             this.executionContext.getHistoryStateConfiguration(historyRegion);
         final ExecutionState historyState = _historyStateConfiguration;
         EList<StateCase> _cases = stateSwitch.getCases();
         for (final StateCase stateCase : _cases) {
           ExecutionState _state = stateCase.getState();
           boolean _operator_equals = ObjectExtensions.operator_equals(historyState, _state);
           if (_operator_equals) {
             Step _step = stateCase.getStep();
             this.execute(_step);
           }
         }
       }
     } else {
       EList<StateCase> _cases_1 = stateSwitch.getCases();
       for (final StateCase stateCase_1 : _cases_1) {
         ExecutionState[] _stateConfiguration = this.executionContext.getStateConfiguration();
         ExecutionState _state_1 = stateCase_1.getState();
         boolean _contains =
             ((List<ExecutionState>) Conversions.doWrapArray(_stateConfiguration))
                 .contains(_state_1);
         if (_contains) {
           Step _step_1 = stateCase_1.getStep();
           this.execute(_step_1);
         }
       }
     }
     _xblockexpression = (null);
   }
   return _xblockexpression;
 }
 /**
  * Construct a Classloader with the classpathentries from the provided and all upstream-projects,
  * except the output folders of the local project.
  */
 protected URLClassLoader createClassLoaderForJavaProject(final IJavaProject projectToUse) {
   final LinkedHashSet<URL> urls = CollectionLiterals.<URL>newLinkedHashSet();
   try {
     boolean _isOutputFolderIncluded = this.isOutputFolderIncluded();
     HashSet<IJavaProject> _newHashSet = CollectionLiterals.<IJavaProject>newHashSet();
     this.collectClasspathURLs(projectToUse, urls, _isOutputFolderIncluded, _newHashSet);
   } catch (final Throwable _t) {
     if (_t instanceof JavaModelException) {
       final JavaModelException e = (JavaModelException) _t;
       boolean _isDoesNotExist = e.isDoesNotExist();
       boolean _not = (!_isDoesNotExist);
       if (_not) {
         String _message = e.getMessage();
         JdtBasedProcessorProvider.LOG.error(_message, e);
       }
     } else {
       throw Exceptions.sneakyThrow(_t);
     }
   }
   ClassLoader _parentClassLoader = this.getParentClassLoader();
   return new URLClassLoader(
       ((URL[]) Conversions.unwrapArray(urls, URL.class)), _parentClassLoader);
 }
Beispiel #22
0
 protected String surroundWithDiv(final String html, final String... divClasses) {
   StringConcatenation _builder = new StringConcatenation();
   _builder.append("<div");
   {
     int _length = divClasses.length;
     boolean _greaterThan = (_length > 0);
     if (_greaterThan) {
       _builder.append(" class=\"");
       String _join =
           IterableExtensions.join(((Iterable<?>) Conversions.doWrapArray(divClasses)), " ");
       _builder.append(_join, "");
       _builder.append("\"");
     }
   }
   _builder.append(">");
   _builder.newLineIfNotEmpty();
   _builder.append("\t");
   _builder.append(html, "\t");
   _builder.newLineIfNotEmpty();
   _builder.append("</div>");
   _builder.newLine();
   return _builder.toString();
 }
 public void testLibNotAddedTwice() {
   this.libraryAdder.apply(this.myModule);
   this.libraryAdder.apply(this.myModule);
   ModuleRootManager _instance = ModuleRootManager.getInstance(this.myModule);
   OrderEntry[] _orderEntries = _instance.getOrderEntries();
   final Function1<OrderEntry, Boolean> _function =
       new Function1<OrderEntry, Boolean>() {
         @Override
         public Boolean apply(final OrderEntry it) {
           String _presentableName = it.getPresentableName();
           return Boolean.valueOf(
               _presentableName.startsWith(XtendLibraryDescription.XTEND_LIBRARY_NAME));
         }
       };
   final Iterable<OrderEntry> xtendlibs =
       IterableExtensions.<OrderEntry>filter(
           ((Iterable<OrderEntry>) Conversions.doWrapArray(_orderEntries)), _function);
   int _size = IterableExtensions.size(xtendlibs);
   TestCase.assertEquals("Xtend libraries in module", 1, _size);
   StringConcatenation _builder = new StringConcatenation();
   _builder.append("class Foo {");
   _builder.newLine();
   _builder.append("\t");
   _builder.append("def static void main(String... args) {");
   _builder.newLine();
   _builder.append("\t\t");
   _builder.append("println(\"Foo\")");
   _builder.newLine();
   _builder.append("\t");
   _builder.append("}");
   _builder.newLine();
   _builder.append("}");
   _builder.newLine();
   this.configureByText(_builder.toString());
   this.myFixture.checkHighlighting();
 }
 @Test
 public void bug390290InnerClassMemberImport() {
   try {
     final XExpression expression = this.expression("null");
     final Procedure1<JvmGenericType> _function =
         new Procedure1<JvmGenericType>() {
           public void apply(final JvmGenericType it) {
             final JvmGenericType innerClass =
                 JvmModelGeneratorTest.this.builder.toClass(it, "InnerClass");
             final JvmGenericType innerClassString =
                 JvmModelGeneratorTest.this.builder.toClass(it, "String");
             EList<JvmMember> _members = it.getMembers();
             JvmModelGeneratorTest.this.builder.<JvmGenericType>operator_add(_members, innerClass);
             EList<JvmMember> _members_1 = it.getMembers();
             JvmModelGeneratorTest.this.builder.<JvmGenericType>operator_add(
                 _members_1, innerClassString);
             EList<JvmMember> _members_2 = it.getMembers();
             JvmTypeReference _typeForName =
                 JvmModelGeneratorTest.this.references.getTypeForName(String.class, expression);
             final Procedure1<JvmOperation> _function =
                 new Procedure1<JvmOperation>() {
                   public void apply(final JvmOperation fooMethod) {
                     EList<JvmFormalParameter> _parameters = fooMethod.getParameters();
                     JvmParameterizedTypeReference _createTypeRef =
                         JvmModelGeneratorTest.this.references.createTypeRef(innerClass);
                     JvmFormalParameter _parameter =
                         JvmModelGeneratorTest.this.builder.toParameter(it, "p1", _createTypeRef);
                     JvmModelGeneratorTest.this.builder.<JvmFormalParameter>operator_add(
                         _parameters, _parameter);
                     EList<JvmFormalParameter> _parameters_1 = fooMethod.getParameters();
                     JvmParameterizedTypeReference _createTypeRef_1 =
                         JvmModelGeneratorTest.this.references.createTypeRef(innerClassString);
                     JvmFormalParameter _parameter_1 =
                         JvmModelGeneratorTest.this.builder.toParameter(
                             it, "p2", _createTypeRef_1);
                     JvmModelGeneratorTest.this.builder.<JvmFormalParameter>operator_add(
                         _parameters_1, _parameter_1);
                     JvmModelGeneratorTest.this.builder.setBody(fooMethod, expression);
                   }
                 };
             JvmOperation _method =
                 JvmModelGeneratorTest.this.builder.toMethod(it, "foo", _typeForName, _function);
             JvmModelGeneratorTest.this.builder.<JvmOperation>operator_add(_members_2, _method);
           }
         };
     final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Outer", _function);
     Resource _eResource = expression.eResource();
     _eResource.eSetDeliver(false);
     Resource _eResource_1 = expression.eResource();
     EList<EObject> _contents = _eResource_1.getContents();
     this.builder.<JvmGenericType>operator_add(_contents, clazz);
     Resource _eResource_2 = expression.eResource();
     _eResource_2.eSetDeliver(true);
     InMemoryFileSystemAccess _inMemoryFileSystemAccess = new InMemoryFileSystemAccess();
     final InMemoryFileSystemAccess fsa = _inMemoryFileSystemAccess;
     Resource _eResource_3 = expression.eResource();
     this.generator.doGenerate(_eResource_3, fsa);
     Map<String, CharSequence> _files = fsa.getFiles();
     String _identifier = clazz.getIdentifier();
     String _replace = _identifier.replace(".", "/");
     String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace);
     String _plus_1 = (_plus + ".java");
     CharSequence _get = _files.get(_plus_1);
     final String code = _get.toString();
     boolean _contains = code.contains("import");
     Assert.assertFalse(_contains);
     boolean _contains_1 = code.contains("java.lang.String foo");
     Assert.assertTrue(_contains_1);
     String _identifier_1 = clazz.getIdentifier();
     final Class<? extends Object> compiledClass =
         this.javaCompiler.compileToClass(_identifier_1, code);
     Resource _eResource_4 = expression.eResource();
     EList<EObject> _contents_1 = _eResource_4.getContents();
     EObject _head = IterableExtensions.<EObject>head(_contents_1);
     this.helper.assertNoErrors(_head);
     Class<? extends Object>[] _declaredClasses = compiledClass.getDeclaredClasses();
     int _size =
         ((List<Class<? extends Object>>) Conversions.doWrapArray(_declaredClasses)).size();
     Assert.assertEquals(2, _size);
     Class<? extends Object>[] _declaredClasses_1 = compiledClass.getDeclaredClasses();
     Class<? extends Object> _head_1 =
         IterableExtensions.<Class<? extends Object>>head(
             ((Iterable<Class<? extends Object>>) Conversions.doWrapArray(_declaredClasses_1)));
     Class<? extends Object>[] _declaredClasses_2 = compiledClass.getDeclaredClasses();
     Class<? extends Object> _last =
         IterableExtensions.<Class<? extends Object>>last(
             ((Iterable<Class<? extends Object>>) Conversions.doWrapArray(_declaredClasses_2)));
     Method _method = compiledClass.getMethod("foo", _head_1, _last);
     Assert.assertNotNull(_method);
   } catch (Exception _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 @Test
 public void testAnnotation_2() {
   try {
     final XExpression expression = this.expression("typeof(String)", false);
     final Procedure1<JvmAnnotationType> _function =
         new Procedure1<JvmAnnotationType>() {
           public void apply(final JvmAnnotationType it) {
             EList<JvmMember> _members = it.getMembers();
             JvmWildcardTypeReference _wildCard = JvmModelGeneratorTest.this.references.wildCard();
             JvmTypeReference _typeForName =
                 JvmModelGeneratorTest.this.references.getTypeForName(
                     Class.class, expression, _wildCard);
             final Procedure1<JvmOperation> _function =
                 new Procedure1<JvmOperation>() {
                   public void apply(final JvmOperation it) {
                     JvmModelGeneratorTest.this.builder.setBody(it, expression);
                   }
                 };
             JvmOperation _method =
                 JvmModelGeneratorTest.this.builder.toMethod(
                     expression, "value", _typeForName, _function);
             JvmModelGeneratorTest.this.builder.<JvmOperation>operator_add(_members, _method);
             EList<JvmMember> _members_1 = it.getMembers();
             JvmTypeReference _typeForName_1 =
                 JvmModelGeneratorTest.this.references.getTypeForName(int.class, expression);
             final Procedure1<JvmOperation> _function_1 =
                 new Procedure1<JvmOperation>() {
                   public void apply(final JvmOperation it) {}
                 };
             JvmOperation _method_1 =
                 JvmModelGeneratorTest.this.builder.toMethod(
                     expression, "otherValue", _typeForName_1, _function_1);
             JvmModelGeneratorTest.this.builder.<JvmOperation>operator_add(_members_1, _method_1);
           }
         };
     final JvmAnnotationType clazz =
         this.builder.toAnnotationType(expression, "my.test.Foo", _function);
     Resource _eResource = expression.eResource();
     final Class<? extends Object> compiledClass = this.compile(_eResource, clazz);
     boolean _isAnnotation = compiledClass.isAnnotation();
     Assert.assertTrue(_isAnnotation);
     Method[] _methods = compiledClass.getMethods();
     final Function1<Method, Boolean> _function_1 =
         new Function1<Method, Boolean>() {
           public Boolean apply(final Method it) {
             String _name = it.getName();
             boolean _equals = Objects.equal(_name, "value");
             return Boolean.valueOf(_equals);
           }
         };
     Method _findFirst =
         IterableExtensions.<Method>findFirst(
             ((Iterable<Method>) Conversions.doWrapArray(_methods)), _function_1);
     Object _defaultValue = _findFirst.getDefaultValue();
     Assert.assertEquals(String.class, _defaultValue);
     Method[] _methods_1 = compiledClass.getMethods();
     final Function1<Method, Boolean> _function_2 =
         new Function1<Method, Boolean>() {
           public Boolean apply(final Method it) {
             String _name = it.getName();
             boolean _equals = Objects.equal(_name, "otherValue");
             return Boolean.valueOf(_equals);
           }
         };
     Method _findFirst_1 =
         IterableExtensions.<Method>findFirst(
             ((Iterable<Method>) Conversions.doWrapArray(_methods_1)), _function_2);
     Object _defaultValue_1 = _findFirst_1.getDefaultValue();
     Assert.assertNull(_defaultValue_1);
   } catch (Exception _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
Beispiel #26
0
 public static TypeReference typeRef(final Class<?> clazz, final TypeReference... arguments) {
   return new TypeReference(clazz, (List<TypeReference>) Conversions.doWrapArray(arguments));
 }
Beispiel #27
0
 public static TypeReference typeRef(final String name, final TypeReference... arguments) {
   return new TypeReference(name, (List<TypeReference>) Conversions.doWrapArray(arguments));
 }
 public Library createOrGetXtendJavaLibrary(
     final ModifiableRootModel rootModel, final Module module) {
   LibraryTablesRegistrar _instance = LibraryTablesRegistrar.getInstance();
   Project _project = module.getProject();
   LibraryTable _libraryTable = _instance.getLibraryTable(_project);
   Library[] _libraries = _libraryTable.getLibraries();
   LibraryTablesRegistrar _instance_1 = LibraryTablesRegistrar.getInstance();
   LibraryTable _libraryTable_1 = _instance_1.getLibraryTable();
   Library[] _libraries_1 = _libraryTable_1.getLibraries();
   final Iterable<Library> libraryTable =
       Iterables.<Library>concat(
           ((Iterable<? extends Library>) Conversions.doWrapArray(_libraries)),
           ((Iterable<? extends Library>) Conversions.doWrapArray(_libraries_1)));
   final Function1<Library, Boolean> _function =
       new Function1<Library, Boolean>() {
         @Override
         public Boolean apply(final Library it) {
           String _name = it.getName();
           boolean _startsWith = false;
           if (_name != null) {
             _startsWith = _name.startsWith(XtendLibraryDescription.XTEND_LIBRARY_NAME);
           }
           return Boolean.valueOf(_startsWith);
         }
       };
   final Iterable<Library> xtendLibs = IterableExtensions.<Library>filter(libraryTable, _function);
   boolean _isEmpty = IterableExtensions.isEmpty(xtendLibs);
   boolean _not = (!_isEmpty);
   if (_not) {
     final Function1<Library, Boolean> _function_1 =
         new Function1<Library, Boolean>() {
           @Override
           public Boolean apply(final Library it) {
             String _name = it.getName();
             return Boolean.valueOf(
                 Objects.equal(_name, XtendLibraryDescription.XTEND_LIBRARY_NAME));
           }
         };
     boolean _exists = IterableExtensions.<Library>exists(xtendLibs, _function_1);
     if (_exists) {
       final Function1<Library, Boolean> _function_2 =
           new Function1<Library, Boolean>() {
             @Override
             public Boolean apply(final Library it) {
               String _name = it.getName();
               return Boolean.valueOf(
                   Objects.equal(_name, XtendLibraryDescription.XTEND_LIBRARY_NAME));
             }
           };
       return IterableExtensions.<Library>findFirst(xtendLibs, _function_2);
     } else {
       return IterableExtensions.<Library>head(xtendLibs);
     }
   } else {
     final NewLibraryConfiguration libDescr = this.xtendLibDescr.createLibraryDescription();
     LibraryTable _moduleLibraryTable = rootModel.getModuleLibraryTable();
     final LibraryTable.ModifiableModel model = _moduleLibraryTable.getModifiableModel();
     String _defaultLibraryName = libDescr.getDefaultLibraryName();
     final Library createdLib = model.createLibrary(_defaultLibraryName);
     final Library.ModifiableModel libModel = createdLib.getModifiableModel();
     HashMap<OrderRootType, List<String>> _libraryRoots = this.xtendLibDescr.libraryRoots();
     final Procedure2<OrderRootType, List<String>> _function_3 =
         new Procedure2<OrderRootType, List<String>>() {
           @Override
           public void apply(final OrderRootType type, final List<String> roots) {
             final Procedure1<String> _function =
                 new Procedure1<String>() {
                   @Override
                   public void apply(final String it) {
                     libModel.addRoot(it, type);
                   }
                 };
             IterableExtensions.<String>forEach(roots, _function);
           }
         };
     MapExtensions.<OrderRootType, List<String>>forEach(_libraryRoots, _function_3);
     libModel.commit();
     model.commit();
     return createdLib;
   }
 }
Beispiel #29
0
 protected CharSequence internalToHtmlParagraph(final Object it) {
   CharSequence _switchResult = null;
   boolean matched = false;
   if (!matched) {
     if (it instanceof TextOrMarkup) {
       final TextOrMarkup _textOrMarkup = (TextOrMarkup) it;
       matched = true;
       EList<EObject> _contents = _textOrMarkup.getContents();
       CharSequence _internalToHtmlParagraph = this.internalToHtmlParagraph(_contents);
       _switchResult = _internalToHtmlParagraph;
     }
   }
   if (!matched) {
     if (it instanceof List) {
       final List<EObject> _list = (List<EObject>) it;
       matched = true;
       final Function1<EObject, CharSequence> _function =
           new Function1<EObject, CharSequence>() {
             public CharSequence apply(final EObject it) {
               CharSequence _internalToHtmlParagraph =
                   HtmlExtensions.this.internalToHtmlParagraph(it);
               return _internalToHtmlParagraph;
             }
           };
       List<CharSequence> _map = ListExtensions.<EObject, CharSequence>map(_list, _function);
       String _join = IterableExtensions.join(_map);
       _switchResult = _join;
     }
   }
   if (!matched) {
     if (it instanceof TextPart) {
       final TextPart _textPart = (TextPart) it;
       matched = true;
       String _xblockexpression = null;
       {
         String _text = _textPart.getText();
         String _quote = this.quote(_text);
         String[] _split = _quote.split("^\\s*$");
         final String[] paragraphs = _split;
         final String[] _typeConverted_paragraphs = (String[]) paragraphs;
         final Function1<String, Boolean> _function =
             new Function1<String, Boolean>() {
               public Boolean apply(final String it) {
                 boolean _isEmpty = it.isEmpty();
                 boolean _operator_not = BooleanExtensions.operator_not(_isEmpty);
                 return Boolean.valueOf(_operator_not);
               }
             };
         Iterable<String> _filter =
             IterableExtensions.<String>filter(
                 ((Iterable<String>) Conversions.doWrapArray(_typeConverted_paragraphs)),
                 _function);
         StringConcatenation _builder = new StringConcatenation();
         _builder.append("</p>");
         _builder.newLine();
         _builder.append("<p>");
         _builder.newLine();
         String _join = IterableExtensions.join(_filter, _builder);
         _xblockexpression = (_join);
       }
       _switchResult = _xblockexpression;
     }
   }
   if (!matched) {
     if (it instanceof CodeBlock) {
       final CodeBlock _codeBlock = (CodeBlock) it;
       matched = true;
       CharSequence _internalToHtml = this.internalToHtml(_codeBlock, true);
       _switchResult = _internalToHtml;
     }
   }
   if (!matched) {
     CharSequence _html = this.toHtml(it);
     _switchResult = _html;
   }
   return _switchResult;
 }
Beispiel #30
0
 /** @deprecated this method is available for backwards compatibility reasons */
 @Deprecated
 public static TypeReference guessTypeRef(final String name, final TypeReference... arguments) {
   return new TypeReference(name, (List<TypeReference>) Conversions.doWrapArray(arguments), false);
 }