List of usage examples for org.eclipse.jdt.core IType getElementName
@Override String getElementName();
From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.contentassist.FXGraphProposalProvider.java
License:Open Source License
@Override public void completeReferenceValueProperty_Reference(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (!model.eResource().getContents().isEmpty()) { Model m = (Model) model.eResource().getContents().get(0); if (m.getComponentDef() != null) { for (Define d : m.getComponentDef().getDefines()) { Element element = d.getElement(); boolean includeType = false; if (element == null) { element = d.getIncludeElement().getSource().getRootNode(); includeType = true;//from w w w. j a v a 2 s .com } IJavaProject javaProject = projectProvider.getJavaProject(element.eResource().getResourceSet()); try { IType defType = javaProject.findType(element.getType().getQualifiedName()); ReferenceValueProperty rp = (ReferenceValueProperty) model; IType targetType = null; if (rp.eContainer() instanceof Property) { Property p = (Property) rp.eContainer(); if (p.eContainer() instanceof Element) { Element e = (Element) p.eContainer(); IType ownerType = javaProject.findType(e.getType().getQualifiedName()); IFXClass ownerClass = FXPlugin.getClassmodel().findClass(javaProject, ownerType); IFXProperty ownerProp = ownerClass.getProperty(p.getName()); if (ownerProp instanceof IFXObjectProperty) { targetType = ((IFXObjectProperty) ownerProp).getElementType(); } } } else if (rp.eContainer() instanceof StaticCallValueProperty) { LOGGER.warn("Unable to extract type for " + rp.eContainer()); } else if (rp.eContainer() instanceof ListValueProperty) { ListValueProperty lvp = (ListValueProperty) rp.eContainer(); if (lvp.eContainer() instanceof Property) { Property p = (Property) lvp.eContainer(); if (p.eContainer() instanceof Element) { Element e = (Element) p.eContainer(); IType ownerType = javaProject.findType(e.getType().getQualifiedName()); IFXClass ownerClass = FXPlugin.getClassmodel().findClass(javaProject, ownerType); IFXProperty ownerProp = ownerClass.getProperty(p.getName()); if (ownerProp instanceof IFXCollectionProperty) { targetType = ((IFXCollectionProperty) ownerProp).getElementType(); } } } else { LOGGER.warn("Unable to extract type for " + rp.eContainer()); } } if (targetType != null) { if (Util.assignable(defType, targetType)) { StyledString s = new StyledString( includeType ? d.getIncludeElement().getName() : element.getName()); s.append(" - " + defType.getElementName(), StyledString.QUALIFIER_STYLER); acceptor.accept(createCompletionProposal( includeType ? d.getIncludeElement().getName() : element.getName(), s, IconKeys.getIcon(IconKeys.CLASS_KEY), context)); } } } catch (JavaModelException e) { LOGGER.error("Unable to extract define type", e); } } } } }
From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.wizards.FXGraphWizardPage.java
License:Open Source License
@Override protected void createFields(Composite parent, DataBindingContext dbc) { {/*from ww w . j av a 2s.co m*/ Label l = new Label(parent, SWT.NONE); l.setText("Root Element"); final ComboViewer viewer = new ComboViewer(parent); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { IType t = (IType) element; return t.getElementName() + " - " + t.getPackageFragment().getElementName(); } }); viewer.setContentProvider(new ArrayContentProvider()); List<IType> types = getTypes(); viewer.setInput(types); viewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button button = new Button(parent, SWT.PUSH); button.setText("Browse ..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IType type = findContainerType(); if (type != null) { customSelection = type; viewer.setInput(getTypes()); viewer.setSelection(new StructuredSelection(type)); } } }); FXGraphElement element = getClazz(); element.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("fragmentRoot".equals(evt.getPropertyName())) { viewer.setInput(getTypes()); } } }); dbc.bindValue(ViewerProperties.singleSelection().observe(viewer), BeanProperties.value("rootElement").observe(getClazz())); if (types.size() > 0) { viewer.setSelection(new StructuredSelection(types.get(0))); } } { Label l = new Label(parent, SWT.NONE); l.setText("Dynamic Root (fx:root)"); Button b = new Button(parent, SWT.CHECK); dbc.bindValue(WidgetProperties.selection().observe(b), BeanProperties.value("dynamic").observe(getClazz())); } }
From source file:at.bestsolution.efxclipse.tooling.fxgraph.validation.FXGraphJavaValidator.java
License:Open Source License
@Check public void validate(Element element) { JvmTypeReference controller = ((Model) element.eResource().getContents().get(0)).getComponentDef() .getController();/*from ww w .ja v a2 s . com*/ if (controller != null && element.getName() != null) { IJavaProject javaProject = projectProvider.getJavaProject(element.eResource().getResourceSet()); try { IType type = javaProject.findType(controller.getQualifiedName()); IFXCtrlClass fxClazz = FXPlugin.getClassmodel().findCtrlClass(javaProject, type); if (fxClazz != null) { IFXCtrlField f = fxClazz.getAllFields().get(element.getName()); if (f == null) { // Defines should not lead to a warning because it is referenced later on if (!(element.eContainer() instanceof Define)) { warning("The controller '" + type.getElementName() + "' has no field '" + element.getName() + "'", FXGraphPackage.Literals.ELEMENT__NAME, UNKNOWN_CONTROLLER_FIELD, element.getName(), controller.getQualifiedName(), element.getType().getQualifiedName()); } } else { IType fromType = javaProject.findType(element.getType().getQualifiedName()); IType toType = f.getType(); if (!Util.assignable(fromType, toType)) { error("The type '" + fromType.getElementName() + "' is not assignable to the controller fields type '" + toType.getElementName() + "'", FXGraphPackage.Literals.ELEMENT__NAME, CONTROLLER_FIELD_NOT_ASSIGNABLE, element.getName(), controller.getQualifiedName(), element.getType().getQualifiedName()); } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:at.bestsolution.efxclipse.tooling.fxgraph.validation.FXGraphJavaValidator.java
License:Open Source License
@Check public void validate(ControllerHandledValueProperty element) { JvmTypeReference controller = ((Model) element.eResource().getContents().get(0)).getComponentDef() .getController();/*from ww w. j a va 2 s. c o m*/ if (controller != null && element.getMethodname() != null) { IJavaProject javaProject = projectProvider.getJavaProject(element.eResource().getResourceSet()); try { IType ctrlType = javaProject.findType(controller.getQualifiedName()); Property propertyModel = (Property) element.eContainer(); Element elementModel = (Element) propertyModel.eContainer(); IType elType = javaProject.findType(elementModel.getType().getQualifiedName()); IFXCtrlClass fxCtrlClazz = FXPlugin.getClassmodel().findCtrlClass(javaProject, ctrlType); IFXClass fxElClass = FXPlugin.getClassmodel().findClass(javaProject, elType); IFXProperty fxProp = fxElClass.getAllProperties().get(propertyModel.getName()); if (!(fxProp instanceof IFXEventHandlerProperty)) { error("Property is not an event property", propertyModel, FXGraphPackage.Literals.PROPERTY__NAME, -1); return; } if (fxCtrlClazz != null) { IFXCtrlEventMethod m = fxCtrlClazz.getAllEventMethods().get(element.getMethodname()); if (m == null) { warning("The controller '" + ctrlType.getElementName() + "' has no event method '" + element.getMethodname() + "'", FXGraphPackage.Literals.CONTROLLER_HANDLED_VALUE_PROPERTY__METHODNAME, UNKNOWN_CONTROLLER_METHOD, element.getMethodname(), controller.getQualifiedName(), ((IFXEventHandlerProperty) fxProp).getEventType().getFullyQualifiedName()); } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:at.bestsolution.efxclipse.tooling.fxml.wizards.FXMLWizardPage.java
License:Open Source License
@Override protected void createFields(Composite parent, DataBindingContext dbc) { {/*from w w w . ja va 2 s. c o m*/ Label l = new Label(parent, SWT.NONE); l.setText("Root Element"); final ComboViewer viewer = new ComboViewer(parent); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { IType t = (IType) element; return t.getElementName() + " - " + t.getPackageFragment().getElementName(); } }); viewer.setContentProvider(new ArrayContentProvider()); List<IType> types = getTypes(); viewer.setInput(types); viewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button button = new Button(parent, SWT.PUSH); button.setText("Browse ..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IType type = findContainerType(); if (type != null) { customSelection = type; viewer.setInput(getTypes()); viewer.setSelection(new StructuredSelection(type)); } } }); FXMLElement element = getClazz(); element.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("fragmentRoot".equals(evt.getPropertyName())) { viewer.setInput(getTypes()); } } }); dbc.bindValue(ViewerProperties.singleSelection().observe(viewer), BeanProperties.value("rootElement").observe(getClazz())); if (types.size() > 0) { viewer.setSelection(new StructuredSelection(types.get(0))); } } { Label l = new Label(parent, SWT.NONE); l.setText("Dynamic Root (fx:root)"); Button b = new Button(parent, SWT.CHECK); dbc.bindValue(WidgetProperties.selection().observe(b), BeanProperties.value("fxRoot").observe(getClazz())); } }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXEventHandlerProperty.java
License:Open Source License
@Override public String getEventTypeAsString(boolean fqn) { IType t = getEventType(); if (t == null) { return "?"; }/* www . j ava 2 s . c o m*/ return fqn ? t.getFullyQualifiedName() : t.getElementName(); }
From source file:bndtools.editor.components.MethodProposalLabelProvider.java
License:Open Source License
private static StyledString getStyledString(Object element) { MethodContentProposal proposal = (MethodContentProposal) element; IMethod method = proposal.getMethod(); String methodName = method.getElementName(); IType type = method.getDeclaringType(); String typeName = type.getElementName(); StyledString styledString = new StyledString(methodName); styledString.append(": " + typeName, StyledString.QUALIFIER_STYLER); return styledString; }
From source file:bndtools.utils.JavaTypeContentProposal.java
License:Open Source License
public JavaTypeContentProposal(IType element) throws JavaModelException { super(element.getPackageFragment().getElementName(), element.getElementName(), element.isInterface()); this.element = element; }
From source file:ca.mt.wb.devtools.tx.InheritanceView.java
License:unlicense.org
protected void addSubTypes(final IType type) { Job job = new Job("Add Subtypes") { @Override//from www.j a va2 s . c om protected IStatus run(IProgressMonitor monitor) { monitor.beginTask("Adding subtypes of " + type.getElementName(), 100); try { monitor.subTask("Computing type hierarchy"); ITypeHierarchy hierarchy = type.newTypeHierarchy(new SubProgressMonitor(monitor, 90)); monitor.subTask("Adding elements"); final Collection<IType> subtypes = Arrays.asList(hierarchy.getSubtypes(type)); monitor.worked(10); getDisplay().asyncExec(new Runnable() { public void run() { addTypes(subtypes); } }); } catch (JavaModelException e) { return new Status(IStatus.ERROR, "ca.mt.wb.devtools.tx", "Error occurred computing type hierarchy for " + type.getElementName(), e); } finally { monitor.done(); } return Status.OK_STATUS; } }; job.schedule(); }
From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java
License:Open Source License
/** * @param scope//from w ww . j a va 2s. c o m * @param monitor * @param classSignature * @param methodName * @param signature * @return * @throws CoreException * @throws InterruptedException */ public static IJavaElement searchForMethod(IJavaSearchScope scope, IProgressMonitor monitor, String classSignature, String methodName, String signature) throws CoreException, InterruptedException { SubProgressMonitor typeMonitor = new SubProgressMonitor(monitor, 100); SubProgressMonitor hierarchyMonitor = new SubProgressMonitor(monitor, 100); IType foundType = (IType) searchForType(classSignature, scope, typeMonitor); if (foundType == null) return null; boolean isConstructor = false; if (methodName.startsWith("<init")) { isConstructor = true; boolean i = isConstructor; boolean isAnonymous = false; if (!foundType.exists()) { //check anonymity using the dollar sign String elementName = foundType.getElementName(); if (elementName.length() > 0 && Character.isDigit(elementName.charAt(0))) { isAnonymous = true; } } else { isAnonymous = foundType.isAnonymous(); } if (isAnonymous) { methodName = ""; } else { methodName = foundType.getElementName(); } } String[] methodParamTypes = Signature.getParameterTypes(signature); IMethod searchMethod = foundType.getMethod(methodName, methodParamTypes); IMethod[] methods = foundType.getMethods(); for (IMethod checkMethod : methods) { if (isSimilar(searchMethod, checkMethod)) { return checkMethod; } } return searchMethod; }