Search in sources :

Example 31 with IMember

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

the class JavaElementLabelComposer method appendTypeParameterLabel.

/**
	 * Appends the styled label for a type parameter.
	 *
	 * @param typeParameter the element to render
	 * @param flags the rendering flags. Flags with names starting with 'T_' are considered.
	 */
public void appendTypeParameterLabel(ITypeParameter typeParameter, long flags) {
    try {
        appendTypeParameterWithBounds(typeParameter, flags);
        // post qualification
        if (getFlag(flags, JavaElementLabels.TP_POST_QUALIFIED)) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            IMember declaringMember = typeParameter.getDeclaringMember();
            appendElementLabel(declaringMember, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
        }
    } catch (JavaModelException e) {
        // NotExistsException will not reach this point
        JavaPlugin.log(e);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IMember(org.eclipse.jdt.core.IMember)

Example 32 with IMember

use of org.eclipse.jdt.core.IMember in project flux by eclipse.

the class JavaDocService method getJavadoc.

public JSONObject getJavadoc(String username, String requestorResourcePath, int offset, int length) {
    try {
        ICompilationUnit liveEditUnit = liveEditUnits.getLiveEditUnit(username, requestorResourcePath);
        if (liveEditUnit != null) {
            IJavaElement[] elements = liveEditUnit.codeSelect(offset, length);
            if (elements != null && elements.length > 0) {
                JSONObject result = new JSONObject();
                IJavaElement element = elements[0];
                String javadoc = null;
                if (element instanceof IMember && !((IMember) element).isBinary()) {
                    javadoc = getJavadocFromSourceElement((IMember) element);
                } else {
                    javadoc = element.getAttachedJavadoc(null);
                }
                result.put("javadoc", javadoc);
                return result;
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IMember(org.eclipse.jdt.core.IMember)

Example 33 with IMember

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

the class RenameTypeTest method checkMappers.

private void checkMappers(Refactoring refactoring, IType type, String newCUName, IJavaElement[] someClassMembers) {
    RenameTypeProcessor rtp = (RenameTypeProcessor) ((RenameRefactoring) refactoring).getProcessor();
    ICompilationUnit newUnit = (ICompilationUnit) rtp.getRefactoredJavaElement(type.getCompilationUnit());
    TestCase.assertTrue(newUnit.exists());
    TestCase.assertTrue(newUnit.getElementName().equals(newCUName));
    IFile newFile = (IFile) rtp.getRefactoredResource(type.getResource());
    TestCase.assertTrue(newFile.exists());
    TestCase.assertTrue(newFile.getName().equals(newCUName));
    if ((type.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) && type.getCompilationUnit().getElementName().equals(type.getElementName() + ".java")) {
        Assert.assertFalse(type.getCompilationUnit().exists());
        Assert.assertFalse(type.getResource().exists());
    }
    IPackageFragment oldPackage = (IPackageFragment) type.getCompilationUnit().getParent();
    IPackageFragment newPackage = (IPackageFragment) rtp.getRefactoredJavaElement(oldPackage);
    Assert.assertEquals(oldPackage, newPackage);
    for (int i = 0; i < someClassMembers.length; i++) {
        IMember member = (IMember) someClassMembers[i];
        IJavaElement refactoredMember = rtp.getRefactoredJavaElement(member);
        if (member instanceof IMethod && member.getElementName().equals(type.getElementName()))
            // constructor
            continue;
        TestCase.assertTrue(refactoredMember.exists());
        Assert.assertEquals(member.getElementName(), refactoredMember.getElementName());
        Assert.assertFalse(refactoredMember.equals(member));
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) RenameTypeProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor) IMethod(org.eclipse.jdt.core.IMethod) IMember(org.eclipse.jdt.core.IMember)

Aggregations

IMember (org.eclipse.jdt.core.IMember)33 IType (org.eclipse.jdt.core.IType)15 IJavaElement (org.eclipse.jdt.core.IJavaElement)14 IMethod (org.eclipse.jdt.core.IMethod)13 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 List (java.util.List)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 IField (org.eclipse.jdt.core.IField)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4 CompilationUnitRewrite (org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 ISourceRange (org.eclipse.jdt.core.ISourceRange)3 ASTNode (org.eclipse.jdt.core.dom.ASTNode)3 HashMap (java.util.HashMap)2 IInitializer (org.eclipse.jdt.core.IInitializer)2