List of usage examples for org.eclipse.jdt.core IField getAnnotation
IAnnotation getAnnotation(String name);
From source file:cn.ieclipse.adt.ext.jdt.SourceAnalysis.java
License:Apache License
public static String getSQL(TypeMapping typeMapping, boolean format) { StringBuilder sb = new StringBuilder(); sb.append("create TABLE "); sb.append(typeMapping.getTable());/*from w w w. j ava 2 s . co m*/ sb.append(" ( "); if (format) { sb.append(LF); } try { IField[] fds = typeMapping.getType().getFields(); for (IField iField : fds) { String fieldType = iField.getTypeSignature(); IAnnotation nc = iField.getAnnotation("Column"); if (nc != null && nc.exists()) { ColumnMeta meta = new ColumnMeta(); meta.type = getColumnBySig(fieldType); IMemberValuePair[] mvps = nc.getMemberValuePairs(); for (IMemberValuePair imvp : mvps) { String mn = imvp.getMemberName(); Object mv = imvp.getValue(); if ("name".equals(mn)) { meta.name = (String) mv; } else if ("id".equals(mn)) { meta.id = (Boolean) mv; meta.haveId = true; } else if ("notNull".equals(mn)) { meta.notNull = (Boolean) mv; meta.haveNotNull = true; } else if ("defaultValue".equals(mn)) { meta.defaultValue = (String) mv; meta.haveDefaultValue = true; } } sb.append(meta.toSQL()); sb.append(", "); if (format) { sb.append(LF); } } // end if } // end for int len = sb.length() - 2; if (format) { len = len - LF.length(); } sb.delete(len, sb.length()); sb.append(")"); sb.append(LF); } catch (Exception e) { e.printStackTrace(); return ""; } return sb.toString(); }
From source file:com.gwtplatform.plugin.wizard.NewPresenterWizardPage.java
License:Apache License
protected IStatus revealInParentChanged() { StatusInfo status = new StatusInfo(); if (isRevealContentEvent.isEnabled() && isRevealContentEvent.getSelection()) { if (contentSlot.getText().isEmpty()) { status.setError("You must enter the parent's content slot when selecting RevealContentEvent"); return status; }/* w w w . j a v a 2s . c om*/ String slotParent = ""; String slotName = ""; if (!contentSlot.getText().contains("#")) { slotParent = contentSlot.getText(); } else { String[] split = contentSlot.getText().split("#"); slotParent = split[0]; if (split.length > 1) { slotName = split[1]; } } try { IType type = getJavaProject().findType(slotParent); if (type == null || !type.exists()) { status.setError(slotParent + " doesn't exist"); return status; } ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor()); IType[] interfaces = hierarchy.getAllInterfaces(); boolean hasSlots = false; for (IType inter : interfaces) { if (inter.getFullyQualifiedName('.').equals("com.gwtplatform.mvp.client.HasSlots")) { hasSlots = true; break; } } if (!hasSlots) { status.setError(slotParent + " doesn't implement HasSlots"); return status; } if (slotName.isEmpty()) { status.setError("You must enter the slot's name (fully.qualified.ParentPresenter#SlotName)"); return status; } IField field = type.getField(slotName); if (!field.exists()) { status.setError(slotName + " doesn't exist"); return status; } if (!field.getAnnotation("ContentSlot").exists()) { status.setError(slotName + " isn't a ContentSlot"); return status; } } catch (JavaModelException e) { status.setError("An unexpected error has happened. Close the wizard and retry."); return status; } } return status; }
From source file:org.jboss.tools.common.model.test.AnnotationTest.java
License:Open Source License
IAnnotation findAnnotation(String fieldName, String annotationTypeName) { IField field = type.getField(fieldName); assertTrue(field.exists());/*from w ww . jav a 2 s. c o m*/ IAnnotation annotation = field.getAnnotation(annotationTypeName); assertTrue(annotation.exists()); return annotation; }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementDeltaScannerTestCase.java
License:Open Source License
@Test public void shouldNotifyWhenFieldAnnotationChangedInWorkingCopy() throws CoreException, InterruptedException { // pre-condition IType type = metamodelMonitor.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource"); IField field = type.getField("entityManager"); // operation//from w ww. j a v a2s. c o m field = replaceFirstOccurrenceOfCode(field, "@PersistenceContext", "@PersistenceContext(value=\"foo\")", WORKING_COPY); // verifications IAnnotation annotation = field.getAnnotation("PersistenceContext"); verifyEventNotification(annotation, CHANGED, POST_RECONCILE, F_CONTENT, times(1)); }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementDeltaScannerTestCase.java
License:Open Source License
@Test public void shouldNotifyWhenFieldAnnotationChangedInPrimaryCopy() throws CoreException, InterruptedException { // pre-condition IType type = metamodelMonitor.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource"); IField field = type.getField("entityManager"); // operation/* w ww . j a v a 2 s . co m*/ field = replaceFirstOccurrenceOfCode(field, "@PersistenceContext", "@PersistenceContext(value=\"foo\")", PRIMARY_COPY); // verifications IAnnotation annotation = field.getAnnotation("PersistenceContext"); verifyEventNotification(annotation.getResource(), CHANGED, POST_CHANGE, new Flags(CONTENT), atLeastOnce()); }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementDeltaScannerTestCase.java
License:Open Source License
@Test public void shouldNotifyWhenFieldAnnotationRemovedInWorkingCopy() throws CoreException, InterruptedException { // pre-condition IType type = metamodelMonitor.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource"); IField field = type.getField("entityManager"); IAnnotation annotation = field.getAnnotation("PersistenceContext"); // operation/*ww w .ja v a 2s .c o m*/ removeFieldAnnotation(field, "@PersistenceContext", WORKING_COPY); // verifications verifyEventNotification(annotation, REMOVED, POST_RECONCILE, Flags.NONE, times(1)); }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementDeltaScannerTestCase.java
License:Open Source License
@Test public void shouldNotifyWhenFieldAnnotationRemovedInPrimaryCopy() throws CoreException, InterruptedException { // pre-condition IType type = metamodelMonitor.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource"); IField field = type.getField("entityManager"); IAnnotation annotation = field.getAnnotation("PersistenceContext"); // operation/*from w w w .ja v a2 s. co m*/ removeFieldAnnotation(field, "@PersistenceContext", PRIMARY_COPY); // verifications verifyEventNotification(annotation.getResource(), CHANGED, POST_CHANGE, new Flags(CONTENT), atLeastOnce()); }
From source file:org.springframework.ide.eclipse.quickfix.hyperlinks.AutowireHyperlinkDetector.java
License:Open Source License
@Override protected void addHyperlinks(List<IHyperlink> hyperlinksCollector, final IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) { if (element instanceof ILocalVariable) { ILocalVariable localVariable = (ILocalVariable) element; IJavaElement parent = localVariable.getParent(); if (parent instanceof IMethod) { IMethod parentMethod = (IMethod) parent; if (parentMethod.getAnnotation("Autowired") != null) { String typeSignature = localVariable.getTypeSignature(); addHyperlinksHelper(typeSignature, localVariable, hyperlinksCollector); }//w ww. ja va 2 s. c o m } } else if (element instanceof IField) { IField field = (IField) element; if (field.getAnnotation("Autowired") != null) { try { String typeSignature = field.getTypeSignature(); addHyperlinksHelper(typeSignature, field, hyperlinksCollector); } catch (JavaModelException e) { StatusHandler.log(e.getStatus()); } } } }