コード例 #1
0
  public static Object getAdapterFromActualObject(IResource actualObject2, Class adapter) {
    if (IProject.class.equals(adapter)
        || IResource.class.equals(adapter)
        || IFolder.class.equals(adapter)
        || IContainer.class.equals(adapter)
        || IFile.class.equals(adapter)
        || ResourceMapping.class.equals(adapter)
        || IFileStore.class.equals(adapter)) {
      return actualObject2.getAdapter(adapter);
    }

    try {
      if (IWatchExpressionFactoryAdapter2.class.equals(adapter)) {
        return actualObject2.getAdapter(adapter);
      }
    } catch (Throwable e) {
      // Ignore (not available in eclipse 3.2)
    }

    if (IDeferredWorkbenchAdapter.class.equals(adapter)
        || IWorkbenchAdapter2.class.equals(adapter)
        || IWorkbenchAdapter.class.equals(adapter)) {
      return null;
    }
    synchronized (lock) {
      if (!logged.contains(adapter)) {
        logged.add(adapter);
        // Only log once per session.
        Log.logInfo("Did not expect adapter request: " + adapter);
      }
    }
    return null;
  }
コード例 #2
0
 /** {@inheritDoc} */
 public ResourceMapping[] getMappings(
     final IResource resource,
     final ResourceMappingContext context,
     final IProgressMonitor monitor)
     throws CoreException {
   ResourceMapping[] result = null;
   if (resource instanceof IProject) {
     Option<ModelingProject> optionalModelingProject =
         ModelingProject.asModelingProject((IProject) resource);
     if (optionalModelingProject.some()) {
       result =
           new ResourceMapping[] {
             ModelingElementResourceMapping.create(optionalModelingProject.get())
           };
     }
   }
   if (result == null) {
     final Object adapted = resource.getAdapter(ResourceMapping.class);
     if (adapted instanceof ResourceMapping) {
       result = new ResourceMapping[] {(ResourceMapping) adapted};
     }
   }
   if (result == null) {
     result = new ResourceMapping[] {new ModelingResourceMapping(resource)};
   }
   return result;
 }
コード例 #3
0
  protected IJavaElement getInitialJavaElement(IStructuredSelection selection) {
    IJavaElement jelem = null;
    if (selection != null && !selection.isEmpty()) {
      Object selectedElement = selection.getFirstElement();
      if (selectedElement instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) selectedElement;

        jelem = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
        if (jelem == null || !jelem.exists()) {
          jelem = null;
          IResource resource = (IResource) adaptable.getAdapter(IResource.class);
          if (resource != null && resource.getType() != IResource.ROOT) {
            while (jelem == null && resource.getType() != IResource.PROJECT) {
              resource = resource.getParent();
              jelem = (IJavaElement) resource.getAdapter(IJavaElement.class);
            }
            if (jelem == null) {
              jelem = JavaCore.create(resource); // java project
            }
          }
        }
      }
    }

    return jelem;
  }
コード例 #4
0
 @Override
 public Image getImage(Object element) {
   if (element instanceof CPElement) {
     CPElement cpentry = (CPElement) element;
     ImageDescriptor imageDescriptor = getCPElementBaseImage(cpentry);
     if (imageDescriptor != null) {
       switch (cpentry.getStatus().getSeverity()) {
         case IStatus.WARNING:
           imageDescriptor =
               new CPListImageDescriptor(
                   imageDescriptor, CPListImageDescriptor.WARNING, SMALL_SIZE);
           break;
         case IStatus.ERROR:
           imageDescriptor =
               new CPListImageDescriptor(imageDescriptor, CPListImageDescriptor.ERROR, SMALL_SIZE);
           break;
       }
       if (cpentry.getInherited() != null) {
         imageDescriptor =
             new CPListImageDescriptor(
                 imageDescriptor, CPListImageDescriptor.PATH_INHERIT, SMALL_SIZE);
       }
       return fRegistry.get(imageDescriptor);
     }
   } else if (element instanceof CPElementAttribute) {
     String key = ((CPElementAttribute) element).getKey();
     if (key.equals(CPElement.SOURCEATTACHMENT)) {
       return fRegistry.get(
           CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_SOURCE_ATTACH_ATTRIB));
     } else if (key.equals(CPElement.EXCLUSION)) {
       return CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_EXCLUSION_FILTER_ATTRIB);
     }
   } else if (element instanceof IPathEntry) {
     return getImage(CPElement.createFromExisting((IPathEntry) element, null));
   } else if (element instanceof CPElementGroup) {
     switch (((CPElementGroup) element).getEntryKind()) {
       case IPathEntry.CDT_INCLUDE:
         return CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_INCLUDES_CONTAINER);
       case IPathEntry.CDT_MACRO:
         return fRegistry.get(fMacroIcon);
       case IPathEntry.CDT_INCLUDE_FILE:
       case IPathEntry.CDT_MACRO_FILE:
         return CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_INCLUDE);
       case IPathEntry.CDT_LIBRARY:
         return CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_LIBRARY);
       case -1:
         IResource res = ((CPElementGroup) element).getResource();
         IWorkbenchAdapter adapter = (IWorkbenchAdapter) res.getAdapter(IWorkbenchAdapter.class);
         ImageDescriptor imageDescriptor = adapter.getImageDescriptor(res);
         if (!res.exists()) {
           imageDescriptor =
               new CPListImageDescriptor(
                   imageDescriptor, CPListImageDescriptor.WARNING, SMALL_SIZE);
         }
         return fRegistry.get(imageDescriptor);
     }
   }
   return null;
 }
コード例 #5
0
  /**
   * Utility method to inspect a selection to find a Java element.
   *
   * @param selection the selection to be inspected
   * @return a Java element to be used as the initial selection, or <code>null</code>, if no Java
   *     element exists in the given selection
   */
  protected IJavaElement getInitialJavaElement(IStructuredSelection selection) {
    IJavaElement jelem = null;
    if (selection != null && !selection.isEmpty()) {
      Object selectedElement = selection.getFirstElement();
      if (selectedElement instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) selectedElement;

        jelem = adaptable.getAdapter(IJavaElement.class);
        if (jelem == null || !jelem.exists()) {
          jelem = null;
          IResource resource = adaptable.getAdapter(IResource.class);
          if (resource != null && resource.getType() != IResource.ROOT) {
            while (jelem == null && resource.getType() != IResource.PROJECT) {
              resource = resource.getParent();
              jelem = resource.getAdapter(IJavaElement.class);
            }
            if (jelem == null) {
              jelem = JavaCore.create(resource); // java project
            }
          }
        }
      }
    }
    if (jelem == null) {
      IWorkbenchPart part = JavaPlugin.getActivePage().getActivePart();
      if (part instanceof ContentOutline) {
        part = JavaPlugin.getActivePage().getActiveEditor();
      }

      if (part instanceof IViewPartInputProvider) {
        Object elem = ((IViewPartInputProvider) part).getViewPartInput();
        if (elem instanceof IJavaElement) {
          jelem = (IJavaElement) elem;
        }
      }
    }

    if (jelem == null || jelem.getElementType() == IJavaElement.JAVA_MODEL) {
      try {
        IJavaProject[] projects = JavaCore.create(getWorkspaceRoot()).getJavaProjects();
        if (projects.length == 1) {
          IClasspathEntry[] rawClasspath = projects[0].getRawClasspath();
          for (int i = 0; i < rawClasspath.length; i++) {
            if (rawClasspath[i].getEntryKind()
                == IClasspathEntry.CPE_SOURCE) { // add only if the project contains a source folder
              jelem = projects[0];
              break;
            }
          }
        }
      } catch (JavaModelException e) {
        JavaPlugin.log(e);
      }
    }
    return jelem;
  }
コード例 #6
0
  public static IFile getSelectedFile(IWorkbenchPage page) {
    if (null == page) return null;
    IFile file = null;
    ISelection selection = page.getSelection();

    if (selection instanceof ITextSelection) {
      IEditorInput editorInput = page.getActiveEditor().getEditorInput();
      if (editorInput instanceof IFileEditorInput) {
        file = ((IFileEditorInput) editorInput).getFile();
      }
    } else if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
      Object element = ((IStructuredSelection) selection).getFirstElement();
      if (element instanceof IFile) {
        file = (IFile) element;
      } else if (element instanceof IMethod) {
        IResource r = ((IMethod) element).getResource();
        if (r != null) {
          return (IFile) r.getAdapter(IFile.class);
        }
      }
    }
    return file;
  }
コード例 #7
0
 private BreakpointData[] createBreakpointData() {
   IBreakpointManager bpm = getBreakpointManager();
   IBreakpoint[] breakpoints = bpm.getBreakpoints(LSLDebugTarget.LSLFORGE);
   LinkedList<BreakpointData> list = new LinkedList<BreakpointData>();
   for (int i = 0; i < breakpoints.length; i++) {
     try {
       if (breakpoints[i] instanceof LSLLineBreakpoint) {
         LSLLineBreakpoint bp = (LSLLineBreakpoint) breakpoints[i];
         int line = bp.getLineNumber();
         IMarker marker = bp.getMarker();
         IResource resource = marker.getResource();
         IFile file = (IFile) resource.getAdapter(IFile.class);
         if (file == null) continue;
         if (!marker.getAttribute(IBreakpoint.ENABLED, false)) continue;
         IPath fullPath = file.getLocation();
         list.add(new BreakpointData(fullPath.toOSString(), line));
       }
     } catch (CoreException e) {
       Log.error(e);
     }
   }
   return list.toArray(new BreakpointData[list.size()]);
 }
コード例 #8
0
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    if (LslPlusPlugin.DEBUG) Util.log("launch!!!"); // $NON-NLS-1$

    String fullPath = configuration.getAttribute(LaunchLslTestShortcut.LC_RESOURCE_NAME, BLANK);
    Path path = new Path(fullPath);
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);

    if (resource == null) {
      MessageDialog.openError(
          null,
          Messages.getString("TestLaunchDelegate.TEST_NO_LONGER_EXISTS"), // $NON-NLS-1$
          Messages.getString("TestLaunchDelegate.REFERENCED_TEST_NO_LONGER_EXISTS")); // $NON-NLS-1$
      return;
    }
    LslTestSuite suite = (LslTestSuite) resource.getAdapter(LslTestSuite.class);
    LslProjectNature nature =
        (LslProjectNature) resource.getProject().getNature(LslProjectNature.ID);
    String sourceDescriptor = nature.projectSourceList();
    String suiteDescriptor = suite.toXml();
    String testDescriptor =
        "<test-descriptor>"
            + sourceDescriptor
            + suiteDescriptor
            + "</test-descriptor>"; //$NON-NLS-1$//$NON-NLS-2$
    if (LslPlusPlugin.DEBUG) Util.log(testDescriptor);
    TestManager testManager = LslPlusPlugin.getDefault().getTestManager();
    testManager.testLaunched(configuration, launch, suite.getTests().length);
    LslTestProcess p = new LslTestProcess(testDescriptor, launch);
    LslDebugTarget target = new LslDebugTarget("lslplus-test", launch, p); // $NON-NLS-1$
    p.go();
    launch.addDebugTarget(target);
    launch.addProcess(p);
    launch.setSourceLocator(new LslSourceLocator());
  }
コード例 #9
0
ファイル: BaseVisitor.java プロジェクト: robinst/pmd
  /**
   * Run PMD against a resource
   *
   * @param resource the resource to process
   */
  protected final void reviewResource(IResource resource) {

    IFile file = (IFile) resource.getAdapter(IFile.class);
    if (file == null || file.getFileExtension() == null) return;

    Reader input = null;
    try {
      boolean included = isIncluded(file);
      log.debug("Derived files included: " + projectProperties.isIncludeDerivedFiles());
      log.debug("file " + file.getName() + " is derived: " + file.isDerived());
      log.debug("file checked: " + included);

      prepareMarkerAccumulator(file);

      LanguageVersionDiscoverer languageDiscoverer = new LanguageVersionDiscoverer();
      LanguageVersion languageVersion =
          languageDiscoverer.getDefaultLanguageVersionForFile(file.getName());
      // in case it is java, select the correct java version
      if (languageVersion != null && languageVersion.getLanguage() == Language.JAVA) {
        languageVersion = PMDPlugin.javaVersionFor(file.getProject());
      }
      if (languageVersion != null) {
        configuration().setDefaultLanguageVersion(languageVersion);
      }
      log.debug("discovered language: " + languageVersion);

      final File sourceCodeFile = file.getRawLocation().toFile();
      if (included
          && getRuleSet().applies(sourceCodeFile)
          && isFileInWorkingSet(file)
          && languageVersion != null) {
        subTask("PMD checking: " + file.getName());

        Timer timer = new Timer();

        RuleContext context = PMD.newRuleContext(file.getName(), sourceCodeFile);
        context.setLanguageVersion(languageVersion);

        input = new InputStreamReader(file.getContents(), file.getCharset());
        //                    getPmdEngine().processFile(input, getRuleSet(), context);
        //                    getPmdEngine().processFile(sourceCodeFile, getRuleSet(), context);

        RuleSets rSets = new RuleSets(getRuleSet());
        new SourceCodeProcessor(configuration()).processSourceCode(input, rSets, context);

        timer.stop();
        pmdDuration += timer.getDuration();

        updateMarkers(file, context, isUseTaskMarker());

        worked(1);
        fileCount++;
      } else {
        log.debug("The file " + file.getName() + " is not in the working set");
      }

    } catch (CoreException e) {
      log.error("Core exception visiting " + file.getName(), e); // TODO:		// complete message
    } catch (PMDException e) {
      log.error("PMD exception visiting " + file.getName(), e); // TODO: 		// complete message
    } catch (IOException e) {
      log.error("IO exception visiting " + file.getName(), e); // TODO: 		// complete message
    } catch (PropertiesException e) {
      log.error("Properties exception visiting " + file.getName(), e); // TODO:	// complete message
    } finally {
      IOUtil.closeQuietly(input);
    }
  }