Java 类org.eclipse.xtext.ui.editor.XtextEditor 实例源码

项目:n4js    文件:EditorsUtil.java   
/**
 * Obtains or opens {@link XtextEditor} for provided {@link Resource} and editor id. Upon activation or opening of
 * the editor waits a moment for editor to become active.
 *
 * @param uri
 *            URI to be opened
 * @param editorExtensionID
 *            {String} defining the id of the editor extension to use
 * @return {@link Optional} instance of {@link XtextEditor} for given {@link Resource}.
 */
public static final Optional<XtextEditor> openXtextEditor(URI uri, String editorExtensionID) {

    String platformStr = uri.toString().replace("platform:/resource/", "");
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformStr));

    Optional<IWorkbenchPage> page = getActivePage();
    Optional<IEditorPart> internalFileEditor = getFileEditor(file, page.get(), editorExtensionID);

    if ((page.isPresent() && internalFileEditor.isPresent()) == false) {
        logger.warn("Cannot obtain editor components for " + file.getRawLocationURI());
        return Optional.empty();
    }

    IEditorPart ieditorPart = internalFileEditor.get();
    if (ieditorPart instanceof XtextEditor == false) {
        logger.warn("cannot obtain Xtext editor for file " + file.getRawLocation());
        return Optional.empty();
    }

    waitForEditorToBeActive(ieditorPart, page.get());

    return Optional.ofNullable((XtextEditor) ieditorPart);
}
项目:n4js    文件:N4JSAllContainersState.java   
private void tryValidateManifestInEditor(final IResourceDelta delta) {
    if (isWorkbenchRunning()) {
        Display.getDefault().asyncExec(() -> {
            final IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
            if (null != window) {
                final IWorkbenchPage page = window.getActivePage();
                for (final IEditorReference editorRef : page.getEditorReferences()) {
                    if (isEditorForResource(editorRef, delta.getResource())) {
                        final IWorkbenchPart part = editorRef.getPart(true);
                        if (part instanceof XtextEditor) {
                            editorCallback.afterSave((XtextEditor) part);
                            return;
                        }
                    }
                }
            }
        });
    }
}
项目:n4js    文件:OwnResourceValidatorAwareValidatingEditorCallback.java   
private ValidationJob newValidationJob(final XtextEditor editor) {

        final IXtextDocument document = editor.getDocument();
        final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();

        final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
        final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
        final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);

        final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(
                new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider),
                new MarkerIssueProcessor(editor.getResource(), markerCreator, markerTypeProvider));

        return editor.getDocument().modify(resource -> {
            final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
            final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
            return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
        });
    }
项目:lcdsl    文件:AbstractLaunchConfigGeneratorHandler.java   
protected LaunchConfig getLaunchConfigFromEditor(ExecutionEvent event) {
    XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event);
    if (activeXtextEditor == null) {
        return null;
    }
    final ITextSelection selection = (ITextSelection) activeXtextEditor.getSelectionProvider().getSelection();
    return activeXtextEditor.getDocument().priorityReadOnly(new IUnitOfWork<LaunchConfig, XtextResource>() {

        @Override
        public LaunchConfig exec(XtextResource xTextResource) throws Exception {
            EObject lc = eObjectAtOffsetHelper.resolveContainedElementAt(xTextResource, selection.getOffset());
            return findParentLaunchConfig(lc);
        }

    });
}
项目:dsl-devkit    文件:EObjectContentProvider.java   
/**
 * Retrieve the object's values for the given EAttributes.
 * 
 * @param attributes
 *          the EAttributes
 * @return List<Pair<EAttribute, Object>> the attribute+values - possibly containing null entries
 */
private List<AttributeValuePair> valuesForAttributes(final EList<EAttribute> attributes) {
  final URI elementUri = xtextElementSelectionListener.getSelectedElementUri();
  XtextEditor editor = xtextElementSelectionListener.getEditor();
  if (editor != null && elementUri != null) {
    return editor.getDocument().readOnly(new IUnitOfWork<List<AttributeValuePair>, XtextResource>() {
      @SuppressWarnings("PMD.SignatureDeclareThrowsException")
      public List<AttributeValuePair> exec(final XtextResource state) throws Exception {
        final EObject eObject = state.getEObject(elementUri.fragment());
        List<AttributeValuePair> pairs = Lists.transform(attributes, new Function<EAttribute, AttributeValuePair>() {
          public AttributeValuePair apply(final EAttribute from) {
            return new AttributeValuePair(from, eObject.eGet(from));
          }
        });
        return pairs;
      }
    });
  }
  return newArrayList();
}
项目:dsl-devkit    文件:ASMDEditorUtils.java   
/** {@inheritDoc} */
public XtextEditor getActiveXtextEditor() {
  IWorkbench workbench = PlatformUI.getWorkbench();
  IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
  if (workbenchWindow == null) {
    return null;
  }
  IWorkbenchPage activePage = workbenchWindow.getActivePage();
  if (activePage == null) {
    return null;
  }
  IEditorPart activeEditor = activePage.getActiveEditor();
  if (activeEditor instanceof XtextEditor) {
    return (XtextEditor) activeEditor;
    // return null;
  }
  // XtextEditor xtextEditor = (XtextEditor) activeEditor.getAdapter(XtextEditor.class);
  // return xtextEditor;
  return null;
}
项目:dsl-devkit    文件:EObjectContentProviderTest.java   
/**
 * Mocks XtextEditor and XtextElementSelectionListener to return an element selection that has:
 * - given EAttribute with a specific value (AttributeValuePair)
 * - given EStructuralFeature
 * - given EOperation.
 *
 * @param attributeValuePair
 *          EAttribute with a specific value
 * @param feature
 *          the EStructuralFeature
 * @param operation
 *          the EOperation
 * @return the EClass of the "selected" element
 */
@SuppressWarnings("unchecked")
private EClass mockSelectedElement(final AttributeValuePair attributeValuePair, final EStructuralFeature feature, final EOperation operation) {
  EClass mockSelectionEClass = mock(EClass.class);
  when(mockSelectionListener.getSelectedElementType()).thenReturn(mockSelectionEClass);
  // Mockups for returning AttributeValuePair
  URI elementUri = URI.createURI("");
  when(mockSelectionListener.getSelectedElementUri()).thenReturn(elementUri);
  XtextEditor mockEditor = mock(XtextEditor.class);
  when(mockSelectionListener.getEditor()).thenReturn(mockEditor);
  IXtextDocument mockDocument = mock(IXtextDocument.class);
  when(mockEditor.getDocument()).thenReturn(mockDocument);
  when(mockDocument.<ArrayList<AttributeValuePair>> readOnly(any(IUnitOfWork.class))).thenReturn(newArrayList(attributeValuePair));
  // Mockups for returning EOperation
  BasicEList<EOperation> mockEOperationsList = new BasicEList<EOperation>();
  mockEOperationsList.add(operation);
  when(mockSelectionEClass.getEAllOperations()).thenReturn(mockEOperationsList);
  // Mockups for returning EStructuralFeature
  BasicEList<EStructuralFeature> mockEStructuralFeatureList = new BasicEList<EStructuralFeature>();
  mockEStructuralFeatureList.add(feature);
  mockEStructuralFeatureList.add(attributeValuePair.getAttribute());
  when(mockSelectionEClass.getEAllStructuralFeatures()).thenReturn(mockEStructuralFeatureList);
  return mockSelectionEClass;
}
项目:dsl-devkit    文件:FixedHighlightingReconciler.java   
private Display getDisplay() {
  XtextEditor editor = this.editor;
  if (editor == null) {
    return null;
  }

  IWorkbenchPartSite site = editor.getSite();
  if (site == null) {
    return null;
  }

  Shell shell = site.getShell();
  if (shell == null || shell.isDisposed()) {
    return null;
  }

  Display display = shell.getDisplay();
  if (display == null || display.isDisposed()) {
    return null;
  }
  return display;
}
项目:dsl-devkit    文件:FixedHighlightingReconciler.java   
/**
 * Install this reconciler on the given editor and presenter.
 *
 * @param editor
 *          the editor
 * @param sourceViewer
 *          the source viewer
 * @param presenter
 *          the highlighting presenter
 */
@Override
public void install(final XtextEditor editor, final XtextSourceViewer sourceViewer, final HighlightingPresenter presenter) {
  synchronized (fReconcileLock) {
    cleanUpAfterReconciliation = false; // prevents a potentially already running reconciliation process to clean up after itself
  }
  this.presenter = presenter;
  this.editor = editor;
  this.sourceViewer = sourceViewer;
  if (calculator != null) {
    if (editor == null) {
      ((IXtextDocument) sourceViewer.getDocument()).addModelListener(this);
    } else if (editor.getDocument() != null) {
      editor.getDocument().addModelListener(this);
    }

    sourceViewer.addTextInputListener(this);
  }
  refresh();
}
项目:z80editor    文件:Z80InstructionHelpView.java   
private void loadCycleInfo(final int offset, final int length, XtextEditor editor, final IDocument doc) {
    final ILocationInFileProvider locationInFileProvider = Z80Activator.getInstance().getInjector(Z80Activator.ORG_EFRY_Z80EDITOR_Z80).getInstance(ILocationInFileProvider.class);

    editor.getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() {

        @Override
        public Boolean exec(XtextResource state) throws Exception {
            Z80OperationTypeWalker operationInstructions = new Z80OperationTypeWalker(state, locationInFileProvider, offset, offset + length);

            Z80CycleCalculator calc = new Z80CycleCalculator();

            for (Operation o : operationInstructions) {
                ITextRegion region = locationInFileProvider.getFullTextRegion(o);
                calc.addOperation(o, doc.get(region.getOffset(), region.getLength()));
            }
            label.setText(calc.getHtmlFormattedText());
            return Boolean.TRUE;
        }
    });
}
项目:bts    文件:XtextPluginImages.java   
private static final void initializeImageMaps() {
        if(imagesInitialized)
            return;

        annotationImagesFixable.put(XtextEditor.ERROR_ANNOTATION_TYPE, get(OBJ_FIXABLE_ERROR));
        annotationImagesFixable.put(XtextEditor.WARNING_ANNOTATION_TYPE, get(OBJ_FIXABLE_WARNING));
        annotationImagesFixable.put(XtextEditor.INFO_ANNOTATION_TYPE, get(OBJ_FIXABLE_INFO));

        //XXX cp uncommented
//      ISharedImages sharedImages= PlatformUI.getWorkbench().getSharedImages();
//      Image error = sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
//      Image warning = sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
//      Image info = sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
        annotationImagesNonFixable.put(XtextEditor.ERROR_ANNOTATION_TYPE, get(OBJ_DESC_ERROR));
        annotationImagesNonFixable.put(XtextEditor.WARNING_ANNOTATION_TYPE, get(OBJ_DESC_EXCLAMATION));
        annotationImagesNonFixable.put(XtextEditor.INFO_ANNOTATION_TYPE, get(OBJ_DESC_INFORMATION));

        Display display = Display.getCurrent();
        annotationImagesDeleted.put(XtextEditor.ERROR_ANNOTATION_TYPE, new Image(display, get(OBJ_DESC_ERROR), SWT.IMAGE_GRAY));
        annotationImagesDeleted.put(XtextEditor.WARNING_ANNOTATION_TYPE, new Image(display, get(OBJ_DESC_EXCLAMATION), SWT.IMAGE_GRAY));
        annotationImagesDeleted.put(XtextEditor.INFO_ANNOTATION_TYPE, new Image(display, get(OBJ_DESC_INFORMATION), SWT.IMAGE_GRAY));

        imagesInitialized = true;
    }
项目:bts    文件:ShowQuickOutlineActionHandler.java   
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
    if (xtextEditor != null) {
        final IXtextDocument document = xtextEditor.getDocument();
        document.readOnly(new IUnitOfWork.Void<XtextResource>()  {
            @Override
            public void process(XtextResource state) throws Exception {
                final QuickOutlinePopup quickOutlinePopup = createPopup(xtextEditor.getEditorSite().getShell());
                quickOutlinePopup.setEditor(xtextEditor);
                quickOutlinePopup.setInput(document);
                quickOutlinePopup.setEvent((Event) event.getTrigger());
                quickOutlinePopup.open();
            }
        });
    }
    return null;
}
项目:bts    文件:FindReferencesHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
        if (editor != null) {
            final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
            editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
                @Override
                public void process(XtextResource state) throws Exception {
                    EObject target = eObjectAtOffsetHelper.resolveElementAt(state, selection.getOffset());
                    findReferences(target);
                }
            });
        }
    } catch (Exception e) {
        LOG.error(Messages.FindReferencesHandler_3, e);
    }
    return null;
}
项目:bts    文件:HighlightingReconciler.java   
private Display getDisplay() {
    XtextEditor editor = this.editor;
    if (editor == null){
        if(sourceViewer != null)
            return sourceViewer.getControl().getDisplay();
        return null;
    }
    IWorkbenchPartSite site = editor.getSite();
    if (site == null)
        return null;

    Shell shell = site.getShell();
    if (shell == null || shell.isDisposed())
        return null;

    Display display = shell.getDisplay();
    if (display == null || display.isDisposed())
        return null;
    return display;
}
项目:bts    文件:OpenDeclarationHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
    if (xtextEditor != null) {
        ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection();

        IRegion region = new Region(selection.getOffset(), selection.getLength());

        ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer();

        IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false);
        if (hyperlinks != null && hyperlinks.length > 0) {
            IHyperlink hyperlink = hyperlinks[0];
            hyperlink.open();
        }
    }       
    return null;
}
项目:bts    文件:MarkerResolutionGenerator.java   
public IMarkerResolution[] getResolutions(IMarker marker) {
    final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
    try {
        if(!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION))
            return emptyResult;
    } catch (CoreException e) {
        return emptyResult;
    }
    if(!languageResourceHelper.isLanguageResource(marker.getResource())) {
        return emptyResult;
    }
    XtextEditor editor = getEditor(marker.getResource());
    if(editor == null)
        return emptyResult;

    IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
    if(annotationModel != null && !isMarkerStillValid(marker, annotationModel))
        return emptyResult;

    final Iterable<IssueResolution> resolutions = getResolutions(getIssueUtil().createIssue(marker), editor.getDocument());
    return getAdaptedResolutions(Lists.newArrayList(resolutions));
}
项目:bts    文件:EditorCopyQualifiedNameHandler.java   
@Override
protected String getQualifiedName(ExecutionEvent event) {
    XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event);
    if (activeXtextEditor == null) {
        return null;
    }
    final ITextSelection selection = getTextSelection(activeXtextEditor);
    return activeXtextEditor.getDocument().readOnly(new IUnitOfWork<String, XtextResource>() {

        public String exec(XtextResource xTextResource) throws Exception {
            EObject context = getContext(selection, xTextResource);
            EObject selectedElement = getSelectedName(selection, xTextResource);
            return getQualifiedName(selectedElement, context);
        }

    });
}
项目:bts    文件:SyncUtil.java   
public void reconcileAllEditors(IWorkbench workbench, final boolean saveAll, IProgressMonitor monitor) {
    SubMonitor pm0 = SubMonitor.convert(monitor, workbench.getWorkbenchWindowCount());
    for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
        SubMonitor pm1 = pm0.newChild(1).setWorkRemaining(window.getPages().length);
        for (IWorkbenchPage page : window.getPages()) {
            SubMonitor pm2 = pm1.newChild(1).setWorkRemaining(2 * page.getEditorReferences().length);
            for (IEditorReference editorReference : page.getEditorReferences()) {
                if (pm2.isCanceled())
                    return;
                IEditorPart editor = editorReference.getEditor(false);
                if (editor != null) {
                    if (editor instanceof XtextEditor)
                        waitForReconciler((XtextEditor) editor);
                    if (editor.isDirty() && saveAll)
                        editor.doSave(pm2.newChild(1));
                }
                pm2.worked(1);
            }
        }
    }
}
项目:bts    文件:RenameRefactoringController.java   
protected String getOriginalName(final XtextEditor xtextEditor) {
    return xtextEditor.getDocument().readOnly(new IUnitOfWork<String, XtextResource>() {
        public String exec(XtextResource state) throws Exception {
            try {
                EObject targetElement = state.getResourceSet().getEObject(renameElementContext.getTargetElementURI(),
                    false);
                IRenameStrategy.Provider strategyProvider = globalServiceProvider.findService(targetElement,
                        IRenameStrategy.Provider.class);
                if (strategyProvider != null) {
                    IRenameStrategy strategy = strategyProvider.get(targetElement, renameElementContext);
                    if (strategy != null)
                        return strategy.getOriginalName();
                }
            } catch(NoSuchStrategyException e) {
                // null
            }
            return null;
        }
    });
}
项目:gama    文件:GamlEditorTickUpdater.java   
@Override
protected void updateEditorImage(final XtextEditor editor) {
    Severity severity = null;
    //
    // try {
    severity = getSeverity(editor);
    //
    // } catch (ResourceException e) {
    // // do nothing, emitted when a marker cannot be found
    // }
    ImageDescriptor descriptor = null;
    if (severity == null || severity == Severity.INFO) {
        descriptor = GamaIcons.create(IGamaIcons.OVERLAY_OK).descriptor();
    } else if (severity == Severity.ERROR) {
        descriptor = GamaIcons.create("overlay.error2").descriptor();
    } else if (severity == Severity.WARNING) {
        descriptor = GamaIcons.create("overlay.warning2").descriptor();
    } else {
        super.updateEditorImage(editor);
        return;
    }
    final DecorationOverlayIcon decorationOverlayIcon = new DecorationOverlayIcon(editor.getDefaultImage(),
            descriptor, IDecoration.BOTTOM_LEFT);
    scheduleUpdateEditor(decorationOverlayIcon);

}
项目:CooperateModelingEnvironment    文件:UMLReferencingElementSelectionTester.java   
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof XtextEditor)) {
        return false;
    }

    XtextEditor editor = (XtextEditor) receiver;
    ISelection selection = editor.getSelectionProvider().getSelection();
    if (!(selection instanceof ITextSelection)) {
        return false;
    }
    ITextSelection textSelection = (ITextSelection) selection;

    Optional<EObject> foundEObject = EditorHandlingUtils.findEObjectAtPosition(editor, textSelection);
    return foundEObject.filter(UMLReferencingElement.class::isInstance).map(UMLReferencingElement.class::cast)
            .filter(e -> !RenameUMLElementRefactoringFilterRegistry.getInstance().getFilters().stream()
                    .anyMatch(f -> f.prohibitRefactoring(e)))
            .map(UMLReferencingElement::getReferencedElement).map(NamedElement.class::isInstance).orElse(false);
}
项目:slr-toolkit    文件:TaxonomyCheckboxListView.java   
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (part instanceof XtextEditor && !selection.isEmpty()) {
        final XtextEditor editor = (XtextEditor) part;
        final IXtextDocument document = editor.getDocument();

        document.readOnly(new IUnitOfWork.Void<XtextResource>() {
            @Override
            public void process(XtextResource resource) throws Exception {
                IParseResult parseResult = resource.getParseResult();
                if (parseResult != null) {
                    ICompositeNode root = parseResult.getRootNode();
                    EObject taxonomy = NodeModelUtils.findActualSemanticObjectFor(root);
                    if (taxonomy instanceof Model) {
                        ModelRegistryPlugin.getModelRegistry().setActiveTaxonomy((Model) taxonomy);
                    }
                }
            }
        });
    }
}
项目:sadlos2    文件:SadlEditorCallback.java   
@Override
public void beforeDispose(XtextEditor editor) {
    super.beforeDispose(editor);
    try {
        deleteEditorOpenIndicatorFile(editor);
        if (visitor != null) {
            SadlModelManager smm = null;
            URI uri = null;
            IPath prjLoc = getEditorProject(editor);
            uri = URI.createURI(new SadlUtils().fileNameToFileUrl(prjLoc.toOSString()));
            URI prjUri = ResourceManager.getProjectUri(uri);
            smm = visitor.get(prjUri);
            if (smm != null) {
                IConfigurationManagerForIDE configMgr = smm.getConfigurationMgr(ResourceManager.getOwlModelsFolder(uri));
                configMgr.saveConfiguration();
                configMgr.saveOntPolicyFile();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:antlr4ide    文件:RailroadSynchronizer.java   
@Override
public void partActivated(final IWorkbenchPart part) {
  if (part instanceof XtextEditor) {
    XtextEditor xtextEditor = (XtextEditor) part;
    IXtextDocument xtextDocument = xtextEditor.getDocument();
    if (xtextDocument != lastActiveDocument) {
      selectionLinker.setXtextEditor(xtextEditor);
      final IFigure contents = xtextDocument.readOnly(new IUnitOfWork<IFigure, XtextResource>() {
        @Override
        public IFigure exec(final XtextResource resource) throws Exception {
          return createFigure(resource);
        }
      });
      if (contents != null) {
        view.setContents(contents);
        if (lastActiveDocument != null) {
          lastActiveDocument.removeModelListener(this);
        }
        lastActiveDocument = xtextDocument;
        lastActiveDocument.addModelListener(this);
      }
    }
  }
}
项目:smaccm    文件:AadlAction.java   
public void determineNature(XtextEditor editor, Logger log) {
   // let's see what project this is.
   IProject project = editor.getResource().getProject(); 
   System.out.println(project);
   try {
      IProjectDescription description = project.getDescription();
      String[] natures = description.getNatureIds();
      boolean aadlNature = false; 
      for (String nature: natures) {
         if (nature.equalsIgnoreCase("org.osate.core.aadlnature")) {
            aadlNature = true;
         }
      }
      if (!aadlNature) {
         log.warn("WARNING: Project does not have aadl nature; this will likely fail during compilation because of missing property sets.  Please create a project with aadl nature."); 
      }
   } catch (Exception e) {
      log.warn("WARNING: Unable to determine nature of project; if it does not have aadl nature it will likely fail during compilation.  Please create a project with aadl nature."); 

   }
}
项目:smaccm    文件:AadlHandler.java   
public void determineNature(XtextEditor editor, Logger log) {
   // let's see what project this is.
   IProject project = editor.getResource().getProject(); 
   System.out.println(project);
   try {
      IProjectDescription description = project.getDescription();
      String[] natures = description.getNatureIds();
      boolean aadlNature = false; 
      for (String nature: natures) {
         if (nature.equalsIgnoreCase("org.osate.core.aadlnature")) {
            aadlNature = true;
         }
      }
      if (!aadlNature) {
         log.warn("WARNING: Project does not have aadl nature; this will likely fail during compilation because of missing property sets.  Please create a project with aadl nature."); 
      } else {
      }
   } catch (Exception e) {
      log.warn("WARNING: Unable to determine nature of project; if it does not have aadl nature it will likely fail during compilation.  Please create a project with aadl nature."); 
   }
}
项目:smaccm    文件:AadlHandler.java   
private URI getSelectionURI(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            EObjectNode node = (EObjectNode) iss.getFirstElement();
            return node.getEObjectURI();
        }
    } else if (currentSelection instanceof TextSelection) {
        // Selection may be stale, get latest from editor
        XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
        TextSelection ts = (TextSelection) xtextEditor.getSelectionProvider().getSelection();
        return xtextEditor.getDocument().readOnly(resource -> {
            EObject e = new EObjectAtOffsetHelper().resolveContainedElementAt(resource, ts.getOffset());
            return EcoreUtil2.getURI(e);
        });
    }
    return null;
}
项目:n4js    文件:AbstractBuilderParticipantTest.java   
/***/
protected XtextEditor openAndGetXtextEditor(final IFile file1, final IWorkbenchPage page) {
    IEditorPart fileEditor = getFileEditor(file1, page);
    assertTrue(fileEditor instanceof XtextEditor);
    XtextEditor fileXtextEditor = (XtextEditor) fileEditor;
    return fileXtextEditor;
}
项目:n4js    文件:AbstractBuilderParticipantTest.java   
/**
 * Will only return parse errors, not validation errors!
 */
protected List<Resource.Diagnostic> getEditorErrors(XtextEditor fileXtextEditor) {
    return fileXtextEditor.getDocument().readOnly(new IUnitOfWork<List<Diagnostic>, XtextResource>() {

        @Override
        public List<Resource.Diagnostic> exec(XtextResource state) throws Exception {
            EcoreUtil.resolveAll(state);
            return state.getErrors();
        }
    });
}
项目:n4js    文件:AbstractBuilderParticipantTest.java   
/**
 * Returns validation errors in given Xtext editor.
 */
protected List<Issue> getEditorValidationErrors(XtextEditor editor) {
    return editor.getDocument().readOnly(new IUnitOfWork<List<Issue>, XtextResource>() {
        @Override
        public List<Issue> exec(XtextResource state) throws Exception {
            final IResourceValidator validator = state.getResourceServiceProvider().getResourceValidator();
            return validator.validate(state, CheckMode.ALL, CancelIndicator.NullImpl);
        }
    });
}
项目:n4js    文件:AbstractBuilderParticipantTest.java   
/***/
protected void setDocumentContent(String context, IFile file, XtextEditor fileEditor, String newContent) {
    IDirtyStateManager dirtyStateManager = getInjector().getInstance(IDirtyStateManager.class);

    TestEventListener eventListener = new TestEventListener(context, file);
    dirtyStateManager.addListener(eventListener);

    setDocumentContent(fileEditor, newContent);

    eventListener.waitForFiredEvent();
    dirtyStateManager.removeListener(eventListener);
    waitForUpdateEditorJob();
}
项目:n4js    文件:AbstractBuilderParticipantTest.java   
/***/
protected void setDocumentContent(final XtextEditor xtextEditor, final String content) {
    Display.getCurrent().syncExec(new Runnable() {

        @Override
        public void run() {
            xtextEditor.getDocument().set(content);
        }
    });
}
项目:n4js    文件:N4JSEditorErrorTickUpdater.java   
@Override
public void afterCreatePartControl(XtextEditor xtextEditor) {
    editor = xtextEditor;
    if (xtextEditor instanceof N4JSEditor) {
        ((N4JSEditor) xtextEditor).setErrorTickUpdater(this);
    }
    super.afterCreatePartControl(xtextEditor);
}
项目:n4js    文件:N4JSEditorErrorTickUpdater.java   
@Override
public void beforeDispose(XtextEditor xtextEditor) {
    editor = null;
    if (xtextEditor instanceof N4JSEditor) {
        ((N4JSEditor) xtextEditor).setErrorTickUpdater(null);
    }
    super.beforeDispose(xtextEditor);
}
项目:n4js    文件:OrganizeImportsService.java   
/** Organize provided editor. */
public static void organizeImportsInEditor(XtextEditor editor, final Interaction interaction) {
    try {
        IResource resource = editor.getResource();
        DocumentImportsOrganizer imortsOrganizer = getOrganizeImports(resource);
        imortsOrganizer.organizeDocument(editor.getDocument(), interaction);
    } catch (RuntimeException re) {
        if (re.getCause() instanceof BreakException) {
            LOGGER.debug("user canceled");
        } else {
            LOGGER.warn("Unrecognized RT-exception", re);
        }

    }
}
项目:n4js    文件:OwnResourceValidatorAwareValidatingEditorCallback.java   
@Override
public void afterCreatePartControl(final XtextEditor editor) {
    super.afterCreatePartControl(editor);
    if (editor.isEditable()) {
        newValidationJob(editor).schedule();
    }
}
项目:n4js    文件:OwnResourceValidatorAwareValidatingEditorCallback.java   
@Override
public void afterSave(final XtextEditor editor) {
    super.afterSave(editor);
    if (editor.isEditable()) {
        newValidationJob(editor).schedule();
    }
}
项目:n4js    文件:ChangeManager.java   
private XtextEditor getEditor(URI uri) {
    // note: trimming fragment in previous line makes this more stable in case of changes to the
    // Xtext editor's contents (we are not interested in a particular element, just the editor)
    final URI uriToEditor = uri != null ? uri.trimFragment() : null;
    if (uriToEditor != null) {
        final IEditorPart editor = getEditorOpener().open(uriToEditor, false);
        if (editor instanceof XtextEditor)
            return (XtextEditor) editor;
    }
    return null;
}
项目:n4js    文件:AlwaysAddNatureCallback.java   
@Override
public void afterCreatePartControl(XtextEditor editor) {
    IResource resource = editor.getResource();
    if (resource != null && !toggleNature.hasNature(resource.getProject()) && resource.getProject().isAccessible()
            && !resource.getProject().isHidden()) {
        toggleNature.toggleNature(resource.getProject());
    }
}
项目:n4js    文件:InvalidatingHighlightingHelper.java   
@Override
public void propertyChange(PropertyChangeEvent event) {
    super.propertyChange(event);
    XtextEditor editor = myEditor;
    XtextSourceViewer sourceViewer = mySourceViewer;
    if (editor instanceof N4JSEditor && sourceViewer != null
            && event.getProperty().contains(".syntaxColorer.tokenStyles")) {
        ((N4JSEditor) editor).initializeViewerColors(sourceViewer);
        sourceViewer.invalidateTextPresentation();
    }
}