Example usage for org.eclipse.jdt.core JavaCore getJavaCore

List of usage examples for org.eclipse.jdt.core JavaCore getJavaCore

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore getJavaCore.

Prototype

public static JavaCore getJavaCore() 

Source Link

Document

Returns the single instance of the Java core plug-in runtime class.

Usage

From source file:de.loskutov.anyedit.jdt.JdtUtils.java

License:Open Source License

private static int getJavaProjectTabWidth(int tabWidth, IProject project) {
    IJavaProject javaProject = null;//ww w .  j  a va 2s  .  c o  m
    if (project != null && hasJavaNature(project)) {
        javaProject = getJavaProject(project);
    }
    String tabOption;
    if (javaProject == null || JavaCore.getJavaCore() == null) {
        tabOption = JavaCore.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE);
    } else {
        tabOption = javaProject.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, true);
    }
    if (tabOption != null) {
        try {
            tabWidth = Integer.parseInt(tabOption);
        } catch (NumberFormatException e) {
            // TODO: handle exception
        }
    }
    return tabWidth;
}

From source file:it.unibz.instasearch.indexing.WorkspaceIndexerJDT.java

License:Open Source License

/**
 * @throws Exception /*from   w  w  w .j av a  2 s .  com*/
 * @throws IOException
 */
public WorkspaceIndexerJDT() throws Exception {
    super();

    if (JavaCore.getJavaCore() == null) // check that we have JDT. throws exception if we don't have JavaCore
        throw new RuntimeException("JDT not detected");
}

From source file:net.sourceforge.metrics.core.sources.AbstractMetricSource.java

License:Open Source License

private void configureOutOfRangeMarker(Metric value, MetricDescriptor md, IResource resource)
        throws CoreException {
    IMarker marker = resource.createMarker("net.sourceforge.metrics.outofrangemarker");
    if ((marker != null) && (marker.exists())) {
        JavaCore.getJavaCore().configureJavaElementMarker(marker, getJavaElement());
        marker.setAttribute("metric", value.getName());
        marker.setAttribute("value", "" + value.doubleValue());
        String message = createMessage(value, md);
        marker.setAttribute(IMarker.MESSAGE, message);
        marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
        if (getJavaElement() instanceof IMember) {
            IMember m = (IMember) getJavaElement();
            int offset = m.getNameRange().getOffset();
            int length = m.getNameRange().getLength();
            marker.setAttribute(IMarker.CHAR_START, offset);
            marker.setAttribute(IMarker.CHAR_END, offset + length);
            CompilationUnit cu = getParsedCompilationUnit();
            if (cu != null) {
                marker.setAttribute(IMarker.LINE_NUMBER, cu.lineNumber(offset));
            }/* ww  w  . j  a v  a2 s .com*/
        }
    }
}

From source file:net.sourceforge.tagsea.tasks.TaskWaypointUtils.java

License:Open Source License

public static String[] getJavaTaskTags() {
    Preferences prefs = JavaCore.getJavaCore().getPluginPreferences();
    String tags = prefs.getString(JavaCore.COMPILER_TASK_TAGS);
    String[] tagWords = tags.split("[,]");
    String[] result = new String[tagWords.length];
    for (int i = 0; i < tagWords.length; i++) {
        result[i] = tagWords[i].trim();/*from   w  w  w  .  j a v  a  2 s  . c  o m*/
    }
    return result;
}

From source file:org.codehaus.jdt.groovy.integration.LanguageSupportFactory.java

License:Open Source License

private static LanguageSupport tryInstantiate(String className) {
    LanguageSupport instance = null;//from   w  ww  .j  a v  a  2s .  com
    if (className != null && className.length() > 0) {
        try {
            int separator = className.indexOf(':');
            Bundle bundle = null;
            if (separator == -1) {
                JavaCore javaCore = JavaCore.getJavaCore();
                if (javaCore == null) {
                    Class clazz = Class.forName(className);
                    return (LanguageSupport) clazz.newInstance();
                } else {
                    bundle = javaCore.getBundle();
                }
            } else {
                String bundleName = className.substring(0, separator);
                className = className.substring(separator + 1);
                bundle = Platform.getBundle(bundleName);
            }
            Class c = bundle.loadClass(className);
            instance = (LanguageSupport) c.newInstance();
        } catch (ClassNotFoundException e) {
            log(e);
        } catch (InstantiationException e) {
            log(e);
        } catch (IllegalAccessException e) {
            log(e);
        } catch (ClassCastException e) {
            log(e);
        }
    }
    return instance;
}

From source file:org.eclipse.e4.xwt.tools.ui.designer.jdt.ProjectHelper.java

License:Open Source License

protected static boolean containsJar(IJavaProject javaProject, IClasspathEntry entry, String jarName) {
    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_VARIABLE:
        IClasspathEntry resolvedEntry = JavaCore.getJavaCore().getResolvedClasspathEntry(entry);
        IPath resolvedPath = resolvedEntry.getPath();
        String string = resolvedPath.toString();
        if (string.indexOf(jarName) != -1) {
            return true;
        }/*w ww  . j a  v a 2  s. c o m*/
        break;
    case IClasspathEntry.CPE_CONTAINER:
        try {
            IPath path = entry.getPath();
            IClasspathContainer classpathContainer = JavaCore.getJavaCore().getClasspathContainer(path,
                    javaProject);
            if (classpathContainer != null) {
                classpathContainer.getClasspathEntries();
                IClasspathEntry[] oldclasspath = classpathContainer.getClasspathEntries();
                for (int i = 0; i < oldclasspath.length; i++) {
                    if (containsJar(javaProject, oldclasspath[i], jarName)) {
                        return true;
                    }
                }
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        break;
    case IClasspathEntry.CPE_SOURCE:
    case IClasspathEntry.CPE_LIBRARY:
        IPath path = entry.getPath();
        String value = path.toString();
        if (value.indexOf(jarName) != -1) {
            return true;
        }
    }

    return false;
}

From source file:org.eclipse.objectteams.otdt.core.search.OTSearchHelper.java

License:Open Source License

/**
 * Find all playedBy bindings within a given set of projects refering to one of baseTypes as its baseclass.
 * //from  w ww . j a v  a2s.  co  m
 * @param baseTypes 
 * @param projects
 * @param monitor
 * @return a map indexed by base types containing sets of role types bound to the given base type.
 */
public static Map<IMember, Set<IType>> searchPlayedByBindings(Collection<IType> baseTypes,
        IJavaProject[] projects, IProgressMonitor monitor) {
    if (baseTypes == null || baseTypes.size() == 0) {
        monitor.beginTask("", 1); //$NON-NLS-1$
        monitor.done();
        return null;
    }

    OTSearchEngine engine = new OTSearchEngine();
    IJavaSearchScope searchScope = OTSearchEngine.createOTSearchScope(projects, false);
    final Map<IMember, Set<IType>> resultMap = new HashMap<IMember, Set<IType>>();

    try {
        monitor.beginTask(Messages.OTSearchHelper_progress_searchRoleTypes, baseTypes.size());

        for (final IType baseType : baseTypes) {
            if (monitor.isCanceled())
                return null;
            try {
                IProgressMonitor searchMonitor = new SubProgressMonitor(monitor, 1);
                if (!baseType.exists()) // ensure it's 'open'
                    continue;
                if (baseType.isEnum() || baseType.isAnnotation())
                    continue; // no callin-to-enum/annot 
                SearchPattern pattern = SearchPattern.createPattern(baseType,
                        IJavaSearchConstants.PLAYEDBY_REFERENCES);
                if (pattern == null)
                    JavaCore.getJavaCore().getLog()
                            .log(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, "Error creating pattern")); //$NON-NLS-1$
                else
                    engine.search(pattern, searchScope, new SearchRequestor() {
                        public void acceptSearchMatch(SearchMatch match) throws CoreException {
                            Object element = match.getElement();
                            if (element instanceof IType) {
                                // FIXME(SH): check: if mapping is a role, baseType must be conform to its baseclass 
                                IType mapping = (IType) element;
                                addToMapOfSets(resultMap, baseType, mapping);
                            }
                        }
                    }, searchMonitor);
            } catch (CoreException ex) {
                JavaCore.getJavaCore().getLog().log(
                        new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, "Error finding playedBy bindings", ex)); //$NON-NLS-1$
            }
        }
    } finally {
        monitor.done();
    }

    return resultMap;
}

From source file:org.eclipse.objectteams.otdt.internal.compiler.adaptor.ProjectUtil.java

License:Open Source License

public static boolean isOTPluginProject(IProject project) {
    if (project == null)
        return false;
    try {/*from   ww w  .  j  a v  a 2  s  .co m*/
        return project.hasNature(PLUGIN_NATURE) && OTJavaNature.hasOTJavaNature(project);
    } catch (CoreException e) {
        if (!OTModelManager.EXTERNAL_PROJECT_NAME.equals(project.getName())) // see JavaProject.hasJavaNature()
            JavaCore.getJavaCore().getLog()
                    .log(new Status(IStatus.ERROR, PLUGIN_ID, "Error reading project natures", //$NON-NLS-1$
                            e));
        return false;
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.ext.JavaElementMarkable.java

License:Open Source License

public IMarker createMarker(String id) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IMarker marker = root.createMarker(id);
    JavaCore.getJavaCore().configureJavaElementMarker(marker, this.fJavaElement);
    marker.setAttribute(MarkerViewUtil.NAME_ATTRIBUTE, getName());
    marker.setAttribute(MarkerViewUtil.PATH_ATTRIBUTE, this.fJavaElement.getPath().toString());
    return marker;
}

From source file:org.eclipse.objectteams.otdt.internal.core.RoleType.java

License:Open Source License

private IType getBaseClass(ITypeHierarchy hierarchy) throws JavaModelException {
    if (this.baseClass == null) {
        JavaModelException jex = null;//from ww  w.java  2 s .  com

        try {
            //             System.out.println("RoleType.getBaseClass(): " + getElementName());
            this.baseClass = findBaseClass(hierarchy);
        } catch (JavaModelException ex) {
            jex = ex;
        } catch (Exception ex) {
            // just be sure we get all kind of exceptions
            Util.log(ex,
                    NLS.bind("Resolving of base class ''{0}'' failed!", new Object[] { this.baseClassName })); //$NON-NLS-1$
        }

        // when having syntax/compilation errors, we can't ensure to find our baseclass
        if (this.baseClass == null && (this.baseClassName != null || jex != null)) {
            IStatus status = new Status(IStatus.WARNING, JavaCore.PLUGIN_ID, IStatus.OK,
                    NLS.bind("Base class for role {0} not found.", //$NON-NLS-1$
                            new Object[] { getTypeQualifiedName('.') }),
                    jex);
            JavaCore.getJavaCore().getLog().log(status);
            throw new JavaModelException(new CoreException(status));
        }
    }

    return this.baseClass;
}