Example usage for org.eclipse.jdt.core IJavaElement getParent

List of usage examples for org.eclipse.jdt.core IJavaElement getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement getParent.

Prototype

IJavaElement getParent();

Source Link

Document

Returns the element directly containing this element, or null if this element has no parent.

Usage

From source file:org.eclipse.xtext.common.types.ui.trace.TraceForTypeRootProvider.java

License:Open Source License

protected IPath getSourcePath(final ITypeRoot derivedJavaType) {
    IJavaElement current = derivedJavaType.getParent();
    while (current != null) {
        if (current instanceof IPackageFragmentRoot) {
            IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) current;
            try {
                IPath attachmentPath = fragmentRoot.getSourceAttachmentPath();
                if (attachmentPath != null)
                    return attachmentPath;
            } catch (JavaModelException e) {
            }//  w  w w. j  ava  2  s.com
            if (current instanceof JarPackageFragmentRoot)
                return fragmentRoot.getPath();

        }
        current = current.getParent();
    }
    return null;
}

From source file:org.eclipse.xtext.common.types.ui.trace.TraceForTypeRootProvider.java

License:Open Source License

protected Charset getSourceEncoding(final ITypeRoot derivedJavaType) {
    // this should be symmetric to org.eclipse.jdt.internal.core.SourceMapper.findSource(String) 
    try {/*from   w  ww .j ava 2s. c  o m*/
        IJavaElement current = derivedJavaType.getParent();
        while (current != null) {
            if (current instanceof IPackageFragmentRoot) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) current;
                try {
                    // see org.eclipse.jdt.internal.core.ClasspathEntry.getSourceAttachmentEncoding()
                    IClasspathAttribute[] attributes = root.getResolvedClasspathEntry().getExtraAttributes();
                    for (int i = 0, length = attributes.length; i < length; i++) {
                        IClasspathAttribute attribute = attributes[i];
                        if (SOURCE_ATTACHMENT_ENCODING.equals(attribute.getName()))
                            return Charset.forName(attribute.getValue());
                    }
                } catch (JavaModelException e) {
                }
                return Charset.forName(ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset());
            }
            current = current.getParent();
        }
        return Charset.forName(ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset());
    } catch (CoreException e) {
        log.error("Error determining encoding for source file for " + derivedJavaType.getElementName(), e);
        return Charsets.UTF_8;
    }
}

From source file:org.eclipse.xtext.xbase.ui.editor.XbaseEditorInputRedirector.java

License:Open Source License

protected IPackageFragmentRoot _getPackageFragmentRoot(final IJavaElement element) {
    return this.getPackageFragmentRoot(element.getParent());
}

From source file:org.eclipselabs.spray.xtext.ui.commands.SprayJavaProjectUtil.java

License:Open Source License

protected IPackageFragmentRoot getPackageFragmentRoot(IJavaElement elem) {
    if (elem == null) {
        return null;
    }//from   w w w .  j a v a  2  s.c  om
    if (elem instanceof IPackageFragmentRoot) {
        return (IPackageFragmentRoot) elem;
    }
    return getPackageFragmentRoot(elem.getParent());
}

From source file:org.eclipselabs.stlipse.javaeditor.JavaCompletionProposalComputer.java

License:Open Source License

public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
        IProgressMonitor monitor) {//www.j  a  v  a2  s.  com
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    if (context instanceof JavaContentAssistInvocationContext) {
        JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
        CompletionContext coreContext = javaContext.getCoreContext();
        ICompilationUnit unit = javaContext.getCompilationUnit();
        try {
            if (unit != null && unit.isStructureKnown()) {
                int offset = javaContext.getInvocationOffset();
                IJavaElement element = unit.getElementAt(offset);
                if (element != null && element instanceof IAnnotatable) {
                    ValueInfo valueInfo = scanAnnotation(offset, (IAnnotatable) element);
                    if (valueInfo != null) {
                        int replacementLength = valueInfo.getValueLength();
                        IJavaProject project = javaContext.getProject();
                        String beanFqn = unit.getType(element.getParent().getElementName())
                                .getFullyQualifiedName();
                        if (valueInfo.isField()) {
                            if (valueInfo.isPropertyOmmitted()) {
                                StringBuilder matchStr = resolveBeanPropertyName(element);
                                if (matchStr.length() > 0) {
                                    char[] token = coreContext.getToken();
                                    matchStr.append('.').append(token);
                                    Map<String, String> fields = BeanPropertyCache.searchFields(project,
                                            beanFqn, matchStr.toString(), false, -1, false);
                                    proposals.addAll(BeanPropertyCache.buildFieldNameProposal(fields,
                                            String.valueOf(token), coreContext.getTokenStart() + 1,
                                            replacementLength));
                                }
                            } else {
                                String input = String.valueOf(coreContext.getToken());
                                Map<String, String> fields = BeanPropertyCache.searchFields(project, beanFqn,
                                        input, false, -1, false);
                                proposals.addAll(BeanPropertyCache.buildFieldNameProposal(fields, input,
                                        coreContext.getTokenStart() + 1, replacementLength));
                            }
                        } else if (valueInfo.isEventHandler()) {
                            String input = String.valueOf(coreContext.getToken());
                            boolean isNot = false;
                            if (input.length() > 0 && input.startsWith("!")) {
                                isNot = true;
                                input = input.length() > 1 ? input.substring(1) : "";
                            }
                            List<String> events = BeanPropertyCache.searchEventHandler(project, beanFqn, input,
                                    false, false);
                            int relevance = events.size();
                            for (String event : events) {
                                String replaceStr = isNot ? "!" + event : event;
                                ICompletionProposal proposal = new JavaCompletionProposal(replaceStr,
                                        coreContext.getTokenStart() + 1, replacementLength, replaceStr.length(),
                                        Activator.getIcon(), event, null, null, relevance--);
                                proposals.add(proposal);
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            Activator.log(Status.ERROR, "Something went wrong.", e);
        }
    }
    return proposals;
}

From source file:org.evosuite.eclipse.popup.actions.ExtendSuiteAction.java

License:Open Source License

/**
 * Add a new test generation job to the job queue
 * //from www  .  j ava2s .co m
 * @param target
 */
@Override
protected void addTestJob(final IResource target) {
    IJavaElement element = JavaCore.create(target);
    IJavaElement packageElement = element.getParent();

    String packageName = packageElement.getElementName();

    final String suiteClass = (!packageName.equals("") ? packageName + "." : "")
            + target.getName().replace(".java", "").replace(File.separator, ".");
    System.out.println("Building new job for " + suiteClass);
    DetermineSUT det = new DetermineSUT();
    IJavaProject jProject = JavaCore.create(target.getProject());
    try {
        String classPath = target.getWorkspace().getRoot().findMember(jProject.getOutputLocation())
                .getLocation().toOSString();
        String SUT = det.getSUTName(suiteClass, classPath);

        // choose
        SelectionDialog typeDialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell),
                target.getProject(), IJavaElementSearchConstants.CONSIDER_CLASSES, false);
        Object[] sutDefault = new Object[1];
        sutDefault[0] = SUT;
        typeDialog.setInitialSelections(sutDefault);
        typeDialog.setTitle("Please select the class under test");
        typeDialog.open();

        // Type selected by the user
        Object[] result = typeDialog.getResult();
        if (result.length > 0) {
            SourceType sourceType = (SourceType) result[0];
            SUT = sourceType.getFullyQualifiedName();
        } else {
            return;
        }

        Job job = new TestExtensionJob(shell, target, SUT, suiteClass);
        job.setPriority(Job.SHORT);
        IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
        ISchedulingRule rule = ruleFactory.createRule(target.getProject());

        //IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
        job.setRule(rule);
        job.setUser(true);
        job.schedule(); // start as soon as possible

    } catch (JavaModelException e) {
        e.printStackTrace();
    } catch (NoJUnitClassException e) {
        MessageDialog.openError(shell, "Evosuite", "Cannot find JUnit tests in " + suiteClass);
    }

}

From source file:org.evosuite.eclipse.popup.actions.ExtendSuiteEditorAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);

    String SUT = "";
    IResource target = null;//  w w w  .  ja  v  a 2s .c om

    System.out.println("Current selection of type " + selection.getClass().getName() + ": " + selection);
    if (selection instanceof TreeSelection) {
        TreeSelection treeSelection = (TreeSelection) selection;
        IAdaptable firstElement = (IAdaptable) treeSelection.getFirstElement();

        // Relies on an internal API, bad juju
        if (firstElement instanceof org.eclipse.jdt.internal.core.CompilationUnit) {
            try {
                org.eclipse.jdt.internal.core.CompilationUnit compilationUnit = (org.eclipse.jdt.internal.core.CompilationUnit) firstElement;
                String packageName = "";
                if (compilationUnit.getPackageDeclarations().length > 0) {
                    System.out.println(
                            "Package: " + compilationUnit.getPackageDeclarations()[0].getElementName());
                    packageName = compilationUnit.getPackageDeclarations()[0].getElementName();
                }
                String targetSuite = compilationUnit.getElementName().replace(".java", "");
                if (!packageName.isEmpty())
                    targetSuite = packageName + "." + targetSuite;
                System.out.println("Selected class: " + targetSuite);
                SUT = targetSuite;
                target = compilationUnit.getResource();
            } catch (JavaModelException e) {

            }
        }
    } else if (activeEditor instanceof JavaEditor) {
        ITypeRoot root = EditorUtility.getEditorInputJavaElement(activeEditor, false);
        ITextSelection sel = (ITextSelection) ((JavaEditor) activeEditor).getSelectionProvider().getSelection();
        int offset = sel.getOffset();
        IJavaElement element;

        try {
            element = root.getElementAt(offset);
            if (element.getElementType() == IJavaElement.METHOD) {
                IJavaElement pDeclaration = element.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
                IPackageFragment pFragment = (IPackageFragment) pDeclaration;
                String packageName = "";
                if (pFragment.getCompilationUnits()[0].getPackageDeclarations().length > 0) {
                    System.out.println("Package: "
                            + pFragment.getCompilationUnits()[0].getPackageDeclarations()[0].getElementName());
                    packageName = pFragment.getCompilationUnits()[0].getPackageDeclarations()[0]
                            .getElementName();
                }
                String targetSuite = element.getParent().getElementName();
                if (!packageName.isEmpty())
                    targetSuite = packageName + "." + targetSuite;
                System.out.println("Selected class: " + targetSuite);
                SUT = targetSuite;
            } else if (element.getElementType() == IJavaElement.TYPE) {
                IType type = ((IType) element);
                System.out.println("Selected class: " + type.getFullyQualifiedName());
                SUT = type.getFullyQualifiedName();
            }

            IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
            target = wroot.findMember(root.getPath());
        } catch (JavaModelException e) {

        }
    }
    if (!SUT.isEmpty() && target != null) {
        IProject proj = target.getProject();
        fixJUnitClassPath(JavaCore.create(proj));
        generateTests(target);
    }

    return null;
}

From source file:org.evosuite.eclipse.popup.actions.GenerateTestsEditorAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    // ISelection selection = HandlerUtil.getCurrentSelection(event);
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);

    String SUT = "";
    IResource target = null;/*from  w ww .  j a  v  a2s. com*/
    System.out.println("Current selection of type " + selection.getClass().getName() + ": " + selection);
    if (selection instanceof TreeSelection) {
        TreeSelection treeSelection = (TreeSelection) selection;
        IAdaptable firstElement = (IAdaptable) treeSelection.getFirstElement();

        // Relies on an internal API, bad juju
        if (firstElement instanceof org.eclipse.jdt.internal.core.CompilationUnit) {
            try {
                org.eclipse.jdt.internal.core.CompilationUnit compilationUnit = (org.eclipse.jdt.internal.core.CompilationUnit) firstElement;
                String packageName = "";
                if (compilationUnit.getPackageDeclarations().length > 0) {
                    System.out.println(
                            "Package: " + compilationUnit.getPackageDeclarations()[0].getElementName());
                    packageName = compilationUnit.getPackageDeclarations()[0].getElementName();
                }
                String targetSuite = compilationUnit.getElementName().replace(".java", "");
                if (!packageName.isEmpty())
                    targetSuite = packageName + "." + targetSuite;
                System.out.println("Selected class: " + targetSuite);
                SUT = targetSuite;
                target = compilationUnit.getResource();
            } catch (JavaModelException e) {

            }
        }
    } else if (activeEditor instanceof JavaEditor) {
        ITypeRoot root = EditorUtility.getEditorInputJavaElement(activeEditor, false);
        ITextSelection sel = (ITextSelection) ((JavaEditor) activeEditor).getSelectionProvider().getSelection();
        int offset = sel.getOffset();
        IJavaElement element;

        try {
            element = root.getElementAt(offset);
            if (element == null) {
                ISelection sel2 = HandlerUtil.getCurrentSelection(event);
                System.out.println(
                        "Selected element of type " + sel2.getClass().getName() + ": " + sel2.toString());
            } else if (element.getElementType() == IJavaElement.METHOD) {
                IJavaElement pDeclaration = element.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
                IPackageFragment pFragment = (IPackageFragment) pDeclaration;
                String packageName = "";
                if (pFragment.getCompilationUnits()[0].getPackageDeclarations().length > 0) {
                    System.out.println("Package: "
                            + pFragment.getCompilationUnits()[0].getPackageDeclarations()[0].getElementName());
                    packageName = pFragment.getCompilationUnits()[0].getPackageDeclarations()[0]
                            .getElementName();
                }
                String targetSuite = element.getParent().getElementName();
                if (!packageName.isEmpty())
                    targetSuite = packageName + "." + targetSuite;
                System.out.println("Selected class: " + targetSuite);
                SUT = targetSuite;
            } else if (element.getElementType() == IJavaElement.TYPE) {
                IType type = ((IType) element);
                System.out.println("Selected class: " + type.getFullyQualifiedName());
                SUT = type.getFullyQualifiedName();
            }

            IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
            target = wroot.findMember(EditorUtility.getEditorInputJavaElement(activeEditor, false).getPath());

        } catch (JavaModelException e) {

        }

    }

    if (!SUT.isEmpty() && target != null) {
        IProject proj = target.getProject();
        fixJUnitClassPath(JavaCore.create(proj));
        generateTests(target);
    }

    return null;
}

From source file:org.evosuite.eclipse.popup.actions.TestGenerationAction.java

License:Open Source License

/**
 * Add a new test generation job to the job queue
 * /*w w  w . j av  a2 s  .c  o m*/
 * @param target
 */
protected void addTestJob(final IResource target) {
    IJavaElement element = JavaCore.create(target);
    if (element == null) {
        return;
    }
    IJavaElement packageElement = element.getParent();

    String packageName = packageElement.getElementName();

    final String targetClass = (!packageName.isEmpty() ? packageName + "." : "")
            + target.getName().replace(".java", "").replace(File.separator, ".");
    System.out.println("* Scheduling new automated job for " + targetClass);
    final String targetClassWithoutPackage = target.getName().replace(".java", "");

    final String suiteClassName = targetClass + Properties.JUNIT_SUFFIX;

    final String suiteFileName = target.getProject().getLocation() + "/evosuite-tests/"
            + suiteClassName.replace('.', File.separatorChar) + ".java";
    System.out.println("Checking for " + suiteFileName);
    File suiteFile = new File(suiteFileName);
    Job job = null;
    if (suiteFile.exists()) {

        MessageDialog dialog = new MessageDialog(shell, "Existing test suite found", null, // image
                "A test suite for class \"" + targetClass
                        + "\" already exists. EvoSuite will overwrite this test suite. Do you really want to proceed?",
                MessageDialog.QUESTION_WITH_CANCEL,
                new String[] { "Overwrite", "Extend", "Rename Original", "Cancel" }, 0);

        int returnCode = dialog.open();
        // 0 == overwrite
        // 1 == extend
        if (returnCode == 1) {
            IWorkspaceRoot wroot = target.getWorkspace().getRoot();
            IResource suiteResource = wroot.getFileForLocation(new Path(suiteFileName));
            job = new TestExtensionJob(shell, suiteResource, targetClass, suiteClassName);
        } else if (returnCode == 2) {
            // 2 == Rename
            renameSuite(target, packageName, targetClassWithoutPackage + Properties.JUNIT_SUFFIX + ".java");
        } else if (returnCode > 2) {
            // Cancel
            return;
        }
    }

    if (job == null)
        job = new TestGenerationJob(shell, target, targetClass, suiteClassName);

    job.setPriority(Job.SHORT);
    IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
    ISchedulingRule rule = ruleFactory.createRule(target.getProject());

    //IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
    job.setRule(rule);
    job.setUser(true);
    job.schedule(); // start as soon as possible
}

From source file:org.evosuite.eclipse.quickfixes.MarkerWriter.java

License:Open Source License

public void writeMarkers() {
    System.out.println(tgr);//  w  w  w .  j a  va2 s.  c  o m
    // ServerStatistics.getInstance().getX(); (getCoverage();)
    ASTParser parser = ASTParser.newParser(AST.JLS4);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(true);
    parser.setSource(tgr.getTestSuiteCode().toCharArray());

    CompilationUnit compTest = (CompilationUnit) parser.createAST(null);
    IJavaElement jEle = JavaCore.create(res);

    if (jEle instanceof ICompilationUnit) {

        final ICompilationUnit icomp = (ICompilationUnit) jEle;
        // System.out.println(icomp);
        BufferedReader br;
        char[] varcontent = null;
        try {
            br = new BufferedReader(new FileReader(res.getLocation().toFile()));
            int size = 0;
            while (br.read() != -1) {
                size++;
            }
            // String content = "";
            // String line = br.readLine();
            // content += line;
            // while ((line = br.readLine()) != null){
            // content += line;
            // }
            // parser.setSource(content.toCharArray());
            br = new BufferedReader(new FileReader(res.getLocation().toFile()));
            varcontent = new char[size];
            br.read(varcontent, 0, size);
            parser.setSource(varcontent);
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        final char[] content = varcontent;
        final CompilationUnit compClass = (CompilationUnit) parser.createAST(null);
        compTest.accept(testM);
        compClass.accept(raw);
        IJavaElement element = JavaCore.create(res);
        IJavaElement packageElement = element.getParent();

        String packageName = packageElement.getElementName();

        final String className = (!packageName.isEmpty() ? packageName + "." : "")
                + res.getName().replace(".java", "").replace(File.separator, ".");

        final char[] classContent = varcontent;
        if (tgr != null) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    ArrayList<Integer> lines = new ArrayList<Integer>();
                    Set<Integer> actualLines = new HashSet<Integer>();
                    actualLines.addAll(tgr.getUncoveredLines());
                    actualLines.addAll(tgr.getCoveredLines());
                    int contentPosition = 0;
                    int line = 1;
                    while (contentPosition != -2 && contentPosition != -1) {
                        if (!actualLines.contains(line)) {
                            lines.add(line);
                        }
                        contentPosition = compClass.getPosition(line, 0);
                        line++;
                    }

                    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
                    if (store.getBoolean("removed")) {
                        for (Integer i : lines) {
                            // this line couldn't be reached in the test!
                            IJavaElement currentElement = null;
                            int position = compClass.getPosition(i, 0);
                            int maxPosition = compClass.getPosition(i + 1, 0);
                            if (position == -1 || position == -2) {
                                continue;
                            }
                            while (position < classContent.length
                                    && Character.isWhitespace(classContent[position])) {
                                // System.out.println(classContent);
                                position++;
                            }
                            if (position > maxPosition) {
                                continue;
                            }
                            while (maxPosition < classContent.length
                                    && Character.isWhitespace(classContent[maxPosition])) {
                                // System.out.println(classContent);
                                maxPosition++;
                            }
                            try {
                                currentElement = icomp.getElementAt(position + 1);
                            } catch (JavaModelException e1) {
                                e1.printStackTrace();
                            }
                            if (isMethodDeclaration(i, currentElement, content, compClass, icomp)) {
                                continue;
                            }
                            IJavaElement nextElement = null;
                            int nextPosition = compClass.getPosition(i + 1, 0);
                            if (nextPosition != -1 || nextPosition != -2) {
                                try {
                                    nextElement = icomp.getElementAt(nextPosition);
                                    if (nextElement != currentElement) {
                                        continue;
                                    }
                                } catch (JavaModelException e) {
                                    e.printStackTrace();
                                }
                            }
                            if (position > maxPosition) {
                                continue;
                            }
                            while (maxPosition < classContent.length
                                    && Character.isWhitespace(classContent[maxPosition])) {
                                // System.out.println(classContent);
                                maxPosition++;
                            }
                            try {
                                currentElement = icomp.getElementAt(position + 1);
                            } catch (JavaModelException e1) {
                                e1.printStackTrace();
                            }
                            if (content[position] == '/' && content[position + 1] == '/') {
                                continue;
                            }
                            if (content[position] == '}') {
                                continue;
                            }

                            if (getMethod(currentElement) == null) {
                                continue;
                            }
                            boolean marker = shouldWriteMarkers(currentElement);
                            if (marker) {
                                try {
                                    IMarker m = res.createMarker("EvoSuiteQuickFixes.lineremovedmarker");
                                    m.setAttribute(IMarker.MESSAGE,
                                            "This line appears to be removed by the Java Compiler.");
                                    m.setAttribute(IMarker.LINE_NUMBER, i);
                                    m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
                                    m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                                    m.setAttribute(IMarker.LOCATION, res.getName());
                                    m.setAttribute(IMarker.CHAR_START, position);
                                    m.setAttribute(IMarker.CHAR_END, compClass.getPosition(i + 1, 0));

                                } catch (CoreException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }

                    if (store.getBoolean("uncovered")) {
                        for (Integer i : tgr.getUncoveredLines()) {
                            // this line couldn't be reached in the test!

                            IJavaElement currentElement = null;
                            int position = compClass.getPosition(i, 0);
                            if (position == -1) {
                                continue;
                            }
                            while (position < classContent.length
                                    && Character.isWhitespace(classContent[position])) {
                                // System.out.println(classContent);
                                position++;
                            }
                            try {
                                currentElement = icomp.getElementAt(position + 1);
                            } catch (JavaModelException e1) {
                                e1.printStackTrace();
                            }
                            boolean marker = shouldWriteMarkers(currentElement);
                            if (marker) {
                                try {
                                    IMarker m = res.createMarker("EvoSuiteQuickFixes.uncoveredlinemarker");
                                    m.setAttribute(IMarker.LINE_NUMBER, i);
                                    m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
                                    m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                                    m.setAttribute(IMarker.LOCATION, res.getName());
                                    m.setAttribute(IMarker.CHAR_START, position);
                                    m.setAttribute(IMarker.CHAR_END, compClass.getPosition(i + 1, 0));

                                } catch (CoreException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }

                    for (BranchInfo bi : tgr.getUncoveredBranches()) {
                        int j = bi.getLineNo();
                        IJavaElement currentElement = null;
                        int position = compClass.getPosition(j, 0);
                        while (position < classContent.length
                                && Character.isWhitespace(classContent[position])) {
                            // System.out.println(classContent);
                            position++;
                        }
                        try {
                            currentElement = icomp.getElementAt(position + 1);
                        } catch (JavaModelException e1) {
                            e1.printStackTrace();
                        }
                        boolean marker = shouldWriteMarkers(currentElement);
                        if (marker) {
                            try {
                                IMarker m = res.createMarker("EvoSuiteQuickFixes.notcoveredmarker");
                                m.setAttribute(IMarker.MESSAGE, "This branch (starting line " + j
                                        + ") could not be covered by EvoSuite.");
                                m.setAttribute(IMarker.LINE_NUMBER, j);
                                m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
                                m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                                m.setAttribute(IMarker.LOCATION, res.getName());
                                m = res.createMarker("EvoSuiteQuickFixes.uncoveredlinemarker");
                                // m.setAttribute(IMarker.LINE_NUMBER, j);
                                m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
                                m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                                m.setAttribute(IMarker.LOCATION, res.getName());
                                m.setAttribute(IMarker.CHAR_START, position);
                                m.setAttribute(IMarker.CHAR_END, compClass.getPosition(j + 1, 0) - 1);

                                m.setAttribute(IMarker.CHAR_START, position);
                                m.setAttribute(IMarker.CHAR_END, compClass.getPosition(j + 1, 0) - 1);

                            } catch (CoreException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                    for (MethodDeclaration method : testM.getMethods()) {
                        String test = method.getName().getFullyQualifiedName();
                        Set<Failure> failures = tgr.getContractViolations(test);
                        if (failures != null && failures.size() != 0) {
                            // uncaught Exception!
                            try {
                                for (Failure f : failures) {
                                    if (f != null) {
                                        int lineNumber = 1;
                                        String message = "";
                                        for (int i = 0; i < f.getStackTrace().length; i++) {
                                            if (f.getStackTrace()[i].getClassName().equals(className)) {
                                                boolean found = false;

                                                for (MethodDeclaration method2 : raw.getMethods()) {
                                                    String s = method2.getName().getFullyQualifiedName();
                                                    if (s.equals(f.getStackTrace()[i].getMethodName())) {
                                                        found = true;
                                                        break;
                                                    }
                                                }
                                                if (found) {
                                                    message = f.getStackTrace()[i].toString();
                                                    lineNumber = f.getStackTrace()[i].getLineNumber();
                                                    break;
                                                }
                                            }
                                        }
                                        IJavaElement currentElement = null;
                                        int position = compClass.getPosition(lineNumber, 0);
                                        while (position < classContent.length
                                                && Character.isWhitespace(classContent[position])) {
                                            // System.out.println(classContent);
                                            position++;
                                        }
                                        try {
                                            currentElement = icomp.getElementAt(position + 1);
                                        } catch (JavaModelException e1) {
                                            e1.printStackTrace();
                                        }
                                        boolean marker = shouldWriteMarkers(currentElement);
                                        if (marker) {
                                            IMarker m = res.createMarker("EvoSuiteQuickFixes.exceptionmarker");
                                            m.setAttribute(IMarker.MESSAGE,
                                                    f.getExceptionName() + " detected " + message);
                                            m.setAttribute(IMarker.LINE_NUMBER, lineNumber);
                                            m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
                                            m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
                                            m.setAttribute(IMarker.LOCATION, res.getName());
                                            while (position < classContent.length
                                                    && Character.isWhitespace(classContent[position])) {
                                                // System.out.println(classContent);
                                                position++;
                                            }
                                            m.setAttribute(IMarker.CHAR_START, position);
                                            m.setAttribute(IMarker.CHAR_END,
                                                    compClass.getPosition(lineNumber + 1, 0) - 1);
                                        }
                                    }
                                }
                            } catch (CoreException e) {
                                e.printStackTrace();
                            }
                        }

                    }

                }

            });
        }
    }
}