/** * Returns the type of the enclosing type. * * @param element java element * @return TYPE_INTERFACE, TYPE_CLASS, TYPE_ENUM, TYPE_ANNOTATION or -1 * @throws JavaModelException */ private int getType(IJavaElement element) throws JavaModelException { IJavaElement lelement = element; while (lelement != null && lelement.getElementType() != IJavaElement.TYPE) { lelement = lelement.getParent(); } if (lelement instanceof IType) { IType type = (IType) lelement; if (type.isAnnotation()) { return IApiJavadocTag.TYPE_ANNOTATION; } else if (type.isInterface()) { return IApiJavadocTag.TYPE_INTERFACE; } else if (type.isEnum()) { return IApiJavadocTag.TYPE_ENUM; } } return IApiJavadocTag.TYPE_CLASS; }
/* * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.text.ITextSelection) */ @Override public void run(ITextSelection selection) { try { final IType type = SelectionConverter.getTypeAtOffset(fEditor); if (type != null) { if (!ElementValidator.check(type, getShell(), getDialogTitle(), false) || !ActionUtil.isEditable(fEditor, getShell(), type)) { notifyResult(false); return; } if (type.isAnnotation()) { MessageDialog.openInformation( getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_annotation_not_applicable); notifyResult(false); return; } if (type.isInterface()) { MessageDialog.openInformation( getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_interface_not_applicable); notifyResult(false); return; } run(getShell(), type); } else { MessageDialog.openInformation( getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_not_applicable); } } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); } catch (CoreException e) { ExceptionHandler.handle( e, getShell(), getDialogTitle(), ActionMessages.OverrideMethodsAction_error_actionfailed); } }
private void extractIType(IType type) { try { String fqn = type.getFullyQualifiedName(); // Write the entity if (type.isClass()) { entityWriter.writeClass(fqn, type.getFlags(), path); // Write the superclass String superSig = type.getSuperclassTypeSignature(); if (superSig != null) { relationWriter.writeExtends(fqn, typeSignatureToFqn(superSig), path); } } else if (type.isAnnotation()) { entityWriter.writeAnnotation(fqn, type.getFlags(), path); } else if (type.isInterface()) { entityWriter.writeInterface(fqn, type.getFlags(), path); } else if (type.isEnum()) { entityWriter.writeEnum(fqn, type.getFlags(), path); } // Write the superinterfaces for (String superIntSig : type.getSuperInterfaceTypeSignatures()) { relationWriter.writeImplements(fqn, typeSignatureToFqn(superIntSig), path); } if (!fqnStack.isEmpty()) { relationWriter.writeInside(type.getFullyQualifiedName(), fqnStack.peek(), path); } fqnStack.push(type.getFullyQualifiedName()); for (IType child : type.getTypes()) { extractIType(child); } for (IField field : type.getFields()) { if (!Flags.isSynthetic(field.getFlags())) { extractIField(field); } } for (IMethod method : type.getMethods()) { if (!Flags.isSynthetic(method.getFlags()) || (Flags.isSynthetic(method.getFlags()) && method.isConstructor() && method.getParameterTypes().length == 0)) { extractIMethod(method, type.isAnnotation()); } } int pos = 0; for (ITypeParameter param : type.getTypeParameters()) { relationWriter.writeParametrizedBy(fqn, getTypeParam(param), pos++, path); } fqnStack.pop(); } catch (Exception e) { logger.log(Level.SEVERE, "Error in extracting class file", e); } }