Package org.aspectj.weaver

Examples of org.aspectj.weaver.ResolvedType$Primitive


    }

    bcelWeaver.setReweavableMode(buildConfig.isXNotReweavable());

    // check for org.aspectj.runtime.JoinPoint
    ResolvedType joinPoint = bcelWorld.resolve("org.aspectj.lang.JoinPoint");
    if (joinPoint.isMissing()) {
      IMessage message = new Message(
          "classpath error: unable to find org.aspectj.lang.JoinPoint (check that aspectjrt.jar is in your classpath)",
          null, true);
      handler.handleMessage(message);
    }
View Full Code Here


              if (buildConfig.getOutputJar() == null) {
                String outfile = writeDirectoryEntry(unitResult, classFile, filename);
                getWorld().classWriteEvent(classFile.getCompoundName());
                if (environmentSupportsIncrementalCompilation) {
                  if (!classname.endsWith("$ajcMightHaveAspect")) {
                    ResolvedType type = getBcelWorld().resolve(classname);
                    if (type.isAspect()) {
                      state.recordAspectClassFile(outfile);
                    }
                  }
                }
              } else {
                writeZipEntry(classFile, filename);
              }
              if (shouldAddAspectName && !classname.endsWith("$ajcMightHaveAspect")) {
                addAspectName(classname, unitResult.getFileName());
              }
            } catch (IOException ex) {
              IMessage message = EclipseAdapterUtils.makeErrorMessage(new String(unitResult.fileName),
                  CANT_WRITE_RESULT, ex);
              handler.handleMessage(message);
            }

          }
          state.noteNewResult(unitResult);
          unitResult.compiledTypes.clear(); // free up references to AjClassFile instances
        }

        if (unitResult.hasProblems() || unitResult.hasTasks()) {
          IProblem[] problems = unitResult.getAllProblems();
          for (int i = 0; i < problems.length; i++) {
            IMessage message = EclipseAdapterUtils.makeMessage(unitResult.compilationUnit, problems[i], getBcelWorld(),
                progressListener);
            handler.handleMessage(message);
          }
        }

      }

      private String writeDirectoryEntry(CompilationResult unitResult, ClassFile classFile, String filename)
          throws IOException {
        File destinationPath = buildConfig.getOutputDir();
        if (buildConfig.getCompilationResultDestinationManager() != null) {
          destinationPath = buildConfig.getCompilationResultDestinationManager().getOutputLocationForClass(
              new File(new String(unitResult.fileName)));
        }
        String outFile;
        if (destinationPath == null) {
          outFile = new File(filename).getName();
          outFile = new File(extractDestinationPathFromSourceFile(unitResult), outFile).getPath();
        } else {
          outFile = new File(destinationPath, filename).getPath();
        }

        try {
          BufferedOutputStream os = FileUtil.makeOutputStream(new File(outFile));
          os.write(classFile.getBytes());
          os.close();
        } catch (FileNotFoundException fnfe) {
          IMessage msg = new Message("unable to write out class file: '" + filename + "' - reason: " + fnfe.getMessage(),
              IMessage.ERROR, null, new SourceLocation(new File(outFile), 0));
          handler.handleMessage(msg);
        }

        if (buildConfig.getCompilationResultDestinationManager() != null) {
          buildConfig.getCompilationResultDestinationManager().reportFileWrite(outFile,
              CompilationResultDestinationManager.FILETYPE_CLASS);
        }
        return outFile;
      }

      private void writeZipEntry(ClassFile classFile, String name) throws IOException {
        name = name.replace(File.separatorChar, '/');
        ZipEntry newEntry = new ZipEntry(name); // ??? get compression scheme right

        zos.putNextEntry(newEntry);
        zos.write(classFile.getBytes());
        zos.closeEntry();
      }

      private void addAspectName(String name, char[] fileContainingAspect) {
        BcelWorld world = getBcelWorld();
        ResolvedType type = world.resolve(name);
        // System.err.println("? writeAspectName() type=" + type);
        if (type.isAspect()) {
          if (state.getAspectNamesToFileNameMap() == null) {
            state.initializeAspectNamesToFileNameMap();
          }
          if (!state.getAspectNamesToFileNameMap().containsKey(name)) {
            state.getAspectNamesToFileNameMap().put(name, fileContainingAspect);
View Full Code Here

      Instruction inst = curr.getInstruction();

      // open-up method call
      if ((inst instanceof InvokeInstruction)) {
        InvokeInstruction invoke = (InvokeInstruction) inst;
        ResolvedType callee = m_aspectGen.getWorld().resolve(UnresolvedType.forName(invoke.getClassName(cpg)));

        // look in the whole method list and not just declared for super calls and alike
        List<ResolvedMember> methods = callee.getMethodsWithoutIterator(false, true, false);
        for (ResolvedMember resolvedMember : methods) {
          if (invoke.getName(cpg).equals(resolvedMember.getName())
              && invoke.getSignature(cpg).equals(resolvedMember.getSignature()) && !resolvedMember.isPublic()) {
            if ("<init>".equals(invoke.getName(cpg))) {
              // skipping open up for private constructor
              // can occur when aspect new a private inner type
              // too complex to handle new + dup + .. + invokespecial here.
              aroundAdvice.setCanInline(false);
              realizedCannotInline = true;
            } else {
              // specific handling for super.foo() calls, where foo is non public
              ResolvedType memberType = m_aspectGen.getWorld().resolve(resolvedMember.getDeclaringType());
              if (!aspectType.equals(memberType) && memberType.isAssignableFrom(aspectType)) {
                // old test was...
                // if (aspectType.getSuperclass() != null
                // && aspectType.getSuperclass().getName().equals(resolvedMember.getDeclaringType().getName())) {
                ResolvedMember accessor = createOrGetInlineAccessorForSuperDispatch(resolvedMember);
                InvokeInstruction newInst = factory.createInvoke(aspectType.getName(), accessor.getName(),
                    BcelWorld.makeBcelType(accessor.getReturnType()),
                    BcelWorld.makeBcelTypes(accessor.getParameterTypes()), Constants.INVOKEVIRTUAL);
                curr.setInstruction(newInst);
              } else {
                ResolvedMember accessor = createOrGetInlineAccessorForMethod(resolvedMember);
                InvokeInstruction newInst = factory.createInvoke(aspectType.getName(), accessor.getName(),
                    BcelWorld.makeBcelType(accessor.getReturnType()),
                    BcelWorld.makeBcelTypes(accessor.getParameterTypes()), Constants.INVOKESTATIC);
                curr.setInstruction(newInst);
              }
            }

            break;// ok we found a matching callee member and swapped the instruction with the accessor
          }
        }
      } else if (inst instanceof FieldInstruction) {
        FieldInstruction invoke = (FieldInstruction) inst;
        ResolvedType callee = m_aspectGen.getWorld().resolve(UnresolvedType.forName(invoke.getClassName(cpg)));
        for (int i = 0; i < callee.getDeclaredJavaFields().length; i++) {
          ResolvedMember resolvedMember = callee.getDeclaredJavaFields()[i];
          if (invoke.getName(cpg).equals(resolvedMember.getName())
              && invoke.getSignature(cpg).equals(resolvedMember.getSignature()) && !resolvedMember.isPublic()) {
            final ResolvedMember accessor;
            if ((inst.opcode == Constants.GETFIELD) || (inst.opcode == Constants.GETSTATIC)) {
              accessor = createOrGetInlineAccessorForFieldGet(resolvedMember);
View Full Code Here

  private void addAdviceLikeDeclares(ClassScope s) {
    TypeDeclaration dec = s.referenceContext;

    if (dec instanceof AspectDeclaration) {
      ResolvedType typeX = factory.fromEclipse(dec.binding);
      factory.getWorld().getCrosscuttingMembersSet().addAdviceLikeDeclares(typeX);
    }

    SourceTypeBinding sourceType = s.referenceContext.binding;
    ReferenceBinding[] memberTypes = sourceType.memberTypes;
View Full Code Here

  private void addCrosscuttingStructures(ClassScope s) {
    TypeDeclaration dec = s.referenceContext;

    if (dec instanceof AspectDeclaration) {
      ResolvedType typeX = factory.fromEclipse(dec.binding);
      factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX, false);

      if (typeX.getSuperclass().isAspect() && !typeX.getSuperclass().isExposedToWeaver()) {
        factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX.getSuperclass(), false);
      }
    }

    SourceTypeBinding sourceType = s.referenceContext.binding;
    ReferenceBinding[] memberTypes = sourceType.memberTypes;
View Full Code Here

    }

    SourceTypeBinding sourceType = s.referenceContext.binding;
    // test classes don't extend aspects
    if (sourceType.superclass != null) {
      ResolvedType parent = factory.fromEclipse(sourceType.superclass);
      if (parent.isAspect() && !isAspect(dec)) {
        factory.showMessage(IMessage.ERROR, "class \'" + new String(sourceType.sourceName) + "\' can not extend aspect \'"
            + parent.getName() + "\'", factory.fromEclipse(sourceType).getSourceLocation(), null);
      }
    }

    ReferenceBinding[] memberTypes = sourceType.memberTypes;
    if (memberTypes == null) {
View Full Code Here

      List<DeclareParents> declareParents, List<DeclareAnnotation> declareAnnotationOnTypes, boolean skipInners, int mode) {

    ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_INTERTYPE_DECLARATIONS,
        sourceType.sourceName);

    ResolvedType onType = factory.fromEclipse(sourceType);

    // AMC we shouldn't need this when generic sigs are fixed??
    if (onType.isRawType()) {
      onType = onType.getGenericType();
    }

    WeaverStateInfo info = onType.getWeaverState();

    if (mode < 2) {
      // this test isnt quite right - there will be a case where we fail to
      // flag a problem
      // with a 'dangerous interface' because the type is reweavable when we
      // should have
      // because the type wasn't going to be rewoven... if that happens, we
      // should perhaps
      // move this test and dangerous interface processing to the end of this
      // method and
      // make it conditional on whether any of the typeMungers passed into
      // here actually
      // matched this type.
      if (info != null && !info.isOldStyle() && !info.isReweavable()) {
        processTypeMungersFromExistingWeaverState(sourceType, onType);
        CompilationAndWeavingContext.leavingPhase(tok);
        return;
      }

      // Check if the type we are looking at is the topMostImplementor of a
      // dangerous interface -
      // report a problem if it is.
      for (Iterator i = dangerousInterfaces.entrySet().iterator(); i.hasNext();) {
        Map.Entry entry = (Map.Entry) i.next();
        ResolvedType interfaceType = (ResolvedType) entry.getKey();
        if (onType.isTopmostImplementor(interfaceType)) {
          factory.showMessage(IMessage.ERROR, onType + ": " + entry.getValue(), onType.getSourceLocation(), null);
        }
      }
View Full Code Here

  }

  private boolean doDeclareParents(DeclareParents declareParents, SourceTypeBinding sourceType) {
    ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_DECLARE_PARENTS,
        sourceType.sourceName);
    ResolvedType resolvedSourceType = factory.fromEclipse(sourceType);
    List newParents = declareParents.findMatchingNewParents(resolvedSourceType, false);
    if (!newParents.isEmpty()) {
      for (Iterator i = newParents.iterator(); i.hasNext();) {
        ResolvedType parent = (ResolvedType) i.next();
        if (dangerousInterfaces.containsKey(parent)) {
          ResolvedType onType = factory.fromEclipse(sourceType);
          factory.showMessage(IMessage.ERROR, onType + ": " + dangerousInterfaces.get(parent),
              onType.getSourceLocation(), null);
        }
        if (Modifier.isFinal(parent.getModifiers())) {
          factory.showMessage(IMessage.ERROR, "cannot extend final class " + parent.getClassName(),
              declareParents.getSourceLocation(), null);
        } else {
View Full Code Here

    sb.append("}");
    return sb.toString();
  }

  private boolean doDeclareAnnotations(DeclareAnnotation decA, SourceTypeBinding sourceType, boolean reportProblems) {
    ResolvedType rtx = factory.fromEclipse(sourceType);
    if (!decA.matches(rtx)) {
      return false;
    }
    if (!rtx.isExposedToWeaver()) {
      return false;
    }

    ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_DECLARE_ANNOTATIONS,
        sourceType.sourceName);

    // Get the annotation specified in the declare
    UnresolvedType aspectType = decA.getAspect();
    if (aspectType instanceof ReferenceType) {
      ReferenceType rt = (ReferenceType) aspectType;
      if (rt.isParameterizedType() || rt.isRawType()) {
        aspectType = rt.getGenericType();
      }
    }
    TypeBinding tb = factory.makeTypeBinding(aspectType);

    // Hideousness follows:

    // There are multiple situations to consider here and they relate to the
    // combinations of
    // where the annotation is coming from and where the annotation is going
    // to be put:
    //
    // 1. Straight full build, all from source - the annotation is from a
    // dec@type and
    // is being put on some type. Both types are real SourceTypeBindings.
    // WORKS
    // 2. Incremental build, changing the affected type - the annotation is
    // from a
    // dec@type in a BinaryTypeBinding (so has to be accessed via bcel) and
    // the
    // affected type is a real SourceTypeBinding. Mostly works (pr128665)
    // 3. ?

    SourceTypeBinding stb = (SourceTypeBinding) tb;
    Annotation[] toAdd = null;
    long abits = 0;

    AbstractMethodDeclaration methodDecl = null;
    // Might have to retrieve the annotation through BCEL and construct an
    // eclipse one for it.
    if (stb instanceof BinaryTypeBinding) {
      toAdd = retrieveAnnotationFromBinaryTypeBinding(decA, stb);
      if (toAdd != null && toAdd.length > 0 && toAdd[0].resolvedType != null) {
        abits = toAdd[0].resolvedType.getAnnotationTagBits();
      }
    } else if (stb != null) {
      // much nicer, its a real SourceTypeBinding so we can stay in
      // eclipse land
      // if (decA.getAnnotationMethod() != null) {
      char[] declareSelector = decA.getAnnotationMethod().toCharArray();

      ReferenceBinding rb = stb;
      String declaringAspectName = decA.getDeclaringType().getRawName();
      while (rb != null && !new String(CharOperation.concatWith(rb.compoundName, '.')).equals(declaringAspectName)) {
        rb = rb.superclass();
      }
      MethodBinding[] mbs = rb.getMethods(declareSelector);

      ReferenceBinding declaringBinding = mbs[0].declaringClass;
      if (declaringBinding instanceof ParameterizedTypeBinding) {
        // Unwrap - this means we don't allow the type of the annotation to be parameterized, may need to revisit that
        declaringBinding = ((ParameterizedTypeBinding) declaringBinding).type;
      }
      if (declaringBinding instanceof BinaryTypeBinding) {
        toAdd = retrieveAnnotationFromBinaryTypeBinding(decA, declaringBinding);
        if (toAdd != null && toAdd.length > 0 && toAdd[0].resolvedType != null) {
          abits = toAdd[0].resolvedType.getAnnotationTagBits();
        }
      } else {
        abits = mbs[0].getAnnotationTagBits(); // ensure resolved
        TypeDeclaration typeDecl = ((SourceTypeBinding) declaringBinding).scope.referenceContext;
        methodDecl = typeDecl.declarationOf(mbs[0]);
        toAdd = methodDecl.annotations; // this is what to add
        toAdd[0] = createAnnotationCopy(toAdd[0]);
        if (toAdd[0].resolvedType != null) {
          abits = toAdd[0].resolvedType.getAnnotationTagBits();
          // }
        }
      }
    }

    // This happens if there is another error in the code - that should be reported separately
    if (toAdd == null || toAdd[0] == null || toAdd[0].type == null) {
      CompilationAndWeavingContext.leavingPhase(tok);
      return false;
    }
    if (sourceType instanceof BinaryTypeBinding) {
      // In this case we can't access the source type binding to add a new
      // annotation, so let's put something
      // on the weaver type temporarily
      ResolvedType theTargetType = factory.fromEclipse(sourceType);
      TypeBinding theAnnotationType = toAdd[0].resolvedType;
      // The annotation type may be null if it could not be resolved (eg. the relevant import has not been added yet)
      // In this case an error will be put out about the annotation but not if we crash here
      if (theAnnotationType == null) {
        return false;
      }
      String sig = new String(theAnnotationType.signature());
      UnresolvedType bcelAnnotationType = UnresolvedType.forSignature(sig);
      String name = bcelAnnotationType.getName();
      if (theTargetType.hasAnnotation(bcelAnnotationType)) {
        CompilationAndWeavingContext.leavingPhase(tok);
        return false;
      }

      // FIXME asc tidy up this code that duplicates whats below!
      // Simple checks on the bits
      boolean giveupnow = false;
      if (((abits & TagBits.AnnotationTargetMASK) != 0)) {
        if (isAnnotationTargettingSomethingOtherThanAnnotationOrNormal(abits)) {
          // error will have been already reported
          giveupnow = true;
        } else if ((sourceType.isAnnotationType() && (abits & TagBits.AnnotationForAnnotationType) == 0)
            || (!sourceType.isAnnotationType() && (abits & TagBits.AnnotationForType) == 0)) {

          if (reportProblems) {
            if (decA.isExactPattern()) {
              factory.showMessage(IMessage.ERROR, WeaverMessages.format(
                  WeaverMessages.INCORRECT_TARGET_FOR_DECLARE_ANNOTATION, rtx.getName(), toAdd[0].type,
                  stringifyTargets(abits)), decA.getSourceLocation(), null);
            }
            // dont put out the lint - the weaving process will do
            // that
            // else {
            // if (factory.getWorld().getLint().
            // invalidTargetForAnnotation.isEnabled()) {
            // factory.getWorld().getLint().invalidTargetForAnnotation
            // .signal(new
            // String[]{rtx.getName(),toAdd[0].type.toString(),
            // stringifyTargets
            // (abits)},decA.getSourceLocation(),null);
            // }
            // }
          }
          giveupnow = true;
        }
      }
      if (giveupnow) {
        CompilationAndWeavingContext.leavingPhase(tok);
        return false;
      }

      theTargetType.addAnnotation(new BcelAnnotation(new FakeAnnotation(name, sig,
          (abits & TagBits.AnnotationRuntimeRetention) != 0), factory.getWorld()));
      CompilationAndWeavingContext.leavingPhase(tok);
      return true;
    }
View Full Code Here

                "Annotation field binding is only supported at method-execution join points (compiler limitation)",
                getSourceLocation()));
        return Literal.TRUE; // exit quickly, error will prevent weaving
      }
      BindingAnnotationFieldTypePattern btp = (BindingAnnotationFieldTypePattern) annotationTypePattern;
      ResolvedType formalType = btp.getFormalType().resolve(shadow.getIWorld());
      UnresolvedType annoType = btp.getAnnotationType();
      // TODO 2 need to sort out appropriate creation of the AnnotationAccessFieldVar - what happens for
      // reflective (ReflectionShadow) access to types?
      Var var = shadow.getKindedAnnotationVar(annoType);
      if (var == null) {
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.ResolvedType$Primitive

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.