List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration getName
public SimpleName getName()
From source file:org.jboss.tools.seam.internal.core.scanner.java.ComponentBuilder.java
License:Open Source License
void processFactories() { for (AnnotatedASTNode<MethodDeclaration> n : annotatedMethods) { Annotation a = findAnnotation(n, FACTORY_ANNOTATION_TYPE); if (a == null) continue; MethodDeclaration m = n.getNode(); ValueInfo factoryName = ValueInfo.getValueInfo(a, null); if (factoryName == null) { factoryName = new ValueInfo(); factoryName.setValue(toPropertyName(m.getName().getIdentifier(), "get")); factoryName.valueLength = m.getName().getLength(); factoryName.valueStartPosition = m.getName().getStartPosition(); }//from w ww .j a v a 2 s . c om ValueInfo scope = ValueInfo.getValueInfo(a, ISeamXmlComponentDeclaration.SCOPE); ValueInfo autoCreate = ValueInfo.getValueInfo(a, "autoCreate"); //$NON-NLS-1$ SeamAnnotatedFactory factory = new SeamAnnotatedFactory(); factory.setParentDeclaration(component); IMethod im = findMethod(m); factory.setSourceMember(im); factory.setId(im); factory.setSourcePath(component.getSourcePath()); factory.setName(factoryName); if (autoCreate != null) factory.setAutoCreate(true); if (scope != null) { factory.setScope(scope); } ValueInfo _a = new ValueInfo(); _a.setValue(FACTORY_ANNOTATION_TYPE); _a.valueStartPosition = a.getStartPosition(); _a.valueLength = a.getLength(); factory.addAttribute(FACTORY_ANNOTATION_TYPE, _a); ds.getFactories().add(factory); } }
From source file:org.jboss.tools.seam.internal.core.scanner.java.ComponentBuilder.java
License:Open Source License
void processBijections() { Map<BijectedAttributeType, Annotation> as = new HashMap<BijectedAttributeType, Annotation>(); List<BijectedAttributeType> types = new ArrayList<BijectedAttributeType>(); for (AnnotatedASTNode<MethodDeclaration> n : annotatedMethods) { getBijectedType(n, as, types);//from w w w .j a va 2 s .co m if (as.isEmpty()) continue; boolean isDataModelSelectionType = !types.get(0).isUsingMemberName(); MethodDeclaration m = n.getNode(); BijectedAttribute att = createBijectedAttribute(types); Annotation in = as.get(BijectedAttributeType.IN); Annotation out = as.get(BijectedAttributeType.OUT); Annotation data = as.get(BijectedAttributeType.DATA_BINDER); addLocation(att, in, IN_ANNOTATION_TYPE); addLocation(att, out, OUT_ANNOTATION_TYPE); addLocation(att, data, DATA_MODEL_ANNOTATION_TYPE); ValueInfo name = findValueInfo(as, null); att.setValue(name); if (name == null || isDataModelSelectionType || name.getValue() == null || name.getValue().length() == 0) { name = new ValueInfo(); name.valueStartPosition = m.getStartPosition(); name.valueLength = m.getLength(); name.setValue(m.getName().getIdentifier()); if (in != null) { name.setValue(toPropertyName(name.getValue(), "set")); } else if (out != null || data != null) { name.setValue(toPropertyName(name.getValue(), "get")); } } att.setName(name); ValueInfo scope = findValueInfo(as, "scope"); //$NON-NLS-1$ if (scope != null) att.setScope(scope); IMethod im = findMethod(m); att.setSourceMember(im); att.setId(im); } for (AnnotatedASTNode<FieldDeclaration> n : annotatedFields) { getBijectedType(n, as, types); if (as.isEmpty()) continue; boolean isDataModelSelectionType = !types.get(0).isUsingMemberName(); FieldDeclaration m = n.getNode(); BijectedAttribute att = createBijectedAttribute(types); addLocation(att, as.get(BijectedAttributeType.IN), IN_ANNOTATION_TYPE); addLocation(att, as.get(BijectedAttributeType.OUT), OUT_ANNOTATION_TYPE); addLocation(att, as.get(BijectedAttributeType.DATA_BINDER), DATA_MODEL_ANNOTATION_TYPE); ValueInfo name = findValueInfo(as, null); att.setValue(name); if (name == null || isDataModelSelectionType || name.getValue() == null || name.getValue().length() == 0) { name = new ValueInfo(); name.valueStartPosition = m.getStartPosition(); name.valueLength = m.getLength(); name.setValue(getFieldName(m)); } att.setName(name); ValueInfo scope = findValueInfo(as, "scope"); //$NON-NLS-1$ if (scope != null) att.setScope(scope); IField f = findField(m); att.setSourceMember(f); att.setId(f); } }
From source file:org.jboss.tools.seam.internal.core.scanner.java.ComponentBuilder.java
License:Open Source License
private IMethod findMethod(MethodDeclaration m) { if (m == null || m.getName() == null) return null; IType type = (IType) component.getSourceMember(); IMethod[] ms = null;/* www . j a va 2s.c o m*/ try { ms = type.getMethods(); } catch (JavaModelException e) { SeamCorePlugin.getDefault().logError(e); } String name = m.getName().getIdentifier(); if (ms != null) for (int i = 0; i < ms.length; i++) { if (!name.equals(ms[i].getElementName())) continue; int s = m.getStartPosition() + m.getLength() / 2; try { ISourceRange range = ms[i].getSourceRange(); if (range == null) { //no source and we cannot check position. return ms[i]; } int b = range.getOffset(); int e = b + range.getLength(); if (s >= b && s <= e) return ms[i]; } catch (JavaModelException e) { return ms[i]; } } return null; }
From source file:org.jboss.tools.seam.ui.text.java.JavaStringHyperlinkDetector.java
License:Open Source License
public IMethod findMethod(IType type, MethodDeclaration m) { if (m == null || m.getName() == null) return null; IMethod[] ms = null;/*from ww w. ja v a 2s . com*/ try { ms = type.getMethods(); } catch (JavaModelException e) { SeamGuiPlugin.getDefault().logError(e); } String name = m.getName().getIdentifier(); if (ms != null) for (int i = 0; i < ms.length; i++) { if (!name.equals(ms[i].getElementName())) continue; int s = m.getStartPosition() + m.getLength() / 2; try { ISourceRange range = ms[i].getSourceRange(); if (range == null) { //no source and we cannot check position. return ms[i]; } int b = range.getOffset(); int e = b + range.getLength(); if (s >= b && s <= e) return ms[i]; } catch (JavaModelException e) { return ms[i]; } } return null; }
From source file:org.jboss.tools.ws.creation.core.commands.ClientSampleCreationCommand.java
License:Open Source License
/** * create a code block used to new a web service from a method of web * service client//w w w . j av a 2 s . c om * * @param serviceUnits * @param method * @param sb */ private void createWebService(List<ICompilationUnit> serviceUnits, MethodDeclaration method, StringBuffer sb) { sb.append(" System.out.println(\"" //$NON-NLS-1$ + "Create Web Service...\");"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); sb.append(" " + method.getReturnType2().toString()); //$NON-NLS-1$ sb.append(" port").append(portNum).append(" = "); //$NON-NLS-1$ //$NON-NLS-2$ sb.append("service").append(serviceNum).append("."); //$NON-NLS-1$ //$NON-NLS-2$ sb.append(method.getName()).append("();"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); for (ICompilationUnit unit : serviceUnits) { // parse the unit ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(unit); parser.setResolveBindings(false); parser.setFocalPosition(0); CompilationUnit result = (CompilationUnit) parser.createAST(null); @SuppressWarnings("rawtypes") List types = result.types(); TypeDeclaration typeDec1 = (TypeDeclaration) types.get(0); if (typeDec1.getName().toString().equals(method.getReturnType2().toString())) { callWebServiceOperation(typeDec1, sb); } } }
From source file:org.jboss.tools.ws.creation.core.commands.ClientSampleCreationCommand.java
License:Open Source License
/** * create a code block to call web service operation * //from w w w . j a v a 2s. c o m * @param typeDec * @param sb */ private void callWebServiceOperation(TypeDeclaration typeDec, StringBuffer sb) { sb.append(" System.out.println(\"" //$NON-NLS-1$ + "Call Web Service Operation...\");"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); MethodDeclaration methodDec[] = typeDec.getMethods(); // call web serivce Operation for (MethodDeclaration method : methodDec) { if (method.getReturnType2().toString().equals("void")) { //$NON-NLS-1$ sb.append(" System.out.println(\"Server said: "); //$NON-NLS-1$ sb.append("port").append(portNum).append("."); //$NON-NLS-1$//$NON-NLS-2$ sb.append(method.getName()).append("() is a void method!\");"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); } else { sb.append(" System.out.println(\"Server said: \" + "); //$NON-NLS-1$ sb.append("port").append(portNum).append("."); //$NON-NLS-1$ //$NON-NLS-2$ sb.append(method.getName()).append("("); //$NON-NLS-1$ boolean noNull = true; for (int j = 0; j < method.parameters().size(); j++) { noNull = createWebServiceOperationParameters(method.parameters(), sb, j) && noNull; } sb.append("));"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); if (!noNull) { sb.append(" //Please input the parameters instead of 'null' for the upper method!"); //$NON-NLS-1$ sb.append(LINE_SEPARATOR); sb.append(LINE_SEPARATOR); } } } }
From source file:org.jboss.tools.ws.creation.core.commands.ImplementationClassCreationCommand.java
License:Open Source License
@SuppressWarnings("unchecked") protected MethodDeclaration createMethodForImplClass(AST ast, MethodDeclaration inMethod) { MethodDeclaration md = ast.newMethodDeclaration(); md.setConstructor(false);//from ww w .ja va2s . c om @SuppressWarnings("rawtypes") List modifiers = md.modifiers(); modifiers.add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); md.setName(ast.newSimpleName(inMethod.getName().getFullyQualifiedName())); Type sType = copyTypeFromOtherASTNode(ast, inMethod.getReturnType2()); md.setReturnType2(sType); @SuppressWarnings("rawtypes") List thrownExceptions = inMethod.thrownExceptions(); for (Object obj : thrownExceptions) { if (obj instanceof SimpleName) { SimpleName sname = (SimpleName) obj; Name newName = ast.newName(sname.getFullyQualifiedName()); md.thrownExceptions().add(newName); } } @SuppressWarnings("rawtypes") List parameters = inMethod.parameters(); for (Object obj : parameters) { SingleVariableDeclaration implSvd = ast.newSingleVariableDeclaration(); SingleVariableDeclaration svd = (SingleVariableDeclaration) obj; implSvd.setName(ast.newSimpleName(svd.getName().getFullyQualifiedName())); implSvd.setType(copyTypeFromOtherASTNode(ast, svd.getType())); md.parameters().add(implSvd); } // create method body Block block = ast.newBlock(); // add log info statement // block.statements().add(createLoggerInvokeStatement(ast, // md.getName().getFullyQualifiedName())); Type returnType = inMethod.getReturnType2(); ReturnStatement rs = ast.newReturnStatement(); if (returnType.isPrimitiveType()) { if (((PrimitiveType) returnType).getPrimitiveTypeCode().equals(PrimitiveType.BOOLEAN)) { BooleanLiteral bl = ast.newBooleanLiteral(false); rs.setExpression(bl); } else if (!((PrimitiveType) returnType).getPrimitiveTypeCode().equals(PrimitiveType.VOID)) { NumberLiteral nl = ast.newNumberLiteral(); nl.setToken("0"); //$NON-NLS-1$ rs.setExpression(nl); } } else if (returnType.isSimpleType()) { String typeName = ((SimpleType) returnType).getName().getFullyQualifiedName(); if ("String".equals(typeName)) { //$NON-NLS-1$ StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(""); //$NON-NLS-1$ rs.setExpression(sl); } else { rs.setExpression(ast.newNullLiteral()); } } else { rs.setExpression(ast.newNullLiteral()); } block.statements().add(rs); md.setBody(block); return md; }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.JavaAnnotationsVisitor.java
License:Open Source License
/** * {@inheritDoc}// w ww . j a v a 2 s .c o m * * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. MethodDeclaration) */ @Override public final boolean visit(final MethodDeclaration node) { if (memberType == IJavaElement.METHOD && node.getName().getFullyQualifiedName().equals(memberName) && matchesLocation(node)) { visitExtendedModifiers((List<?>) node.getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY)); return false; } return true; }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java
License:Open Source License
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation) *//*from w w w. j a v a 2s. co m*/ @Override public boolean visit(MethodDeclaration node) { final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.METHOD); if (ancestor != null && ancestor.exists() && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) { // keep searching return true; } // wrong path, stop searching from this branch of the AST return false; }
From source file:org.juniversal.translator.core.ASTUtil.java
License:Open Source License
public static boolean isThisMethod(MethodDeclaration methodDeclaration, String methodName, String... parameterTypes) { // If the method names don't match, it's not the specified method if (!methodDeclaration.getName().getIdentifier().equals(methodName)) return false; // If the method parameter counts don't match, it's not the specified method if (methodDeclaration.parameters().size() != parameterTypes.length) return false; // Ensure each parameter has the expected type int index = 0; for (Object parameterObject : methodDeclaration.parameters()) { SingleVariableDeclaration parameter = (SingleVariableDeclaration) parameterObject; if (!isType(parameter.getType(), parameterTypes[index])) return false; ++index;/*from w w w. j a va2 s. c o m*/ } return true; }