Search in sources :

Example 51 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class AnonymousTypeCompletionProposal method updateReplacementString.

/*
	 * @see org.eclipse.jdt.internal.ui.text.java.JavaTypeCompletionProposal#updateReplacementString(org.eclipse.jface.text.IDocument, char, int, org.eclipse.jdt.core.dom.rewrite.ImportRewrite)
	 */
@Override
protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException {
    fImportRewrite = impRewrite;
    String newBody = createNewBody(impRewrite);
    if (newBody == null)
        return false;
    CompletionProposal coreProposal = ((MemberProposalInfo) getProposalInfo()).fProposal;
    boolean isAnonymousConstructorInvoc = coreProposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION;
    //$NON-NLS-1$
    boolean replacementStringEndsWithParentheses = isAnonymousConstructorInvoc || getReplacementString().endsWith(")");
    // construct replacement text: an expression to be formatted
    //$NON-NLS-1$
    StringBuffer buf = new StringBuffer("new A(");
    if (!replacementStringEndsWithParentheses || isAnonymousConstructorInvoc)
        buf.append(')');
    buf.append(newBody);
    // use the code formatter
    String lineDelim = TextUtilities.getDefaultLineDelimiter(document);
    final IJavaProject project = fCompilationUnit.getJavaProject();
    IRegion lineInfo = document.getLineInformationOfOffset(getReplacementOffset());
    int indent = Strings.computeIndentUnits(document.get(lineInfo.getOffset(), lineInfo.getLength()), project);
    Map<String, String> options = project != null ? project.getOptions(true) : JavaCore.getOptions();
    options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, DefaultCodeFormatterConstants.TRUE);
    String replacementString = CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, buf.toString(), 0, lineDelim, options);
    int lineEndOffset = lineInfo.getOffset() + lineInfo.getLength();
    int p = offset;
    char ch = document.getChar(p);
    while (p < lineEndOffset) {
        if (ch == '(' || ch == ')' || ch == ';' || ch == ',')
            break;
        ch = document.getChar(++p);
    }
    if (ch != ';' && ch != ',' && ch != ')')
        replacementString = replacementString + ';';
    replacementString = Strings.changeIndent(replacementString, 0, project, CodeFormatterUtil.createIndentString(indent, project), lineDelim);
    int beginIndex = replacementString.indexOf('(');
    if (!isAnonymousConstructorInvoc)
        beginIndex++;
    replacementString = replacementString.substring(beginIndex);
    int pos = offset;
    if (isAnonymousConstructorInvoc && (insertCompletion() ^ isInsertModeToggled())) {
        // Keep existing code
        int endPos = pos;
        ch = document.getChar(endPos);
        while (endPos < lineEndOffset && ch != '(' && ch != ')' && ch != ';' && ch != ',' && !Character.isWhitespace(ch)) ch = document.getChar(++endPos);
        int keepLength = endPos - pos;
        if (keepLength > 0) {
            String keepStr = document.get(pos, keepLength);
            replacementString = replacementString + keepStr;
            setCursorPosition(replacementString.length() - keepLength);
        }
    } else
        setCursorPosition(replacementString.length());
    setReplacementString(replacementString);
    if (pos < document.getLength() && document.getChar(pos) == ')') {
        int currentLength = getReplacementLength();
        if (replacementStringEndsWithParentheses)
            setReplacementLength(currentLength + pos - offset);
        else
            setReplacementLength(currentLength + pos - offset + 1);
    }
    return false;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CompletionProposal(org.eclipse.jdt.core.CompletionProposal) StyledString(org.eclipse.jface.viewers.StyledString) IRegion(org.eclipse.jface.text.IRegion)

Example 52 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class ImportCompletionProposal method isJavadocProcessingEnabled.

/**
	 * Returns whether Javadoc processing is enabled.
	 *
	 * @return <code>true</code> if Javadoc processing is enabled, <code>false</code> otherwise
	 */
private boolean isJavadocProcessingEnabled() {
    IJavaProject project = fCompilationUnit.getJavaProject();
    boolean processJavadoc;
    if (project == null)
        processJavadoc = JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT));
    else
        processJavadoc = JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true));
    return processJavadoc;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 53 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class LazyJavaTypeCompletionProposal method isJavadocProcessingEnabled.

private boolean isJavadocProcessingEnabled() {
    IJavaProject project = fCompilationUnit.getJavaProject();
    boolean processJavadoc;
    if (project == null)
        processJavadoc = JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT));
    else
        processJavadoc = JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true));
    return processJavadoc;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 54 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project generator by mybatis.

the class RunGeneratorThread method getJavaProject.

private IJavaProject getJavaProject() {
    IJavaProject answer = null;
    IProject project = inputFile.getProject();
    try {
        if (project.hasNature(JavaCore.NATURE_ID)) {
            answer = JavaCore.create(project);
        }
    } catch (CoreException e) {
        // ignore - something is wrong
        ;
    }
    return answer;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject)

Example 55 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project generator by mybatis.

the class RunGeneratorThread method setClassLoader.

private void setClassLoader() {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IJavaProject javaProject = getJavaProject();
    try {
        if (javaProject != null) {
            List<URL> entries = new ArrayList<URL>();
            IPath path = javaProject.getOutputLocation();
            IResource iResource = root.findMember(path);
            path = iResource.getLocation();
            path = path.addTrailingSeparator();
            entries.add(path.toFile().toURI().toURL());
            IClasspathEntry[] cpEntries = javaProject.getRawClasspath();
            for (IClasspathEntry cpEntry : cpEntries) {
                switch(cpEntry.getEntryKind()) {
                    case IClasspathEntry.CPE_SOURCE:
                        path = cpEntry.getOutputLocation();
                        if (path != null) {
                            iResource = root.findMember(path);
                            path = iResource.getLocation();
                            path = path.addTrailingSeparator();
                            entries.add(path.toFile().toURI().toURL());
                        }
                        break;
                    case IClasspathEntry.CPE_LIBRARY:
                        iResource = root.findMember(cpEntry.getPath());
                        if (iResource == null) {
                            // resource is not in workspace, must be an external JAR
                            path = cpEntry.getPath();
                        } else {
                            path = iResource.getLocation();
                        }
                        entries.add(path.toFile().toURI().toURL());
                        break;
                }
            }
            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
            URL[] entryArray = new URL[entries.size()];
            entries.toArray(entryArray);
            ClassLoader newCl = new URLClassLoader(entryArray, oldCl);
            Thread.currentThread().setContextClassLoader(newCl);
            oldClassLoader = oldCl;
        }
    } catch (Exception e) {
        // ignore - something too complex is wrong
        ;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) XMLParserException(org.mybatis.generator.exception.XMLParserException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) IResource(org.eclipse.core.resources.IResource)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)743 IProject (org.eclipse.core.resources.IProject)178 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)146 CoreException (org.eclipse.core.runtime.CoreException)127 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)103 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)63 IType (org.eclipse.jdt.core.IType)63 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)62 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)56 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)47 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38