List of usage examples for org.eclipse.jdt.internal.compiler.ast ArrayQualifiedTypeReference ArrayQualifiedTypeReference
public ArrayQualifiedTypeReference(char[][] sources, int dim, long[] poss)
From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java
License:Open Source License
@Override public ASTNode visitTypeRef(final lombok.ast.TypeRef node, final Void p) { final TypeReference[] paramTypes = build(node.getTypeArgs()).toArray(new TypeReference[0]); final TypeReference typeReference; if (node.getTypeName().equals("void")) { typeReference = new SingleTypeReference(TypeBinding.VOID.simpleName, 0); } else if (node.getTypeName().contains(".")) { final char[][] typeNameTokens = fromQualifiedName(node.getTypeName()); long[] poss = new long[typeNameTokens.length]; Arrays.fill(poss, 0);//from w w w. j ava 2 s . com if (Is.notEmpty(paramTypes)) { final TypeReference[][] typeArguments = new TypeReference[typeNameTokens.length][]; typeArguments[typeNameTokens.length - 1] = paramTypes; typeReference = new ParameterizedQualifiedTypeReference(typeNameTokens, typeArguments, 0, poss); } else { if (node.getDims() > 0) { typeReference = new ArrayQualifiedTypeReference(typeNameTokens, node.getDims(), poss); } else { typeReference = new QualifiedTypeReference(typeNameTokens, poss); } } } else { final char[] typeNameToken = node.getTypeName().toCharArray(); if (Is.notEmpty(paramTypes)) { typeReference = new ParameterizedSingleTypeReference(typeNameToken, paramTypes, 0, 0); } else { if (node.getDims() > 0) { typeReference = new ArrayTypeReference(typeNameToken, node.getDims(), 0); } else { typeReference = new SingleTypeReference(typeNameToken, 0); } } } setGeneratedByAndCopyPos(typeReference, source, posHintOf(node)); if (node.isSuperType()) typeReference.bits |= IsSuperType; return typeReference; }
From source file:lombok.eclipse.handlers.EclipseHandlerUtil.java
License:Open Source License
/** * You can't share TypeReference objects or subtle errors start happening. * Unfortunately the TypeReference type hierarchy is complicated and there's no clone * method on TypeReference itself. This method can clone them. */// ww w . j a va2 s . c om public static TypeReference copyType(TypeReference ref, ASTNode source) { if (ref instanceof ParameterizedQualifiedTypeReference) { ParameterizedQualifiedTypeReference iRef = (ParameterizedQualifiedTypeReference) ref; TypeReference[][] args = null; if (iRef.typeArguments != null) { args = new TypeReference[iRef.typeArguments.length][]; int idx = 0; for (TypeReference[] inRefArray : iRef.typeArguments) { if (inRefArray == null) args[idx++] = null; else { TypeReference[] outRefArray = new TypeReference[inRefArray.length]; int idx2 = 0; for (TypeReference inRef : inRefArray) { outRefArray[idx2++] = copyType(inRef, source); } args[idx++] = outRefArray; } } } TypeReference typeRef = new ParameterizedQualifiedTypeReference(iRef.tokens, args, iRef.dimensions(), copy(iRef.sourcePositions)); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof ArrayQualifiedTypeReference) { ArrayQualifiedTypeReference iRef = (ArrayQualifiedTypeReference) ref; TypeReference typeRef = new ArrayQualifiedTypeReference(iRef.tokens, iRef.dimensions(), copy(iRef.sourcePositions)); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof QualifiedTypeReference) { QualifiedTypeReference iRef = (QualifiedTypeReference) ref; TypeReference typeRef = new QualifiedTypeReference(iRef.tokens, copy(iRef.sourcePositions)); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof ParameterizedSingleTypeReference) { ParameterizedSingleTypeReference iRef = (ParameterizedSingleTypeReference) ref; TypeReference[] args = null; if (iRef.typeArguments != null) { args = new TypeReference[iRef.typeArguments.length]; int idx = 0; for (TypeReference inRef : iRef.typeArguments) { if (inRef == null) args[idx++] = null; else args[idx++] = copyType(inRef, source); } } TypeReference typeRef = new ParameterizedSingleTypeReference(iRef.token, args, iRef.dimensions(), (long) iRef.sourceStart << 32 | iRef.sourceEnd); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof ArrayTypeReference) { ArrayTypeReference iRef = (ArrayTypeReference) ref; TypeReference typeRef = new ArrayTypeReference(iRef.token, iRef.dimensions(), (long) iRef.sourceStart << 32 | iRef.sourceEnd); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof Wildcard) { Wildcard original = (Wildcard) ref; Wildcard wildcard = new Wildcard(original.kind); wildcard.sourceStart = original.sourceStart; wildcard.sourceEnd = original.sourceEnd; if (original.bound != null) wildcard.bound = copyType(original.bound, source); if (source != null) setGeneratedBy(wildcard, source); return wildcard; } if (ref instanceof SingleTypeReference) { SingleTypeReference iRef = (SingleTypeReference) ref; TypeReference typeRef = new SingleTypeReference(iRef.token, (long) iRef.sourceStart << 32 | iRef.sourceEnd); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } return ref; }
From source file:lombok.eclipse.handlers.EclipseHandlerUtil.java
License:Open Source License
public static TypeReference makeType(TypeBinding binding, ASTNode pos, boolean allowCompound) { int dims = binding.dimensions(); binding = binding.leafComponentType(); // Primitives char[] base = null; switch (binding.id) { case TypeIds.T_int: base = TypeConstants.INT;// w w w . j a va2 s .co m break; case TypeIds.T_long: base = TypeConstants.LONG; break; case TypeIds.T_short: base = TypeConstants.SHORT; break; case TypeIds.T_byte: base = TypeConstants.BYTE; break; case TypeIds.T_double: base = TypeConstants.DOUBLE; break; case TypeIds.T_float: base = TypeConstants.FLOAT; break; case TypeIds.T_boolean: base = TypeConstants.BOOLEAN; break; case TypeIds.T_char: base = TypeConstants.CHAR; break; case TypeIds.T_void: base = TypeConstants.VOID; break; case TypeIds.T_null: return null; } if (base != null) { if (dims > 0) { TypeReference result = new ArrayTypeReference(base, dims, pos(pos)); setGeneratedBy(result, pos); return result; } TypeReference result = new SingleTypeReference(base, pos(pos)); setGeneratedBy(result, pos); return result; } if (binding.isAnonymousType()) { ReferenceBinding ref = (ReferenceBinding) binding; ReferenceBinding[] supers = ref.superInterfaces(); if (supers == null || supers.length == 0) supers = new ReferenceBinding[] { ref.superclass() }; if (supers[0] == null) { TypeReference result = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(pos, 3)); setGeneratedBy(result, pos); return result; } return makeType(supers[0], pos, false); } if (binding instanceof CaptureBinding) { return makeType(((CaptureBinding) binding).wildcard, pos, allowCompound); } if (binding.isUnboundWildcard()) { if (!allowCompound) { TypeReference result = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(pos, 3)); setGeneratedBy(result, pos); return result; } else { Wildcard out = new Wildcard(Wildcard.UNBOUND); setGeneratedBy(out, pos); out.sourceStart = pos.sourceStart; out.sourceEnd = pos.sourceEnd; return out; } } if (binding.isWildcard()) { WildcardBinding wildcard = (WildcardBinding) binding; if (wildcard.boundKind == Wildcard.EXTENDS) { if (!allowCompound) { return makeType(wildcard.bound, pos, false); } else { Wildcard out = new Wildcard(Wildcard.EXTENDS); setGeneratedBy(out, pos); out.bound = makeType(wildcard.bound, pos, false); out.sourceStart = pos.sourceStart; out.sourceEnd = pos.sourceEnd; return out; } } else if (allowCompound && wildcard.boundKind == Wildcard.SUPER) { Wildcard out = new Wildcard(Wildcard.SUPER); setGeneratedBy(out, pos); out.bound = makeType(wildcard.bound, pos, false); out.sourceStart = pos.sourceStart; out.sourceEnd = pos.sourceEnd; return out; } else { TypeReference result = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(pos, 3)); setGeneratedBy(result, pos); return result; } } // Keep moving up via 'binding.enclosingType()' and gather generics from each binding. We stop after a local type, or a static type, or a top-level type. // Finally, add however many nullTypeArgument[] arrays as that are missing, inverse the list, toArray it, and use that as PTR's typeArgument argument. List<TypeReference[]> params = new ArrayList<TypeReference[]>(); /* Calculate generics */ { TypeBinding b = binding; while (true) { boolean isFinalStop = b.isLocalType() || !b.isMemberType() || b.enclosingType() == null; TypeReference[] tyParams = null; if (b instanceof ParameterizedTypeBinding) { ParameterizedTypeBinding paramized = (ParameterizedTypeBinding) b; if (paramized.arguments != null) { tyParams = new TypeReference[paramized.arguments.length]; for (int i = 0; i < tyParams.length; i++) { tyParams[i] = makeType(paramized.arguments[i], pos, true); } } } params.add(tyParams); if (isFinalStop) break; b = b.enclosingType(); } } char[][] parts; if (binding.isTypeVariable()) { parts = new char[][] { binding.shortReadableName() }; } else if (binding.isLocalType()) { parts = new char[][] { binding.sourceName() }; } else { String[] pkg = new String(binding.qualifiedPackageName()).split("\\."); String[] name = new String(binding.qualifiedSourceName()).split("\\."); if (pkg.length == 1 && pkg[0].isEmpty()) pkg = new String[0]; parts = new char[pkg.length + name.length][]; int ptr; for (ptr = 0; ptr < pkg.length; ptr++) parts[ptr] = pkg[ptr].toCharArray(); for (; ptr < pkg.length + name.length; ptr++) parts[ptr] = name[ptr - pkg.length].toCharArray(); } while (params.size() < parts.length) params.add(null); Collections.reverse(params); boolean isParamized = false; for (TypeReference[] tyParams : params) { if (tyParams != null) { isParamized = true; break; } } if (isParamized) { if (parts.length > 1) { TypeReference[][] typeArguments = params.toArray(new TypeReference[0][]); TypeReference result = new ParameterizedQualifiedTypeReference(parts, typeArguments, dims, poss(pos, parts.length)); setGeneratedBy(result, pos); return result; } TypeReference result = new ParameterizedSingleTypeReference(parts[0], params.get(0), dims, pos(pos)); setGeneratedBy(result, pos); return result; } if (dims > 0) { if (parts.length > 1) { TypeReference result = new ArrayQualifiedTypeReference(parts, dims, poss(pos, parts.length)); setGeneratedBy(result, pos); return result; } TypeReference result = new ArrayTypeReference(parts[0], dims, pos(pos)); setGeneratedBy(result, pos); return result; } if (parts.length > 1) { TypeReference result = new QualifiedTypeReference(parts, poss(pos, parts.length)); setGeneratedBy(result, pos); return result; } TypeReference result = new SingleTypeReference(parts[0], pos(pos)); setGeneratedBy(result, pos); return result; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java
License:Open Source License
/** * Create a JDT ArrayQualifiedTypeReference.<br> * Positional information://w w w .j av a 2s . c o m * <p> * For a qualified array reference, for example 'java.lang.Number[][]' start will be 'j' and end will be the char after ']'. * When the ArrayQualifiedTypeReference is built we need these positions for the result: sourceStart - the 'j'; sourceEnd - the * final ']'; the positions computed for the reference components would be j..a l..g and N..r */ private ArrayQualifiedTypeReference createJDTArrayQualifiedTypeReference(String arrayComponentTypename, int dimensions, int start, int end) { char[][] compoundName = CharOperation.splitOn('.', arrayComponentTypename.toCharArray()); ArrayQualifiedTypeReference aqtr = new ArrayQualifiedTypeReference(compoundName, dimensions, positionsFor(compoundName, start, end - dimensions * 2)); aqtr.sourceEnd = end - 1; return aqtr; }
From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitStructureRequestor.java
License:Open Source License
/** * Recursively converts from an aj type reference to a JDT type reference. * This class is not involved with Content assist and code select, so the CompletionOn* and SelectionOn* variants of * type references should not make it here. * @param ajRef/*from ww w . j a v a2 s . co m*/ * @return jdtRef */ private TypeReference convertToJDTTypeReference( org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference ajRef) { if (ajRef == null) { return null; } TypeReference jdtRef = null; if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocImplicitTypeReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocImplicitTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocImplicitTypeReference) ajRef; jdtRef = new JavadocImplicitTypeReference(castedAJ.token, castedAJ.sourceStart); } else if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) { if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference) { if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocArrayQualifiedTypeReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocArrayQualifiedTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocArrayQualifiedTypeReference) ajRef; jdtRef = new JavadocArrayQualifiedTypeReference( new JavadocQualifiedTypeReference(castedAJ.tokens, castedAJ.sourcePositions, castedAJ.tagSourceStart, castedAJ.tagSourceEnd), castedAJ.dimensions()); } else if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference) ajRef; jdtRef = new ParameterizedQualifiedTypeReference(castedAJ.tokens, convertDoubleArray(castedAJ.typeArguments), castedAJ.dimensions(), castedAJ.sourcePositions); } else { // assume vanilla ArrayQualifiedTypeReference org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference) ajRef; jdtRef = new ArrayQualifiedTypeReference(castedAJ.tokens, castedAJ.dimensions(), castedAJ.sourcePositions); } } else if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocQualifiedTypeReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocQualifiedTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocQualifiedTypeReference) ajRef; jdtRef = new JavadocQualifiedTypeReference(castedAJ.tokens, castedAJ.sourcePositions, castedAJ.tagSourceStart, castedAJ.tagSourceEnd); } else { // assume vanilla QualifiedTypeReference org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ajRef; jdtRef = new QualifiedTypeReference(castedAJ.tokens, castedAJ.sourcePositions); } } else if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) { if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference) { if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocArraySingleTypeReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocArraySingleTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocArraySingleTypeReference) ajRef; jdtRef = new JavadocArraySingleTypeReference(castedAJ.token, castedAJ.dimensions, toPos(castedAJ.sourceStart, castedAJ.sourceEnd)); } else if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference) ajRef; jdtRef = new ParameterizedSingleTypeReference(castedAJ.token, convertSingleArray(castedAJ.typeArguments), castedAJ.dimensions, toPos(castedAJ.sourceStart, castedAJ.sourceEnd)); } else { // assume vanilla ArrayTypeReference org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference) ajRef; jdtRef = new ArrayTypeReference(castedAJ.token, castedAJ.dimensions, toPos(castedAJ.sourceStart, castedAJ.sourceEnd)); } } else if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference) ajRef; jdtRef = new JavadocSingleTypeReference(castedAJ.token, toPos(castedAJ.sourceStart, castedAJ.sourceEnd), castedAJ.tagSourceStart, castedAJ.tagSourceEnd); } else { // assume vanilla SingleTypeReference org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) ajRef; jdtRef = new SingleTypeReference(castedAJ.token, toPos(castedAJ.sourceStart, castedAJ.sourceEnd)); } } else if (ajRef instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Wildcard) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.Wildcard castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Wildcard) ajRef; Wildcard castedJDT = new Wildcard(castedAJ.kind); castedJDT.bound = convertToJDTTypeReference(castedAJ.bound); jdtRef = castedJDT; } Assert.isNotNull(jdtRef, "Conversion to JDT type reference failed. Original AJ type reference is: '" + ajRef + "' and class '" + ajRef.getClass() + "'"); // now fill in the rest of the shared fields. Not all of them will be applicable in all cases jdtRef.bits = ajRef.bits; jdtRef.implicitConversion = ajRef.implicitConversion; jdtRef.statementEnd = ajRef.statementEnd; return jdtRef; }
From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementParser2.java
License:Open Source License
public TypeReference getTypeReference(int dim) { /* build a Reference on a variable that may be qualified or not * This variable is a type reference and dim will be its dimensions */// w ww .j a v a 2s .com int length = identifierLengthStack[identifierLengthPtr--]; if (length < 0) { //flag for precompiled type reference on base types TypeReference ref = TypeReference.baseTypeReference(-length, dim); ref.sourceStart = intStack[intPtr--]; if (dim == 0) { ref.sourceEnd = intStack[intPtr--]; } else { intPtr--; // no need to use this position as it is an array ref.sourceEnd = endPosition; } if (reportReferenceInfo) { requestor.acceptTypeReference(ref.getParameterizedTypeName(), ref.sourceStart, ref.sourceEnd); } return ref; } else { int numberOfIdentifiers = this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr--]; if (length != numberOfIdentifiers || this.genericsLengthStack[this.genericsLengthPtr] != 0) { // generic type TypeReference ref = getTypeReferenceForGenericType(dim, length, numberOfIdentifiers); if (reportReferenceInfo) { if (length == 1 && numberOfIdentifiers == 1) { ParameterizedSingleTypeReference parameterizedSingleTypeReference = (ParameterizedSingleTypeReference) ref; requestor.acceptTypeReference(parameterizedSingleTypeReference.token, parameterizedSingleTypeReference.sourceStart); } else { ParameterizedQualifiedTypeReference parameterizedQualifiedTypeReference = (ParameterizedQualifiedTypeReference) ref; requestor.acceptTypeReference(parameterizedQualifiedTypeReference.tokens, parameterizedQualifiedTypeReference.sourceStart, parameterizedQualifiedTypeReference.sourceEnd); } } return ref; } else if (length == 1) { // single variable reference this.genericsLengthPtr--; // pop the 0 if (dim == 0) { SingleTypeReference ref = new SingleTypeReference(identifierStack[identifierPtr], identifierPositionStack[identifierPtr--]); if (reportReferenceInfo) { requestor.acceptTypeReference(ref.token, ref.sourceStart); } return ref; } else { ArrayTypeReference ref = new ArrayTypeReference(identifierStack[identifierPtr], dim, identifierPositionStack[identifierPtr--]); ref.sourceEnd = endPosition; if (reportReferenceInfo) { requestor.acceptTypeReference(ref.token, ref.sourceStart); } return ref; } } else {//Qualified variable reference this.genericsLengthPtr--; char[][] tokens = new char[length][]; identifierPtr -= length; long[] positions = new long[length]; System.arraycopy(identifierStack, identifierPtr + 1, tokens, 0, length); System.arraycopy(identifierPositionStack, identifierPtr + 1, positions, 0, length); if (dim == 0) { QualifiedTypeReference ref = new QualifiedTypeReference(tokens, positions); if (reportReferenceInfo) { requestor.acceptTypeReference(ref.tokens, ref.sourceStart, ref.sourceEnd); } return ref; } else { ArrayQualifiedTypeReference ref = new ArrayQualifiedTypeReference(tokens, dim, positions); ref.sourceEnd = endPosition; if (reportReferenceInfo) { requestor.acceptTypeReference(ref.tokens, ref.sourceStart, ref.sourceEnd); } return ref; } } } }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected TypeReference getTypeReference(int dim) { /* build a Reference on a variable that may be qualified or not This variable is a type reference and dim will be its dimensions*/ TypeReference ref;/*from w w w . jav a2 s .c o m*/ int length = this.identifierLengthStack[this.identifierLengthPtr--]; if (length < 0) { //flag for precompiled type reference on base types ref = TypeReference.baseTypeReference(-length, dim); ref.sourceStart = this.intStack[this.intPtr--]; if (dim == 0) { ref.sourceEnd = this.intStack[this.intPtr--]; } else { this.intPtr--; ref.sourceEnd = this.endPosition; } } else { int numberOfIdentifiers = this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr--]; if (length != numberOfIdentifiers || this.genericsLengthStack[this.genericsLengthPtr] != 0) { // generic type ref = getTypeReferenceForGenericType(dim, length, numberOfIdentifiers); } else if (length == 1) { // single variable reference this.genericsLengthPtr--; // pop the 0 if (dim == 0) { ref = new SingleTypeReference(this.identifierStack[this.identifierPtr], this.identifierPositionStack[this.identifierPtr--]); } else { ref = new ArrayTypeReference(this.identifierStack[this.identifierPtr], dim, this.identifierPositionStack[this.identifierPtr--]); ref.sourceEnd = this.endPosition; } } else { this.genericsLengthPtr--; //Qualified variable reference char[][] tokens = new char[length][]; this.identifierPtr -= length; long[] positions = new long[length]; System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); if (dim == 0) { ref = new QualifiedTypeReference(tokens, positions); } else { ref = new ArrayQualifiedTypeReference(tokens, dim, positions); ref.sourceEnd = this.endPosition; } } } return ref; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementor.java
License:Open Source License
private void packUnmappedArgs(MethodSpec baseMethodSpec, CallinMappingDeclaration callinBindingDeclaration, MethodDeclaration callinWrapper, ArrayList<Statement> statements, AstGenerator gen) { int[] unmapped = callinBindingDeclaration.getUnmappedBasePositions(baseMethodSpec); if (unmapped.length == 0) return;/*from w w w . java 2 s .com*/ SourcePosition savePos = gen.getSourcePosition(); gen.setSourcePosition(new StepOverSourcePosition()); try { // must have signatures if mapping present. int unusedIdx; int basePos = 1; // skip base object if (callinBindingDeclaration.isReplaceCallin()) { // we have enhanced arguments including _OT$unusedArgs basePos += getMethodSignatureEnhancer().ENHANCING_ARG_LEN; unusedIdx = 0; // check what is already in _OT$unusedArgs: if (baseMethodSpec.isCallin()) { unusedIdx = getMethodSignatureEnhancer().ENHANCING_ARG_LEN; if (baseMethodSpec.isStatic()) // FIXME(SH): Static role methods other the callin? unusedIdx += 2; // a (dummyInt,MyTeam) pair of synthetics } } else { // no enhanced arguments, means also: no _OT$unusedArgs available yet. statements.add(gen.localVariable(getMethodSignatureEnhancer().UNUSED_ARGS, new ArrayQualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, 1, // dims new long[] { gen.pos, gen.pos, gen.pos }), gen.arrayAllocation(gen.qualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT), unmapped.length, // constant dims null))); unusedIdx = 0; } for (int i = 0; i < unmapped.length; i++) { Argument arg = callinWrapper.arguments[basePos + unmapped[i]]; TypeBinding paramType = arg.type.resolvedType; Expression rhs = gen.singleNameReference(arg.name); if (paramType.isBaseType()) rhs = gen.createBoxing(rhs, (BaseTypeBinding) paramType); statements.add(gen.assignment( new ArrayReference(gen.singleNameReference(getMethodSignatureEnhancer().UNUSED_ARGS), gen.intLiteral(unusedIdx++)), rhs)); } } finally { gen.setSourcePosition(savePos); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstClone.java
License:Open Source License
public static TypeReference copyTypeReference(TypeReference typeReference) { if (typeReference == null) return null; TypeReference result = null;/*from ww w . ja va 2s . co m*/ int dims = typeReference.dimensions(); if (typeReference instanceof Wildcard) { Wildcard wildcard = (Wildcard) typeReference; Wildcard newWildcard = new Wildcard(wildcard.kind); newWildcard.sourceStart = wildcard.sourceStart; newWildcard.sourceEnd = wildcard.sourceEnd; newWildcard.bound = copyTypeReference(wildcard.bound); result = newWildcard; } else if (typeReference instanceof SingleTypeReference) { char[] name = ((SingleTypeReference) typeReference).token; long pos = (((long) typeReference.sourceStart) << 32) + typeReference.sourceEnd; if (typeReference instanceof ParameterizedSingleTypeReference) { ParameterizedSingleTypeReference pTypeReference = (ParameterizedSingleTypeReference) typeReference; TypeReference[] newArgs = copyTypeArguments(typeReference, pos, pTypeReference.typeArguments); result = new ParameterizedSingleTypeReference(name, newArgs, dims, pos); } else { if (dims > 0) result = new ArrayTypeReference(name, dims, pos); else result = new SingleTypeReference(name, pos); } } else if (typeReference instanceof QualifiedTypeReference) { QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) typeReference; char[][] typeName = CharOperation.deepCopy(qualifiedTypeReference.tokens); long[] poss = qualifiedTypeReference.sourcePositions; if (typeReference instanceof ParameterizedQualifiedTypeReference) { ParameterizedQualifiedTypeReference pqTypeReference = (ParameterizedQualifiedTypeReference) typeReference; int len = pqTypeReference.typeArguments.length; TypeReference[][] newArgs = new TypeReference[len][]; for (int i = 0; i < len; i++) newArgs[i] = copyTypeArray(pqTypeReference.typeArguments[i]); // sufficient; qualified types are not dependent. result = new ParameterizedQualifiedTypeReference(typeName, newArgs, dims, poss); } else { if (dims > 0) result = new ArrayQualifiedTypeReference(typeName, dims, poss); else result = new QualifiedTypeReference(typeName, poss); } } else if (typeReference instanceof LiftingTypeReference) { LiftingTypeReference liftingRef = (LiftingTypeReference) typeReference; LiftingTypeReference newLiftingRef = new LiftingTypeReference(); newLiftingRef.baseReference = AstClone.copyTypeReference(liftingRef.baseReference); newLiftingRef.roleReference = AstClone.copyTypeReference(liftingRef.roleReference); newLiftingRef.sourceStart = liftingRef.sourceStart; newLiftingRef.sourceEnd = liftingRef.sourceEnd; newLiftingRef.roleToken = liftingRef.roleToken; newLiftingRef.baseTokens = new char[liftingRef.baseTokens.length][]; System.arraycopy(liftingRef.baseTokens, 0, newLiftingRef.baseTokens, 0, liftingRef.baseTokens.length); result = newLiftingRef; } else if (typeReference instanceof TypeAnchorReference) { TypeAnchorReference anchorRef = (TypeAnchorReference) typeReference; result = new TypeAnchorReference(copyReference(anchorRef.anchor), anchorRef.sourceStart); // TODO(SH): need to set any further fields?? } if (result != null) { result.setBaseclassDecapsulation(typeReference.getBaseclassDecapsulation()); result.bits = typeReference.bits; result.isGenerated = true; return result; } throw new InternalCompilerError("Unexpected kind of type reference: " + typeReference.getClass().getName()); //$NON-NLS-1$ }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java
License:Open Source License
public QualifiedTypeReference qualifiedArrayTypeReference(char[][] compoundName, int dims) { long[] poss = new long[compoundName.length]; Arrays.fill(poss, this.pos); ArrayQualifiedTypeReference reference = new ArrayQualifiedTypeReference(compoundName, dims, poss); reference.bits |= ASTNode.IgnoreRawTypeCheck; reference.isGenerated = true;/*from www . j a va2 s.c o m*/ return reference; }