List of usage examples for org.aspectj.asm IProgramElement getParameterNames
public List<String> getParameterNames();
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
private void createParameters(Class classifier, Operation operationObject, IProgramElement child) { // protected void createParameters(Element element, Operation operation, IMethod method) throws JavaModelException // {/* ww w . j a va 2 s. com*/ List<?> paramNameList = child.getParameterNames(); //If there weren't any parm names, don't create any parms if (paramNameList == null) { return; } Object[] paramNames = paramNameList.toArray(); Object[] paramTypeSigs = child.getParameterTypes().toArray(); /* * child.getParameterNames is List<String>, but child.getParameterNames is * actually List<char[]> or something equally bizarre. Which is why the * typeSigObj-to-typeSig conversion is so weird. */ for (int i = 0; i < paramNames.length; i++) { Object nameObj = paramNames[i]; Object typeSigObj = paramTypeSigs[i]; if (nameObj instanceof String) { String name = (String) nameObj; char[] typeSigArr = (char[]) typeSigObj; String typeName = String.valueOf(typeSigArr); // String typeSig = String.valueOf(typeSigArr); // Parameter parameter = UMLFactory.eINSTANCE.createParameter(); parameter.setName(name); // // String typeWithoutArray = Signature.getElementType(typeSig); // String typeName = Signature.toString(Signature.getTypeErasure(typeWithoutArray)); Type paramType = findTemplateParameter(classifier, typeName); if (paramType == null) { paramType = findOrCreateType(classifier.getNearestPackage(), typeName); } if (paramType != null) { parameter.setType(paramType); } operationObject.getOwnedParameters().add(parameter); } // processAnnotations(classifier.getNearestPackage(), child, parameter); } }
From source file:edu.utdallas.fdaf.aspectj.reverse.AspectJ2UMLConverter.java
License:Open Source License
private Operation findOperation(StructuredClassifier classifier, IProgramElement child) { // protected Operation findOperation(Classifier classifier, IMethod method) // {//from w w w. j a v a 2 s .c o m for (Operation op : classifier.getOperations()) { if (op.getOwner().equals(classifier) && op.getName().equals(child.getName())) { // try // { List lParamNames = child.getParameterNames(); // if ((lParamNames == null) || (lParamNames.size() == 1)) // { // if (op.getOwnedParameters().size() == 1) // { // return op; // } // } if (lParamNames == null) { if (op.getOwnedParameters().size() == 0) { return op; } } else if (lParamNames.size() == 1) { if (op.getOwnedParameters().size() == 1) { return op; } } else { Object[] aParamNames = lParamNames.toArray(); int i = 0; int paramCount = 0; for (Parameter param : op.getOwnedParameters()) { if (!param.getName().equals("return")) { if (i < aParamNames.length && param.getName().equals(aParamNames[i].toString())) { paramCount++; } i++; } } if (paramCount == aParamNames.length) { return op; } } // } // catch (JavaModelException e) // { // e.printStackTrace(); // } } } return null; }
From source file:org.eclipse.ajdt.core.codeconversion.AspectsConvertingParser.java
License:Open Source License
/** * @param sb//from w ww . ja v a 2 s . c om * @param declareElt */ protected void createITITText(StringBuffer sb, IProgramElement declareElt) { sb.append("\n\tstatic class ").append(declareElt.getName()).append(" {\n"); List<IProgramElement> children = declareElt.getChildren(); for (IProgramElement child : children) { sb.append("\t\tpublic static "); sb.append(child.getCorrespondingType(true) + " "); sb.append(child.getName()); if (child.getKind() == IProgramElement.Kind.FIELD) { sb.append(";\n"); } else { sb.append("("); List<String> names = child.getParameterNames(); List<char[]> types = child.getParameterTypes(); if (types != null && names != null) { for (Iterator<?> typeIter = types.iterator(), nameIter = names.iterator(); typeIter .hasNext();) { String paramType = String.valueOf((char[]) typeIter.next()); String paramName = (String) nameIter.next(); sb.append(paramType + " " + paramName); if (typeIter.hasNext()) { sb.append(", "); } } } sb.append(") { }\n"); } } sb.append("\t}\n"); }
From source file:org.eclipse.ajdt.core.codeconversion.AspectsConvertingParser.java
License:Open Source License
/** * @param currentTypeName// w ww. j ava 2 s.c o m * @param sb * @param declareElt * @param name */ protected void createITDMethodText(char[] currentTypeName, StringBuffer sb, IProgramElement declareElt, String name) { sb.append(getAccessibilityString(declareElt)); for (IProgramElement.Modifiers modifier : declareElt.getModifiers()) { sb.append(modifier + " "); } // need to add a return statement? if (declareElt.getKind() == IProgramElement.Kind.INTER_TYPE_METHOD) { sb.append(declareElt.getCorrespondingType(true) + " " + name); } else { sb.append(currentTypeName); } sb.append("("); List<String> names = declareElt.getParameterNames(); List<char[]> types = declareElt.getParameterTypes(); if (types != null && names != null) { for (Iterator<?> typeIter = types.iterator(), nameIter = names.iterator(); typeIter.hasNext();) { String paramType = String.valueOf((char[]) typeIter.next()); String paramName = (String) nameIter.next(); sb.append(paramType + " " + paramName); if (typeIter.hasNext()) { sb.append(", "); } } } sb.append(") { }\n"); }
From source file:org.eclipse.ajdt.core.javaelements.IntertypeElement.java
License:Open Source License
protected Object createElementInfo() { IntertypeElementInfo info = new IntertypeElementInfo(); IProject project = this.getJavaProject().getProject(); IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForProject(project) .javaElementToProgramElement(this); if (ipe != IHierarchy.NO_STRUCTURE) { // this way of creating the element info does not contain proper source locations for the name and target type info.setAJExtraInfo(ipe.getExtraInfo()); info.setName(name.toCharArray()); info.setAJKind(ipe.getKind());/*from w w w . ja va 2 s. c o m*/ info.setAJModifiers(ipe.getModifiers()); info.setFlags(ipe.getRawModifiers()); info.setDeclaredModifiers(info.getModifiers()); info.setAJAccessibility(ipe.getAccessibility()); ISourceLocation sourceLocation = ipe.getSourceLocation(); info.setSourceRangeStart(sourceLocation.getOffset()); info.setNameSourceStart(sourceLocation.getOffset()); // This is wrong info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); // also wrong info.setConstructor(info.getAJKind() == IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); char[][] argumentNames = CoreUtils.listStringsToCharArrays(ipe.getParameterNames()); char[][] argumentTypeNames = CoreUtils.listCharsToCharArrays(ipe.getParameterTypes()); if (argumentNames.length == 0 && argumentTypeNames.length > 0) { // argument names not found. likely coming from binary class file w/p source attachment // generate argument names argumentNames = new char[argumentTypeNames.length][]; for (int i = 0; i < argumentNames.length; i++) { argumentNames[i] = ("arg" + i).toCharArray(); } } info.setArgumentNames(argumentNames); info.setArgumentTypeNames(argumentTypeNames); info.setReturnType(ipe.getCorrespondingType(false).toCharArray()); info.setQualifiedReturnType(ipe.getCorrespondingType(true).toCharArray()); info.setTypeParameters(createTypeParameters(project)); if (argumentNames != null && argumentNames.length > 0) { ILocalVariable[] arguments = new ILocalVariable[argumentNames.length]; for (int i = 0; i < argumentNames.length; i++) { arguments[i] = new LocalVariable(this, String.valueOf(argumentNames[i]), // sloc is not correct, but it is close enough sourceLocation.getOffset(), sourceLocation.getOffset() + 1, sourceLocation.getOffset(), sourceLocation.getOffset() + 1, String.valueOf(argumentTypeNames[i]), new Annotation[0], Flags.AccDefault, true); } info.setArguments(arguments); } } else { // no successful build yet, we don't know the contents info.setName(name.toCharArray()); info.setAJKind(IProgramElement.Kind.ERROR); info.setAJModifiers(Collections.<Modifiers>emptyList()); } return info; }
From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java
License:Open Source License
private MethodDeclaration createMethod(IProgramElement method, TypeDeclaration type, IType handle) { MethodDeclaration decl = new MethodDeclaration(type.compilationResult); decl.scope = new MethodScope(type.scope, decl, true); String[] split = method.getName().split("\\."); decl.selector = split[split.length - 1].toCharArray(); decl.modifiers = method.getRawModifiers(); decl.returnType = createTypeReference(method.getCorrespondingType(true)); decl.modifiers = method.getRawModifiers(); Argument[] args = method.getParameterTypes() != null ? new Argument[method.getParameterTypes().size()] : new Argument[0]; try {/*from w w w .jav a 2 s . co m*/ ErasedTypeSignature sig = null; if (handle != null) { AJWorldFacade world = new AJWorldFacade(handle.getJavaProject().getProject()); sig = world.getMethodTypeSignatures( Signature.createTypeSignature(handle.getFullyQualifiedName(), true), method); } if (sig == null) { String[] params = new String[method.getParameterTypes().size()]; for (int i = 0; i < params.length; i++) { params[i] = new String(Signature.getTypeErasure((char[]) method.getParameterTypes().get(i))); } sig = new ErasedTypeSignature(method.getCorrespondingTypeSignature(), params); } List<String> pNames = method.getParameterNames(); // bug 270123... no parameter names if coming in from a jar and // not build with debug info...mock it up. if (pNames == null || pNames.size() != args.length) { pNames = new ArrayList<String>(args.length); for (int i = 0; i < args.length; i++) { pNames.add("args" + i); } } for (int i = 0; i < args.length; i++) { args[i] = new Argument(((String) pNames.get(i)).toCharArray(), 0, createTypeReference(Signature.getElementType(sig.paramTypes[i])), 0); } decl.returnType = createTypeReferenceFromSignature(sig.returnTypeSig); decl.typeParameters = createTypeParameters(sig.typeParameters); } catch (Exception e) { AJLog.log("Exception occurred in ITDInserter.createMethod(). (Ignoring)"); AJLog.log("Relevant method: " + method.getParent().getName() + "." + method.getName()); List<String> pNames = method.getParameterNames(); // bug 270123... no parameter names if coming in from a jar and // not build with debug info...mock it up. if (pNames == null || pNames.size() != args.length) { pNames = new ArrayList<String>(args.length); for (int i = 0; i < args.length; i++) { pNames.add("args" + i); } } for (int i = 0; i < args.length; i++) { args[i] = new Argument(((String) pNames.get(i)).toCharArray(), 0, createTypeReference(new String((char[]) method.getParameterTypes().get(i))), 0); } } decl.arguments = args; return decl; }
From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java
License:Open Source License
private ConstructorDeclaration createConstructor(IProgramElement constructor, TypeDeclaration type) { ConstructorDeclaration decl = new ConstructorDeclaration(type.compilationResult); decl.scope = new MethodScope(type.scope, decl, true); decl.selector = constructor.getName().split("\\.")[1].toCharArray(); decl.modifiers = constructor.getRawModifiers(); Argument[] args = constructor.getParameterTypes() != null ? new Argument[constructor.getParameterTypes().size()] : new Argument[0]; List<String> pNames = constructor.getParameterNames(); // bug 270123, bug 334328... no parameter names if coming in from a jar and // not build with debug info...mock it up. if (pNames == null || pNames.size() != args.length) { pNames = new ArrayList<String>(args.length); for (int i = 0; i < args.length; i++) { pNames.add("args" + i); }//from w ww . j a v a2s .c om } for (int i = 0; i < args.length; i++) { args[i] = new Argument(pNames.get(i).toCharArray(), 0, createTypeReference(new String((char[]) constructor.getParameterTypes().get(i))), 0); } decl.arguments = args; return decl; }