Example usage for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS

List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS.

Prototype

int DECLARATIONS

To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS.

Click Source Link

Document

The search result is a declaration.

Usage

From source file:de.gebit.integrity.eclipse.views.IntegrityTestRunnerView.java

License:Open Source License

private void jumpToJavaMethod(String aJavaClassAndMethod) {
    Matcher tempMatcher = Pattern.compile("([^#]*)\\.([^#]*)#(.*)").matcher(aJavaClassAndMethod);
    if (tempMatcher.matches()) {
        final String tempPackageName = tempMatcher.group(1);
        String tempClassName = tempMatcher.group(2);
        final String tempMethodName = tempMatcher.group(3);

        SearchPattern tempPattern = SearchPattern.createPattern(tempClassName, IJavaSearchConstants.TYPE,
                IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
        IJavaSearchScope tempScope = SearchEngine.createWorkspaceScope();
        SearchRequestor tempRequestor = new SearchRequestor() {

            @Override/*from w w w . java2  s.c om*/
            public void acceptSearchMatch(SearchMatch aMatch) throws CoreException {
                IType tempType = (IType) aMatch.getElement();
                if (tempPackageName.equals(tempType.getPackageFragment().getElementName())) {
                    for (IMethod tempMethod : tempType.getMethods()) {
                        if (tempMethodName.equals(tempMethod.getElementName())) {
                            JavaUI.openInEditor(tempMethod);
                            return;
                        }
                    }
                }
            }
        };

        SearchEngine tempSearchEngine = new SearchEngine();
        try {
            tempSearchEngine.search(tempPattern,
                    new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, tempScope,
                    tempRequestor, null);
        } catch (CoreException exc) {
            exc.printStackTrace();
        }
    }
}

From source file:de.loskutov.dh.search.SearchHelper.java

License:Open Source License

private static SearchPattern createAnyFieldPattern(IType[] types) {
    if (types.length == 0) {
        return createAnyFieldPattern();
    }/*  w ww  . j  av  a2  s .c o m*/
    SearchPattern result = null;
    for (IType type : types) {
        SearchPattern searchPattern = SearchPattern.createPattern(type.getFullyQualifiedName() + ".*",
                IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
        if (result == null) {
            result = searchPattern;
        } else {
            result = SearchPattern.createOrPattern(result, searchPattern);
        }
    }
    return result;
}

From source file:de.loskutov.dh.search.SearchHelper.java

License:Open Source License

private static SearchPattern createAnyFieldPattern() {
    return SearchPattern.createPattern("*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS,
            SearchPattern.R_PATTERN_MATCH);
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockCall.java

License:Open Source License

/********************************************************************************/

void getCallPath(String proj, String src, String tgt, boolean shortest, int lvls, IvyXmlWriter xw)
        throws BedrockException {
    IProject ip = our_plugin.getProjectManager().findProject(proj);
    IJavaProject ijp = JavaCore.create(ip);
    if (lvls < 0)
        lvls = MAX_LEVELS;//from w w w.  j  ava2  s. c  om

    IJavaElement[] pelt = new IJavaElement[] { ijp };
    int incl = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES
            | IJavaSearchScope.REFERENCED_PROJECTS;
    IJavaSearchScope scp = SearchEngine.createJavaSearchScope(pelt, incl);

    SearchEngine se = new SearchEngine();
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };

    SearchPattern p1 = SearchPattern.createPattern(src, IJavaSearchConstants.METHOD,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
    SearchPattern p1a = SearchPattern.createPattern(fixConstructor(src), IJavaSearchConstants.CONSTRUCTOR,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
    if (p1 == null || p1a == null)
        throw new BedrockException("Illegal source pattern " + src);

    SearchPattern p2 = SearchPattern.createPattern(tgt, IJavaSearchConstants.METHOD,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
    SearchPattern p2a = SearchPattern.createPattern(fixConstructor(tgt), IJavaSearchConstants.CONSTRUCTOR,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
    if (p2 == null || p2a == null)
        throw new BedrockException("Illegal target pattern " + tgt);

    SetHandler sh = new SetHandler();
    try {
        se.search(p1, parts, scp, sh, null);
        BedrockPlugin.logD("CALL: Source A: " + sh.getSize() + " " + p1);
        if (sh.isEmpty())
            se.search(p1a, parts, scp, sh, null);
        BedrockPlugin.logD("CALL: Source B: " + sh.getSize() + " " + p1a);
    } catch (CoreException e) {
        throw new BedrockException("Problem doing call search 1: " + e, e);
    }

    SetHandler th = new SetHandler();
    try {
        se.search(p2, parts, scp, th, null);
        BedrockPlugin.logD("CALL: Target A: " + th.getSize() + " " + p2);
        if (th.isEmpty())
            se.search(p2a, parts, scp, th, null);
        BedrockPlugin.logD("CALL: Target B: " + th.getSize() + " " + p2a);
    } catch (CoreException e) {
        throw new BedrockException("Problem doing call search 2: " + e, e);
    }

    Map<IMethod, CallNode> nodes = new HashMap<IMethod, CallNode>();
    Queue<IMethod> workqueue = new LinkedList<IMethod>();
    for (IMethod je : th.getElements()) {
        CallNode cn = new CallNode(je, 0);
        cn.setTarget();
        nodes.put(je, cn);
        workqueue.add(je);
    }

    while (!workqueue.isEmpty()) {
        IMethod je = workqueue.remove();
        CallNode cn = nodes.get(je);
        if (cn.isDone())
            continue;
        cn.markDone();

        BedrockPlugin.logD("CALL: WORK ON " + je.getKey() + " " + cn.getLevel() + " " + sh.contains(je));

        if (shortest && sh.contains(je))
            break;
        int lvl = cn.getLevel() + 1;
        if (lvl > lvls)
            continue;

        String nm = je.getElementName();
        if (nm == null)
            continue;
        String cnm = je.getDeclaringType().getFullyQualifiedName();
        if (cnm != null)
            nm = cnm.replace("$", ".") + "." + nm;
        nm += "(";
        String[] ptyps = je.getParameterTypes();
        for (int i = 0; i < ptyps.length; ++i) {
            if (i > 0)
                nm += ",";
            nm += IvyFormat.formatTypeName(ptyps[i]);
        }
        nm += ")";

        SearchPattern p3;
        try {
            BedrockPlugin.logD("CALL: Search for: " + nm + " " + je.isConstructor());
            if (je.isConstructor()) {
                String nm1 = fixConstructor(nm);
                p3 = SearchPattern.createPattern(nm1, IJavaSearchConstants.CONSTRUCTOR,
                        IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH);
            } else {
                p3 = SearchPattern.createPattern(nm, IJavaSearchConstants.METHOD,
                        IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH);
            }

            CallHandler ch = new CallHandler(je, workqueue, nodes, lvl);

            se.search(p3, parts, scp, ch, null);
        } catch (CoreException e) {
            throw new BedrockException("Problem doing call search e: " + e, e);
        }
    }

    // TODO: restrict to single path if shortest is set

    xw.begin("PATH");
    for (IMethod je : sh.getElements()) {
        CallNode cn = nodes.get(je);
        if (cn == null)
            continue;
        Set<IMethod> done = new HashSet<IMethod>();
        cn.output(xw, done, nodes);
    }
    xw.end("PATH");
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java

License:Open Source License

/********************************************************************************/

void handleFindAll(String proj, String file, int start, int end, boolean defs, boolean refs, boolean impls,
        boolean equiv, boolean exact, boolean system, boolean typeof, boolean ronly, boolean wonly,
        IvyXmlWriter xw) throws BedrockException {
    IJavaProject ijp = getJavaProject(proj);
    IPath fp = new Path(file);

    int limit = 0;
    if (defs && refs)
        limit = IJavaSearchConstants.ALL_OCCURRENCES;
    else if (defs)
        limit = IJavaSearchConstants.DECLARATIONS;
    else if (refs)
        limit = IJavaSearchConstants.REFERENCES;
    int flimit = limit;
    if (ronly)//from ww w.j  a va  2 s. c  om
        flimit = IJavaSearchConstants.READ_ACCESSES;
    else if (wonly)
        flimit = IJavaSearchConstants.WRITE_ACCESSES;

    int mrule = -1;
    if (equiv)
        mrule = SearchPattern.R_EQUIVALENT_MATCH;
    else if (exact)
        mrule = SearchPattern.R_EXACT_MATCH;

    SearchPattern pat = null;
    IJavaSearchScope scp = null;

    ICompilationUnit icu = our_plugin.getProjectManager().getCompilationUnit(proj, file);
    if (icu == null)
        throw new BedrockException("Compilation unit not found for " + fp);
    icu = getCompilationElement(icu);

    ICompilationUnit[] working = null;
    FindFilter filter = null;

    IJavaElement cls = null;
    char[] packagename = null;
    char[] typename = null;

    try {
        BedrockPlugin.logD("Getting search scopes");
        IJavaElement[] pelt;
        if (ijp != null)
            pelt = new IJavaElement[] { ijp };
        else
            pelt = getAllProjects();
        working = getWorkingElements(pelt);
        int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
        if (system)
            fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES;
        scp = SearchEngine.createJavaSearchScope(pelt, fg);

        BedrockPlugin.logD("Locating item to search for");
        IJavaElement[] elts = icu.codeSelect(start, end - start);

        if (typeof) {
            Set<IJavaElement> nelt = new LinkedHashSet<IJavaElement>();
            for (int i = 0; i < elts.length; ++i) {
                IType typ = null;
                String tnm = null;
                switch (elts[i].getElementType()) {
                case IJavaElement.FIELD:
                    tnm = ((IField) elts[i]).getTypeSignature();
                    break;
                case IJavaElement.LOCAL_VARIABLE:
                    tnm = ((ILocalVariable) elts[i]).getTypeSignature();
                    break;
                case IJavaElement.METHOD:
                    typ = ((IMethod) elts[i]).getDeclaringType();
                    break;
                default:
                    nelt.add(elts[i]);
                    break;
                }
                if (typ != null)
                    nelt.add(typ);
                else if (tnm != null && ijp != null) {
                    IJavaElement elt = ijp.findElement(tnm, null);
                    if (elt != null) {
                        nelt.add(elt);
                        typ = null;
                    } else {
                        while (tnm.startsWith("[")) {
                            String xtnm = tnm.substring(1);
                            if (xtnm == null)
                                break;
                            tnm = xtnm;
                        }
                        int ln = tnm.length();
                        String xtnm = tnm;
                        if (tnm.startsWith("L") && tnm.endsWith(";")) {
                            xtnm = tnm.substring(1, ln - 1);
                        } else if (tnm.startsWith("Q") && tnm.endsWith(";")) {
                            xtnm = tnm.substring(1, ln - 1);
                        }
                        if (xtnm != null)
                            tnm = xtnm;
                        int idx1 = tnm.lastIndexOf(".");
                        if (idx1 > 0) {
                            String pkgnm = tnm.substring(0, idx1);
                            xtnm = tnm.substring(idx1 + 1);
                            if (xtnm != null)
                                tnm = xtnm;
                            pkgnm = pkgnm.replace('$', '.');
                            packagename = pkgnm.toCharArray();
                        }
                        tnm = tnm.replace('$', '.');
                        typename = tnm.toCharArray();
                    }

                    if (typename != null) {
                        BedrockPlugin.logD("Handling type names");
                        FindTypeHandler fth = new FindTypeHandler(ijp);
                        SearchEngine se = new SearchEngine(working);
                        se.searchAllTypeNames(packagename, SearchPattern.R_EXACT_MATCH, typename,
                                SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, scp, fth,
                                IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
                        nelt.addAll(fth.getFoundItems());
                    }
                }
            }
            IJavaElement[] nelts = new IJavaElement[nelt.size()];
            elts = nelt.toArray(nelts);
        }

        if (elts.length == 1 && !typeof) {
            xw.begin("SEARCHFOR");
            switch (elts[0].getElementType()) {
            case IJavaElement.FIELD:
                xw.field("TYPE", "Field");
                break;
            case IJavaElement.LOCAL_VARIABLE:
                xw.field("TYPE", "Local");
                break;
            case IJavaElement.METHOD:
                xw.field("TYPE", "Function");
                break;
            case IJavaElement.TYPE:
            case IJavaElement.TYPE_PARAMETER:
                xw.field("TYPE", "Class");
                cls = elts[0];
                break;
            }
            xw.text(elts[0].getElementName());
            xw.end("SEARCHFOR");
        }
        int etyp = -1;
        for (int i = 0; i < elts.length; ++i) {
            SearchPattern sp;
            int xlimit = limit;
            switch (elts[i].getElementType()) {
            case IJavaElement.FIELD:
            case IJavaElement.LOCAL_VARIABLE:
                xlimit = flimit;
                break;
            case IJavaElement.TYPE:
                if (impls)
                    xlimit = IJavaSearchConstants.IMPLEMENTORS;
                break;
            case IJavaElement.METHOD:
                if (impls)
                    xlimit |= IJavaSearchConstants.IGNORE_DECLARING_TYPE;
                break;
            }
            if (mrule < 0)
                sp = SearchPattern.createPattern(elts[i], xlimit);
            else
                sp = SearchPattern.createPattern(elts[i], xlimit, mrule);
            if (pat == null)
                pat = sp;
            else
                pat = SearchPattern.createOrPattern(pat, sp);
            if (etyp < 0)
                etyp = elts[i].getElementType();
        }

        if (etyp == IJavaElement.METHOD) {
            if (impls) {
                if (defs)
                    filter = new ImplementFilter(elts);
            } else if (defs && !refs)
                filter = new ClassFilter(elts);
        }

    } catch (JavaModelException e) {
        BedrockPlugin.logE("SEARCH PROBLEM: " + e);
        e.printStackTrace();
        throw new BedrockException("Can't find anything to search for", e);
    }

    if (pat == null) {
        BedrockPlugin.logW("Nothing to search for");
        return;
    }

    BedrockPlugin.logD("Setting up search");
    SearchEngine se = new SearchEngine(working);
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    FindHandler fh = new FindHandler(xw, filter, false);

    BedrockPlugin.logD(
            "BEGIN SEARCH " + pat + " " + parts.length + " " + " " + scp + " :: COPIES: " + working.length);

    try {
        se.search(pat, parts, scp, fh, null);
    } catch (Throwable e) {
        throw new BedrockException("Problem doing find all search for " + pat + ": " + e, e);
    }

    if (cls != null && defs) { // need to add the actual class definition
        BedrockUtil.outputJavaElement(cls, false, xw);
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java

License:Open Source License

/********************************************************************************/

void handleJavaSearch(String proj, String bid, String patstr, String foritems, boolean defs, boolean refs,
        boolean impls, boolean equiv, boolean exact, boolean system, IvyXmlWriter xw) throws BedrockException {
    IJavaProject ijp = getJavaProject(proj);

    our_plugin.waitForEdits();/*from   www  .  j ava  2 s .  c  om*/

    int forflags = 0;
    if (foritems == null)
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("CLASS"))
        forflags = IJavaSearchConstants.CLASS;
    else if (foritems.equalsIgnoreCase("INTERFACE"))
        forflags = IJavaSearchConstants.INTERFACE;
    else if (foritems.equalsIgnoreCase("ENUM"))
        forflags = IJavaSearchConstants.ENUM;
    else if (foritems.equalsIgnoreCase("ANNOTATION"))
        forflags = IJavaSearchConstants.ANNOTATION_TYPE;
    else if (foritems.equalsIgnoreCase("CLASS&ENUM"))
        forflags = IJavaSearchConstants.CLASS_AND_ENUM;
    else if (foritems.equalsIgnoreCase("CLASS&INTERFACE"))
        forflags = IJavaSearchConstants.CLASS_AND_INTERFACE;
    else if (foritems.equalsIgnoreCase("TYPE"))
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("FIELD"))
        forflags = IJavaSearchConstants.FIELD;
    else if (foritems.equalsIgnoreCase("METHOD"))
        forflags = IJavaSearchConstants.METHOD;
    else if (foritems.equalsIgnoreCase("CONSTRUCTOR"))
        forflags = IJavaSearchConstants.CONSTRUCTOR;
    else if (foritems.equalsIgnoreCase("PACKAGE"))
        forflags = IJavaSearchConstants.PACKAGE;
    else if (foritems.equalsIgnoreCase("FIELDWRITE"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.WRITE_ACCESSES;
    else if (foritems.equalsIgnoreCase("FIELDREAD"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.READ_ACCESSES;
    else
        forflags = IJavaSearchConstants.TYPE;

    int limit = 0;
    if (defs && refs)
        limit = IJavaSearchConstants.ALL_OCCURRENCES;
    else if (defs)
        limit = IJavaSearchConstants.DECLARATIONS;
    else if (refs)
        limit = IJavaSearchConstants.REFERENCES;
    else if (impls)
        limit = IJavaSearchConstants.IMPLEMENTORS;

    int mrule = SearchPattern.R_PATTERN_MATCH;
    if (equiv)
        mrule = SearchPattern.R_EQUIVALENT_MATCH;
    else if (exact)
        mrule = SearchPattern.R_EXACT_MATCH;

    SearchPattern pat = SearchPattern.createPattern(patstr, forflags, limit, mrule);
    if (pat == null) {
        throw new BedrockException(
                "Invalid java search pattern `" + patstr + "' " + forflags + " " + limit + " " + mrule);
    }

    FindFilter filter = null;
    if (forflags == IJavaSearchConstants.METHOD) {
        String p = patstr;
        int idx = p.indexOf("(");
        if (idx > 0)
            p = p.substring(0, idx);
        idx = p.lastIndexOf(".");
        if (idx > 0) {
            if (defs)
                filter = new ClassFilter(p.substring(0, idx));
        }
    }

    // TODO: create scope for only user's items
    IJavaElement[] pelt;
    if (ijp != null)
        pelt = new IJavaElement[] { ijp };
    else
        pelt = getAllProjects();

    ICompilationUnit[] working = getWorkingElements(pelt);
    for (ICompilationUnit xcu : working) {
        try {
            BedrockPlugin.logD("WORK WITH " + xcu.isWorkingCopy() + " " + xcu.getPath() + xcu.getSourceRange());
        } catch (JavaModelException e) {
            BedrockPlugin.logD("WORK WITH ERROR: " + e);
        }
    }

    IJavaSearchScope scp = null;
    int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
    if (system) {
        fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES;
        scp = SearchEngine.createWorkspaceScope();
    } else {
        scp = SearchEngine.createJavaSearchScope(pelt, fg);
    }

    SearchEngine se = new SearchEngine(working);
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    FindHandler fh = new FindHandler(xw, filter, system);

    BedrockPlugin.logD("BEGIN SEARCH " + pat);
    BedrockPlugin.logD("SEARCH SCOPE " + system + " " + fg + " " + scp);

    try {
        se.search(pat, parts, scp, fh, null);
    } catch (Throwable e) {
        throw new BedrockException("Problem doing Java search: " + e, e);
    }
}

From source file:edu.washington.cs.cupid.scripting.java.quickfix.ClasspathProcessor.java

License:Open Source License

private List<IJavaCompletionProposal> buildMissingBundleProposals(final IInvocationContext context,
        final IProblemLocation location) {
    final List<IJavaCompletionProposal> proposals = Lists.newArrayList();

    String className = location.getProblemArguments()[0];

    SearchRequestor requestor = new SearchRequestor() {
        @Override/* w w w . java 2 s.  c  o m*/
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            if (match instanceof TypeDeclarationMatch) {
                if (match.getElement() instanceof IType) {
                    IType type = (IType) match.getElement();
                    Bundle bundle = null;
                    try {
                        bundle = ClasspathUtil.bundleForClass(type.getFullyQualifiedName());
                    } catch (ClassNotFoundException e) {
                        throw new RuntimeException("Internal error finding bundle for class ", e);
                    }
                    proposals.add(
                            new AddBundleCompletion(context.getCompilationUnit().getJavaProject(), bundle));
                } else {
                    throw new RuntimeException("Unexpected match of type " + match.getElement().getClass());
                }
            }
        }
    };

    SearchEngine engine = new SearchEngine();
    try {
        engine.search(
                SearchPattern.createPattern(className, IJavaSearchConstants.TYPE,
                        IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH), // pattern
                new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                SearchEngine.createWorkspaceScope(), //scope, 
                requestor, // searchRequestor
                null // progress monitor
        );
    } catch (CoreException ex) {
        // NO OP
    }

    return proposals;
}

From source file:edu.washington.cs.cupid.wizards.TypeUtil.java

License:Open Source License

/**
 * Search for <code>className</code> in the workspace.
 * @param className a simple or qualified class name
 * @return instances of the type/*w  w w . ja v a 2  s.  c om*/
 * @throws CoreException if an error occurred during the search
 */
public static List<IType> fetchTypes(String className) throws CoreException {
    if (className == null) {
        throw new NullPointerException("Class name to search for cannot be null");
    }

    final List<IType> result = Lists.newArrayList();

    SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            if (match instanceof TypeDeclarationMatch) {
                if (match.getElement() instanceof IType) {
                    result.add((IType) match.getElement());
                } else {
                    throw new RuntimeException("Unexpected match of type " + match.getElement().getClass());
                }
            }
        }
    };

    SearchEngine engine = new SearchEngine();

    engine.search(
            SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS,
                    SearchPattern.R_FULL_MATCH), // pattern
            new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
            SearchEngine.createWorkspaceScope(), //scope, 
            requestor, // searchRequestor
            null // progress monitor
    );

    return result;
}

From source file:fr.inria.diverse.trace.benchmark.EngineHelper.java

License:Open Source License

public void prepareEngine(URI model, IDebuggerHelper debugger, Language language)
        throws CoreException, EngineContextException {

    IRunConfiguration runConfiguration = new BenchmarkRunConfiguration(debugger, language, model);

    // We don't want to debug actually, ie we don't want the animator
    ExecutionMode executionMode = ExecutionMode.Run;

    // In this construction, the addons are created and loaded as well
    executionContext = new ModelExecutionContext(runConfiguration, executionMode);

    String className = executionContext.getRunConfiguration().getExecutionEntryPoint();
    SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    DefaultSearchRequestor requestor = new DefaultSearchRequestor();
    SearchEngine engine = new SearchEngine();

    engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
            requestor, null);//from w  w w.  java2s  .  c  o m

    IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) requestor._binaryType.getPackageFragment()
            .getParent();

    parameters = new ArrayList<>();
    parameters.add(executionContext.getResourceModel().getContents().get(0));
    String bundleName = null;
    bundleName = packageFragmentRoot.getPath().removeLastSegments(1).lastSegment().toString();

    Class<?> c = null;

    Bundle bundle = Platform.getBundle(bundleName);

    // If not found, we try again with projects
    if (bundle == null) {

        String projectName = requestor._binaryType.getJavaProject().getElementName();
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        if (project != null && project.exists()
                && !project.getFullPath().equals(executionContext.getWorkspace().getProjectPath())) {
            Provisionner p = new Provisionner();
            IStatus status = p.provisionFromProject(project, null);
            if (!status.isOK()) {
                throw new CoreException(new Status(1, "EngineHelper", "couldn't provision project :("));
            }
        }
        bundleName = project.getName();
        bundle = Platform.getBundle(bundleName);

    }

    try {
        c = bundle.loadClass(executionContext.getRunConfiguration().getExecutionEntryPoint());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        throw new CoreException(new Status(1, "EngineHelper", "couldn't load Main class"));
    }
    method = null;
    try {
        method = c.getMethod("main", parameters.get(0).getClass().getInterfaces()[0]);
    } catch (Exception e) {
        e.printStackTrace();
        throw new CoreException(new Status(1, "EngineHelper", "couldn't find main method"));
    }
    o = null;
    try {
        o = c.newInstance();
    } catch (Exception e) {
        e.printStackTrace();
        throw new CoreException(new Status(1, "EngineHelper", "couldn't create Main object"));
    }

    _executionEngine = new PlainK3ExecutionEngine(executionContext, o, method, parameters);
    debugger.setExecutionEngine(_executionEngine);

}

From source file:net.harawata.mybatipse.mybatis.XmlCompletionProposalComputer.java

License:Open Source License

private void searchPackage(String matchString, IJavaSearchScope scope, SearchRequestor requestor)
        throws CoreException {
    SearchPattern pattern = SearchPattern.createPattern(matchString + "*", IJavaSearchConstants.PACKAGE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PREFIX_MATCH);
    SearchEngine searchEngine = new SearchEngine();
    searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
            requestor, null);/*from   w  w  w  . j a  v  a  2s  .  c  o  m*/
}