List of usage examples for org.eclipse.jdt.core IAnnotation getElementName
@Override String getElementName();
From source file:at.bestsolution.efxclipse.tooling.fxml.compile.FxmlAnnotationCompilationParticipant.java
License:Open Source License
/** * @param context/* ww w . j av a2 s. com*/ */ private List<CategorizedProblem> checkCU(final ICompilationUnit unit, final Collection<CategorizedProblem> existingProblems) { List<CategorizedProblem> problems = new ArrayList<CategorizedProblem>(); if (existingProblems != null) { problems.addAll(existingProblems); } List<String> fxmlMethods = new ArrayList<String>(); try { IJavaProject project = unit.getJavaProject(); for (IType type : unit.getTypes()) { for (IMethod method : type.getMethods()) { for (IAnnotation a : method.getAnnotations()) { if ("FXML".equals(a.getElementName())) { ////$NON-NLS-1$ if (fxmlMethods.contains(method.getElementName())) { DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "JavaFX controller method name is not unique: " //$NON-NLS-1$ + method.getElementName(), IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, method.getSourceRange().getOffset(), method.getSourceRange().getOffset() + method.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } fxmlMethods.add(method.getElementName()); switch (method.getNumberOfParameters()) { case 0: break; case 1: { ILocalVariable pType = method.getParameters()[0]; String[][] resolvedType = type .resolveType(Signature.toString(pType.getTypeSignature())); IType parameterType = null; if (resolvedType != null) { parameterType = project.findType(resolvedType[0][0] + "." + resolvedType[0][1]); //$NON-NLS-1$ } if (resolvedType == null || !Util.assignable(parameterType, project.findType("javafx.event.Event"))) { ////$NON-NLS-1$ DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "Parameter '" //$NON-NLS-1$ + pType.getElementName() + "' is not assignable to javafx.event.Event", //$NON-NLS-1$ IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, pType.getSourceRange().getOffset(), pType.getSourceRange().getOffset() + pType.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } } break; default: { DefaultProblem problem = new DefaultProblem(unit.getElementName().toCharArray(), "JavaFX controller method must have 0 or exactly 1 argument", //$NON-NLS-1$ IProblem.ExternalProblemNotFixable, new String[0], ProblemSeverities.Warning, method.getSourceRange().getOffset(), method.getSourceRange().getOffset() + method.getSourceRange().getLength(), getMethodLineNumber(type, method), 0); problems.add(problem); } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return problems; }
From source file:at.bestsolution.efxclipse.tooling.fxml.refactoring.RenameJFXControllerParticipant.java
License:Open Source License
/** * @param an/*from w w w .jav a 2 s. co m*/ * an annotation */ private boolean isFxmlAnnotation(IAnnotation a) { if ("FXML".equals(a.getElementName())) { return true; } else { return false; } }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXCtrlClass.java
License:Open Source License
private Map<String, IFXCtrlEventMethod> getLocalEventMethods() { if (eventMethods == null) { eventMethods = new HashMap<String, IFXCtrlEventMethod>(); try {//from w w w.j a va 2 s . com for (IMethod m : type.getMethods()) { boolean annotated = false; for (IAnnotation a : m.getAnnotations()) { if (a.getElementName().endsWith("FXML")) { annotated = true; break; } } if (annotated) { String[] types = m.getParameterTypes(); if (types.length <= 1) { if (types.length == 1) { String erasedFQNType = Util.getFQNType((IType) m.getParent(), Signature.getTypeErasure(Signature.toString(types[0]))); if (FXCtrlEventMethod.isEventMethod(javaProject, erasedFQNType)) { eventMethods.put(m.getElementName(), new FXCtrlEventMethod(this, m, erasedFQNType)); } } else { // Only if there's not already a method with the same id if (!eventMethods.containsKey(m.getElementName())) { eventMethods.put(m.getElementName(), new FXCtrlEventMethod(this, m, null)); } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return eventMethods; }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXCtrlClass.java
License:Open Source License
private Map<String, IFXCtrlField> getLocalFields() { if (fields == null) { fields = new HashMap<String, IFXCtrlField>(); try {// w ww. j a va 2 s. com for (IField f : type.getFields()) { boolean annotated = false; for (IAnnotation a : f.getAnnotations()) { if (a.getElementName().endsWith("FXML")) { annotated = true; break; } } if (annotated) { String erasedFQNType = Util.getFQNType((IType) f.getParent(), Signature.getTypeErasure(Signature.toString(f.getTypeSignature()))); FXCtrlField field = new FXCtrlField(this, f, erasedFQNType); fields.put(f.getElementName(), field); } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return fields; }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException { fBuffer.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);/* w w w .j av a 2s. c o m*/ IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) return; fBuffer.append('('); for (int i = 0; i < memberValuePairs.length; i++) { if (i > 0) fBuffer.append(JavaElementLabels.COMMA_STRING); IMemberValuePair memberValuePair = memberValuePairs[i]; fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); fBuffer.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags); } fBuffer.append(')'); }
From source file:com.aqua.wikiwizard.ObjectsJavaModel.java
License:Apache License
/** * Check if annotation is found/* ww w . ja v a 2s. c om*/ */ private boolean isAnnotationFound(IAnnotatable type, String annotationName) { IAnnotation annotations[]; try { annotations = type.getAnnotations(); for (IAnnotation annotation : annotations) { if (annotation.getElementName().equals(annotationName)) { return true; } } } catch (JavaModelException e) { } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.LocalVariable.java
License:Open Source License
public IAnnotation getAnnotation(String annotationName) { for (int i = 0, length = this.annotations.length; i < length; i++) { IAnnotation annotation = this.annotations[i]; if (annotation.getElementName().equals(annotationName)) return annotation; }//from www .java2s . c o m return super.getAnnotation(annotationName); }
From source file:com.codenvy.ide.ext.java.server.SourcesFromBytecodeGenerator.java
License:Open Source License
public void appendAnnotationLabel(IAnnotation annotation, long flags, StringBuilder builder) throws JavaModelException { builder.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags, builder);//from w w w. j a v a 2 s . co m IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) return; builder.append('('); for (int i = 0; i < memberValuePairs.length; i++) { if (i > 0) builder.append(JavaElementLabels.COMMA_STRING); IMemberValuePair memberValuePair = memberValuePairs[i]; builder.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); builder.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags, builder); } builder.append(')'); }
From source file:com.curlap.orb.plugin.generator.CurlClassGeneratorFactory.java
License:Open Source License
public CurlClassGenerator createGenerator(ICompilationUnit iCompilationUnit) throws CurlGenerateException { ICompilationUnit source = iCompilationUnit; try {/* www . ja v a 2s .com*/ for (IType iType : source.getAllTypes()) { for (IAnnotation annotation : iType.getAnnotations()) { String name = annotation.getElementName(); if (name.equals("AutoGenerateCurlServiceClient")) { String savePath = getSavePath(annotation); for (IMemberValuePair pair : annotation.getMemberValuePairs()) { if (pair.getMemberName().equals("serviceType")) if (((String) pair.getValue()).equals("HttpSession")) return new CurlHttpSessionServiceClassGeneratorImpl(source, savePath); } return new CurlDIServiceClassGeneratorImpl(source, savePath); } else if (name.equals("AutoGenerateCurlDto")) { String savePath = getSavePath(annotation); return new CurlDataClassGeneratorImpl(source, savePath); } else if (name.equals("AutoGenerateCurlException")) { String savePath = getSavePath(annotation); return new CurlExceptionGeneratorImpl(source, savePath); } } } } catch (JavaModelException e) { throw new CurlGenerateException(e); } //throw new CurlGenerateException("Cannot create generator."); return null; }
From source file:com.curlap.orb.plugin.generator.impl.CurlDIServiceClassGeneratorImpl.java
License:Open Source License
@Override public VelocityContext generateClass() throws CurlGenerateException { ICompilationUnit source = iCompilationUnit; VelocityContext context = super.generateClass(); String beanId = null;// w w w. j av a 2s .c o m try { for (IType iType : source.getAllTypes()) { // annotation for (IAnnotation iAnnotation : iType.getAnnotations()) { if (iAnnotation.getElementName().equals("AutoGenerateCurlServiceClient")) { for (IMemberValuePair pair : iAnnotation.getMemberValuePairs()) { String memberName = pair.getMemberName(); if (memberName.equals("serviceBeanId")) beanId = (String) pair.getValue(); } } // "@Service" is a Spring framework annotation. // See org.springframework.stereotype.Service if (iAnnotation.getElementName().equals("Service")) { for (IMemberValuePair pair : iAnnotation.getMemberValuePairs()) { String memberName = pair.getMemberName(); if (memberName.equals("value")) beanId = (String) pair.getValue(); } } } if (beanId == null || beanId.length() == 0) throw new CurlGenerateException( "DI serivce needs 'bean id'. See 'serviceBeanId' of @AutoGenerateCurlServiceClient annotation."); } context.put("server_component", beanId); context.put("superclass", "ApplicationContextClient"); return context; } catch (JavaModelException e) { throw new CurlGenerateException(e); } }