Search in sources :

Example 46 with IJavaElement

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

the class JavadocUrlTest method binaryFieldUri.

@Test
public void binaryFieldUri() throws JavaModelException, URISyntaxException, UnsupportedEncodingException {
    IType type = project.findType("java.util.ArrayList");
    IField field = type.getField("size");
    String uri = JavaElementLinks.createURI(urlPart, field);
    String handle = uri.substring(urlPart.length());
    handle = URLDecoder.decode(handle, "UTF-8");
    IJavaElement element = JavaElementLinks.parseURI(handle, project);
    assertThat(element).isNotNull().isEqualTo(field);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 47 with IJavaElement

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

the class JavadocFromSourceTest method testResolveBinaryMethodsParam.

@Test
public void testResolveBinaryMethodsParam() throws Exception {
    IJavaElement element = project.findElement("Ljava/lang/String;.endsWith(Ljava.lang.String;)Z", null);
    assertThat(element).isNotNull().isInstanceOf(IMethod.class);
    assertThat(element.getElementName()).isEqualTo("endsWith");
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) Test(org.junit.Test)

Example 48 with IJavaElement

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

the class PackageFragmentRootReorgChange method getUpdateModelFlags.

protected int getUpdateModelFlags(boolean isCopy) throws JavaModelException {
    final int destination = IPackageFragmentRoot.DESTINATION_PROJECT_CLASSPATH;
    final int replace = IPackageFragmentRoot.REPLACE;
    final int originating;
    final int otherProjects;
    if (isCopy) {
        //ORIGINATING_PROJECT_CLASSPATH does not apply to copy
        originating = 0;
        //OTHER_REFERRING_PROJECTS_CLASSPATH does not apply to copy
        otherProjects = 0;
    } else {
        originating = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH;
        otherProjects = IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
    }
    IJavaElement javaElement = JavaCore.create(getDestination());
    if (javaElement == null || !javaElement.exists())
        return replace | originating;
    if (fUpdateClasspathQuery == null)
        return replace | originating | destination;
    IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(getRoot());
    if (referencingProjects.length <= 1)
        return replace | originating | destination;
    boolean updateOtherProjectsToo = fUpdateClasspathQuery.confirmManipulation(getRoot(), referencingProjects);
    if (updateOtherProjectsToo)
        return replace | originating | destination | otherProjects;
    else
        return replace | originating | destination;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 49 with IJavaElement

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

the class StubCreator method appendMembers.

protected void appendMembers(final IType type, final IProgressMonitor monitor) throws JavaModelException {
    try {
        monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
        final IJavaElement[] children = type.getChildren();
        for (int index = 0; index < children.length; index++) {
            final IMember child = (IMember) children[index];
            final int flags = child.getFlags();
            final boolean isPrivate = Flags.isPrivate(flags);
            final boolean isDefault = !Flags.isPublic(flags) && !Flags.isProtected(flags) && !isPrivate;
            final boolean stub = fStubInvisible || (!isPrivate && !isDefault);
            if (child instanceof IType) {
                if (stub)
                    appendTypeDeclaration((IType) child, new SubProgressMonitor(monitor, 1));
            } else if (child instanceof IField) {
                if (stub && !Flags.isEnum(flags) && !Flags.isSynthetic(flags))
                    appendFieldDeclaration((IField) child);
            } else if (child instanceof IMethod) {
                final IMethod method = (IMethod) child;
                final String name = method.getElementName();
                if (method.getDeclaringType().isEnum()) {
                    final int count = method.getNumberOfParameters();
                    if (//$NON-NLS-1$
                    count == 0 && "values".equals(name))
                        continue;
                    if (//$NON-NLS-1$ //$NON-NLS-2$
                    count == 1 && "valueOf".equals(name) && "Ljava.lang.String;".equals(method.getParameterTypes()[0]))
                        continue;
                    if (method.isConstructor())
                        continue;
                }
                //$NON-NLS-1$
                boolean skip = !stub || name.equals("<clinit>");
                if (method.isConstructor())
                    skip = false;
                skip = skip || Flags.isSynthetic(flags) || Flags.isBridge(flags);
                if (!skip)
                    appendMethodDeclaration(method);
            }
            //$NON-NLS-1$
            fBuffer.append("\n");
        }
    } finally {
        monitor.done();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IMember(org.eclipse.jdt.core.IMember) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 50 with IJavaElement

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

the class RefactoringSearchEngine method findAffectedCompilationUnits.

//TODO: throw CoreException
public static ICompilationUnit[] findAffectedCompilationUnits(SearchPattern pattern, IJavaSearchScope scope, final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches) throws JavaModelException {
    boolean hasNonCuMatches = false;
    class ResourceSearchRequestor extends SearchRequestor {

        boolean hasPotentialMatches = false;

        Set<IResource> resources = new HashSet<IResource>(5);

        private IResource fLastResource;

        @Override
        public void acceptSearchMatch(SearchMatch match) {
            if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
                hasPotentialMatches = true;
            }
            if (fLastResource != match.getResource()) {
                fLastResource = match.getResource();
                resources.add(fLastResource);
            }
        }
    }
    ResourceSearchRequestor requestor = new ResourceSearchRequestor();
    try {
        new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
    List<IJavaElement> result = new ArrayList<IJavaElement>(requestor.resources.size());
    for (Iterator<IResource> iter = requestor.resources.iterator(); iter.hasNext(); ) {
        IResource resource = iter.next();
        IJavaElement element = JavaCore.create(resource);
        if (element instanceof ICompilationUnit) {
            result.add(element);
        } else {
            hasNonCuMatches = true;
        }
    }
    addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
    return result.toArray(new ICompilationUnit[result.size()]);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)226 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 IType (org.eclipse.jdt.core.IType)44 ArrayList (java.util.ArrayList)35 IJavaProject (org.eclipse.jdt.core.IJavaProject)35 IMethod (org.eclipse.jdt.core.IMethod)34 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)32 JavaModelException (org.eclipse.jdt.core.JavaModelException)32 IResource (org.eclipse.core.resources.IResource)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)28 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)23 IField (org.eclipse.jdt.core.IField)16 IMember (org.eclipse.jdt.core.IMember)14 Test (org.junit.Test)14 CoreException (org.eclipse.core.runtime.CoreException)13 StringTokenizer (java.util.StringTokenizer)11 ISourceRange (org.eclipse.jdt.core.ISourceRange)11 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)11 IPath (org.eclipse.core.runtime.IPath)10 HashMap (java.util.HashMap)9