Search in sources :

Example 16 with IField

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

the class JavaElementToDtoConverter method getFields.

private List<Field> getFields(Object parent) throws JavaModelException {
    List<Field> result = new ArrayList<>();
    Set<Object> objects = childrens.get(parent);
    if (objects == null) {
        return result;
    }
    for (Object object : objects) {
        if (object instanceof IField) {
            IField iField = (IField) object;
            Field field = DtoFactory.newDto(Field.class);
            field.setElementName(iField.getElementName());
            field.setHandleIdentifier(iField.getHandleIdentifier());
            field.setFlags(iField.getFlags());
            field.setLabel(JavaElementLabels.getElementLabel(iField, JavaElementLabels.ALL_DEFAULT));
            result.add(field);
        }
    }
    return result;
}
Also used : IField(org.eclipse.jdt.core.IField) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) ArrayList(java.util.ArrayList) IField(org.eclipse.jdt.core.IField)

Example 17 with IField

use of org.eclipse.jdt.core.IField 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 18 with IField

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

the class StubCreator method appendEnumConstants.

protected void appendEnumConstants(final IType type) throws JavaModelException {
    final IField[] fields = type.getFields();
    final List<IField> list = new ArrayList<IField>(fields.length);
    for (int index = 0; index < fields.length; index++) {
        final IField field = fields[index];
        if (Flags.isEnum(field.getFlags()))
            list.add(field);
    }
    for (int index = 0; index < list.size(); index++) {
        if (index > 0)
            //$NON-NLS-1$
            fBuffer.append(",");
        fBuffer.append(list.get(index).getElementName());
    }
    //$NON-NLS-1$
    fBuffer.append(";");
}
Also used : ArrayList(java.util.ArrayList) IField(org.eclipse.jdt.core.IField)

Example 19 with IField

use of org.eclipse.jdt.core.IField 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 20 with IField

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

the class MemberVisibilityAdjustor method adjustIncomingVisibility.

/**
	 * Adjusts the visibility of the specified member.
	 *
	 * @param element the "source" point from which to calculate the visibility
	 * @param referencedMovedElement the moved element which may be adjusted in visibility
	 * @param monitor the progress monitor to use
	 * @throws JavaModelException if the visibility adjustment could not be computed
	 */
private void adjustIncomingVisibility(final IJavaElement element, IMember referencedMovedElement, final IProgressMonitor monitor) throws JavaModelException {
    final ModifierKeyword threshold = getVisibilityThreshold(element, referencedMovedElement, monitor);
    int flags = referencedMovedElement.getFlags();
    IType declaring = referencedMovedElement.getDeclaringType();
    if (declaring != null && declaring.isInterface() || referencedMovedElement instanceof IField && Flags.isEnum(referencedMovedElement.getFlags()))
        return;
    if (hasLowerVisibility(flags, threshold == null ? Modifier.NONE : threshold.toFlagValue()) && needsVisibilityAdjustment(referencedMovedElement, threshold))
        fAdjustments.put(referencedMovedElement, new IncomingMemberVisibilityAdjustment(referencedMovedElement, threshold, RefactoringStatus.createStatus(fVisibilitySeverity, Messages.format(getMessage(referencedMovedElement), new String[] { getLabel(referencedMovedElement), getLabel(threshold) }), JavaStatusContext.create(referencedMovedElement), null, RefactoringStatusEntry.NO_CODE, null)));
}
Also used : ModifierKeyword(org.eclipse.jdt.core.dom.Modifier.ModifierKeyword) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType)

Aggregations

IField (org.eclipse.jdt.core.IField)47 IType (org.eclipse.jdt.core.IType)30 IMethod (org.eclipse.jdt.core.IMethod)15 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)15 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)14 IJavaElement (org.eclipse.jdt.core.IJavaElement)14 ArrayList (java.util.ArrayList)13 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)9 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)6 Test (org.junit.Test)6 List (java.util.List)5 ILocalVariable (org.eclipse.jdt.core.ILocalVariable)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)5 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 IMember (org.eclipse.jdt.core.IMember)4 ISourceRange (org.eclipse.jdt.core.ISourceRange)4 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)4 Field (org.eclipse.che.ide.ext.java.shared.dto.model.Field)3